From 04aa38bbe4faa93c1b10a10f6a77f319d6230dec Mon Sep 17 00:00:00 2001 From: Danny Morabito Date: Tue, 26 Nov 2024 16:06:50 +0100 Subject: [PATCH] Initial commit --- .gitignore | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 9 +++ bun.lockb | Bin 0 -> 21694 bytes package.json | 23 +++++++ src/cashu.ts | 50 ++++++++++++++ src/email.ts | 34 ++++++++++ src/general.ts | 10 +++ src/index.ts | 4 ++ src/nostr.ts | 27 ++++++++ tsconfig.json | 22 +++++++ 10 files changed, 354 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 bun.lockb create mode 100644 package.json create mode 100644 src/cashu.ts create mode 100644 src/email.ts create mode 100644 src/general.ts create mode 100644 src/index.ts create mode 100644 src/nostr.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..25caa4f --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Arx Utils + +TypeScript utilities for frontend and general-purpose typescript development. + +## Installation + +```bash +bun add git+ssh://git@git.arx-ccn.com:222/Arx/ts-utils.git +``` \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..4efdcff19ba4380ac5039e6b1d47059fdd1277ba GIT binary patch literal 21694 zcmeHP2|QI@*T3qPA|leHA`#_Y^H4JDX;KMk(qOn;WxV&A8blftz0GNs63rn(rO8kf zNrMp0@o19fl)kl&yLEc>aC_eO_j|wZ`?YG@cb~og|F!no!`WxpM@3mHkk8X{_43u? z_y#Gt2Kq`sV0rtw&G+!~=CC~ccs?!yR*<$t2L^*tDz|&l(y;WyrQAjry`Zr7_R(85 zWs7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EnLZ;qB*Ak+xSF~J3mEeSry&0p8RaK4TO9}01_TwVAaxLo84SgwBF0v#PN#m&zh z+KsYH;O9rL2Fsfl$Z~UW<8lH89>%QZ@f*x><-@mTI0BZxpLZyHa>l!jDzq*PRcL*X zMXk=TLM?fskp94hiyJ)y}j#(-gEEkobbnS)QT(V3U`(`;RG>pTEG%4+av6VR-zd1YR9b zNEZHr{5FjG5ei2Acz~tPHfHO$Q?Z}<5tx2wM(8+zV+3F$I8V2ukj{&G>1pr=tf1Rr za0iq-^Tf$ynvs0f-!(+PEvB<0ffyh2@`VZHDZQGhUH z4{t}K4S~>`AHJmp7T}m~yTY{d3*cxe&<8`6>Nn(M=H<`j@c86}<>jxZ zOZz>%85``v_i1DNd@t0Z4G}mmv^#j|$^h*O1`LNff}QQu@rUy-Ae&FblzZA6Q$#16 zolzx30KYHHm8$mRtErL(VP!5?W0Q4?A`-;|HI8OkQ%on)W6B$S!y?DLeHn90*gSx110N;hz>})Jn7f5>8$182kNNh%(rhnq+jS2_L^(Nu7h*QcTJS(NuYg zL$CP?h&rGZ%opmx)omMev{FDwErpw}i<>P9^mX@g^J>>9dNH7(Ct;Bf7t`&nwuEK` r<8mXI&!R5csd=IKYPI c + x.amount, 0); + if (this.amount < TokenInfo.MIN_AMOUNT) + throw new InvalidTokenException(`Invalid amount. Minimum required: ${TokenInfo.MIN_AMOUNT} sats`); + if (!TokenInfo.ALLOWED_MINTS.includes(this.token.mint)) + throw new InvalidTokenException('Unsupported mint'); + this.mint = this.token.mint; + this.proofs = this.token.proofs; + } +} + +export class TokenInfoWithMailSubscriptionDuration extends TokenInfo { + public readonly duration: number; + + constructor(tokenString: string) { + super(tokenString); + this.duration = getMailSubscriptionDurationForSats(this.amount); + } +} diff --git a/src/email.ts b/src/email.ts new file mode 100644 index 0000000..2f7419e --- /dev/null +++ b/src/email.ts @@ -0,0 +1,34 @@ +/** + * Parses a raw email string into its constituent parts, including subject, headers, and body. + * + * @param emailText The raw email text to parse. + * @returns An object containing the extracted email components. + */ +export function parseEmail(emailText: string) { + const lines = emailText.split('\n'); + const headers: { [key: string]: string } = {}; + let bodyLines = []; + let isBody = false; + + for (let line of lines) { + if (!isBody) { + if (line.trim() === '') { + isBody = true; + continue; + } + + const colonIndex = line.indexOf(':'); + if (colonIndex !== -1) { + const key = line.slice(0, colonIndex); + headers[key] = line.slice(colonIndex + 1).trim(); + } + } else + bodyLines.push(line); + } + + return { + subject: headers['Subject'] || 'No subject', + headers, + body: bodyLines.join('\n').trim() + }; +} diff --git a/src/general.ts b/src/general.ts new file mode 100644 index 0000000..ea413a1 --- /dev/null +++ b/src/general.ts @@ -0,0 +1,10 @@ +export function randomTimeUpTo2DaysInThePast() { + const now = Date.now(); + const twoDaysAgo = now - 2 * 24 * 60 * 60 * 1000 - 3600 * 1000; // 1 hour buffer in case of clock skew + return Math.floor((Math.floor(Math.random() * (now - twoDaysAgo)) + twoDaysAgo) / 1000); +} + +export function getMailSubscriptionDurationForSats(n: number) { + const twentyOneSatsToSeconds = 8640 / 21; + return Math.floor(n * twentyOneSatsToSeconds); +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..08492a2 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,4 @@ +export * from "./cashu"; +export * from "./general"; +export * from "./nostr.ts"; +export * from "./email.ts"; \ No newline at end of file diff --git a/src/nostr.ts b/src/nostr.ts new file mode 100644 index 0000000..4b4cd80 --- /dev/null +++ b/src/nostr.ts @@ -0,0 +1,27 @@ +import NDK, {NDKEvent, NDKPrivateKeySigner, NDKUser} from "@nostr-dev-kit/ndk"; +import {generateSecretKey} from "nostr-tools"; +import {randomTimeUpTo2DaysInThePast} from "./general.ts"; + +export async function encryptEventForRecipient( + ndk: NDK, + event: NDKEvent, + recipient: NDKUser +): Promise { + await ndk.connect(); + let randomKey = generateSecretKey(); + const randomKeySinger = new NDKPrivateKeySigner(randomKey); + const seal = new NDKEvent(); + seal.pubkey = recipient.pubkey; + seal.kind = 13; + seal.content = await ndk.signer!.nip44Encrypt(recipient, JSON.stringify(event)); + seal.created_at = randomTimeUpTo2DaysInThePast(); + await seal.sign(ndk.signer); + const giftWrap = new NDKEvent(); + giftWrap.kind = 1059; + giftWrap.created_at = randomTimeUpTo2DaysInThePast(); + giftWrap.content = await randomKeySinger.nip44Encrypt(recipient, JSON.stringify(seal)); + giftWrap.tags.push(['p', recipient.pubkey]); + await giftWrap.sign(randomKeySinger); + giftWrap.ndk = ndk; + return giftWrap; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0aba36f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "allowJs": false, + + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": false + } +}