ns-auth-sdk 1.14.0 → 1.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cjs-CSUAVztq.cjs → browser-index.cjs} +5476 -296
- package/dist/browser-index.cjs.map +1 -0
- package/dist/browser-index.d.cts +1998 -0
- package/dist/browser-index.d.cts.map +1 -0
- package/dist/browser-index.d.mts +1998 -0
- package/dist/browser-index.d.mts.map +1 -0
- package/dist/{cjs-sm5h7qxv.mjs → browser-index.mjs} +5169 -69
- package/dist/browser-index.mjs.map +1 -0
- package/dist/{group-coordination-BlFpBVpn.mjs → group-coordination-BV6PKlKp.mjs} +1 -1
- package/dist/{group-coordination-BlFpBVpn.mjs.map → group-coordination-BV6PKlKp.mjs.map} +1 -1
- package/dist/{group-coordination-ImuoJEoy.mjs → group-coordination-BytkmY9j.mjs} +1 -1
- package/dist/{group-coordination-LGIyipaX.cjs → group-coordination-DL39hJ3R.cjs} +1 -1
- package/dist/{group-coordination-LGIyipaX.cjs.map → group-coordination-DL39hJ3R.cjs.map} +1 -1
- package/dist/{group-coordination-Cf18OjZt.cjs → group-coordination-DLban6a7.cjs} +1 -1
- package/dist/index.cjs +8899 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.mjs +9072 -213
- package/dist/index.mjs.map +1 -1
- package/dist/{prf-handler-D3EqUNWe.cjs → prf-handler-BNd7gmXJ.cjs} +1 -1
- package/dist/{prf-handler-D3EqUNWe.cjs.map → prf-handler-BNd7gmXJ.cjs.map} +1 -1
- package/dist/prf-handler-CRMgzJG2.cjs +3 -0
- package/dist/{prf-handler-Dly_WZGn.mjs → prf-handler-DG99ZkS2.mjs} +1 -1
- package/dist/{prf-handler-Db8CsoIP.mjs → prf-handler-Dj2WTO9i.mjs} +1 -1
- package/dist/{prf-handler-Db8CsoIP.mjs.map → prf-handler-Dj2WTO9i.mjs.map} +1 -1
- package/dist/zkm.service-Bv88tVS5.mjs +3 -0
- package/dist/zkm.service-D2BZ_aqA.cjs +3 -0
- package/dist/{zkm.service-DfSPbuOl.cjs → zkm.service-DX06sSfB.cjs} +1 -1
- package/dist/{zkm.service-DfSPbuOl.cjs.map → zkm.service-DX06sSfB.cjs.map} +1 -1
- package/dist/{zkm.service-B24N_0FB.mjs → zkm.service-j0HlN7Oq.mjs} +1 -1
- package/dist/{zkm.service-B24N_0FB.mjs.map → zkm.service-j0HlN7Oq.mjs.map} +1 -1
- package/package.json +19 -6
- package/dist/_esm-C7FRLTj2.cjs +0 -9030
- package/dist/_esm-C7FRLTj2.cjs.map +0 -1
- package/dist/_esm-D_oMW5T5.mjs +0 -9028
- package/dist/_esm-D_oMW5T5.mjs.map +0 -1
- package/dist/base64-js-B8y7dH5k.mjs +0 -93
- package/dist/base64-js-B8y7dH5k.mjs.map +0 -1
- package/dist/base64-js-Tm-kCeud.cjs +0 -98
- package/dist/base64-js-Tm-kCeud.cjs.map +0 -1
- package/dist/ccip-157tdxqP.cjs +0 -7947
- package/dist/ccip-157tdxqP.cjs.map +0 -1
- package/dist/ccip-BEMMdVyd.cjs +0 -4
- package/dist/ccip-BSmCdJ3K.mjs +0 -3
- package/dist/ccip-okqXkslP.mjs +0 -6567
- package/dist/ccip-okqXkslP.mjs.map +0 -1
- package/dist/chains-CTeD2UcS.mjs +0 -33
- package/dist/chains-CTeD2UcS.mjs.map +0 -1
- package/dist/chains-Du-lv_5i.cjs +0 -33
- package/dist/chains-Du-lv_5i.cjs.map +0 -1
- package/dist/chunk-Bnu9O96Y.cjs +0 -60
- package/dist/chunk-CVYhg9ik.mjs +0 -45
- package/dist/cjs-CSUAVztq.cjs.map +0 -1
- package/dist/cjs-sm5h7qxv.mjs.map +0 -1
- package/dist/defineChain-7QG67hYU.cjs +0 -30
- package/dist/defineChain-7QG67hYU.cjs.map +0 -1
- package/dist/defineChain-DBem8ZQY.mjs +0 -24
- package/dist/defineChain-DBem8ZQY.mjs.map +0 -1
- package/dist/dist-BPmSxkxc.cjs +0 -10676
- package/dist/dist-BPmSxkxc.cjs.map +0 -1
- package/dist/dist-BSjH4t6s.cjs +0 -12932
- package/dist/dist-BSjH4t6s.cjs.map +0 -1
- package/dist/dist-C-KjTK4Q.cjs +0 -447
- package/dist/dist-C-KjTK4Q.cjs.map +0 -1
- package/dist/dist-C2h97xM-.mjs +0 -355
- package/dist/dist-C2h97xM-.mjs.map +0 -1
- package/dist/dist-CT7grDWb.mjs +0 -12920
- package/dist/dist-CT7grDWb.mjs.map +0 -1
- package/dist/dist-D7fRmK6G.mjs +0 -10632
- package/dist/dist-D7fRmK6G.mjs.map +0 -1
- package/dist/dist-DlmcyFmM.mjs +0 -16951
- package/dist/dist-DlmcyFmM.mjs.map +0 -1
- package/dist/dist-O0uZr5OF.cjs +0 -17122
- package/dist/dist-O0uZr5OF.cjs.map +0 -1
- package/dist/echo-BB-JgAYZ.cjs +0 -339
- package/dist/echo-BB-JgAYZ.cjs.map +0 -1
- package/dist/echo-Bwy4_Cvh.mjs +0 -316
- package/dist/echo-Bwy4_Cvh.mjs.map +0 -1
- package/dist/echo-D6X2IuNW.cjs +0 -9
- package/dist/echo-DvfG_heb.mjs +0 -8
- package/dist/esm-BcHKCX5i.mjs +0 -569
- package/dist/esm-BcHKCX5i.mjs.map +0 -1
- package/dist/esm-Bh_YwFIz.cjs +0 -599
- package/dist/esm-Bh_YwFIz.cjs.map +0 -1
- package/dist/esm-C0XO9TQm.cjs +0 -30449
- package/dist/esm-C0XO9TQm.cjs.map +0 -1
- package/dist/esm-vMUVj9k4.mjs +0 -30440
- package/dist/esm-vMUVj9k4.mjs.map +0 -1
- package/dist/keyset-CKMQXvsb.mjs +0 -172
- package/dist/keyset-CKMQXvsb.mjs.map +0 -1
- package/dist/keyset-Cxdgu110.cjs +0 -237
- package/dist/keyset-Cxdgu110.cjs.map +0 -1
- package/dist/keyset-DLxpGhdu.cjs +0 -6
- package/dist/keyset-IKjlhvqF.mjs +0 -4
- package/dist/node-3EUJ4ga9.cjs +0 -9
- package/dist/node-C2UpE11T.cjs +0 -444
- package/dist/node-C2UpE11T.cjs.map +0 -1
- package/dist/node-CHdpTQdN.mjs +0 -8679
- package/dist/node-CHdpTQdN.mjs.map +0 -1
- package/dist/node-DQt1CVGl.mjs +0 -6
- package/dist/node-Dy8ww1LG.cjs +0 -8680
- package/dist/node-Dy8ww1LG.cjs.map +0 -1
- package/dist/node-IX55IH6z.mjs +0 -397
- package/dist/node-IX55IH6z.mjs.map +0 -1
- package/dist/nostr-BTOpBN_5.cjs +0 -11
- package/dist/nostr-D4E52XRU.mjs +0 -224
- package/dist/nostr-D4E52XRU.mjs.map +0 -1
- package/dist/nostr-Hv2tsnuI.cjs +0 -272
- package/dist/nostr-Hv2tsnuI.cjs.map +0 -1
- package/dist/nostr-ZwJe_DlZ.mjs +0 -4
- package/dist/pako.esm-DTVnlCJh.cjs +0 -3856
- package/dist/pako.esm-DTVnlCJh.cjs.map +0 -1
- package/dist/pako.esm-ORhkEHM2.mjs +0 -3838
- package/dist/pako.esm-ORhkEHM2.mjs.map +0 -1
- package/dist/peer-B9g3OQ5D.cjs +0 -18
- package/dist/peer-CptDj7zu.mjs +0 -745
- package/dist/peer-CptDj7zu.mjs.map +0 -1
- package/dist/peer-CtqL0yiE.mjs +0 -9
- package/dist/peer-XrPL0O6z.cjs +0 -822
- package/dist/peer-XrPL0O6z.cjs.map +0 -1
- package/dist/ping-BXKREIdI.mjs +0 -7
- package/dist/ping-BtVhKocl.cjs +0 -379
- package/dist/ping-BtVhKocl.cjs.map +0 -1
- package/dist/ping-D5fpMhGC.cjs +0 -11
- package/dist/ping-DOD50kW_.mjs +0 -332
- package/dist/ping-DOD50kW_.mjs.map +0 -1
- package/dist/policy-8HcjulLD.cjs +0 -293
- package/dist/policy-8HcjulLD.cjs.map +0 -1
- package/dist/policy-BA6MEOBY.mjs +0 -5
- package/dist/policy-BFNdXvmM.cjs +0 -11
- package/dist/policy-D_nFHHjo.mjs +0 -228
- package/dist/policy-D_nFHHjo.mjs.map +0 -1
- package/dist/prf-handler-BNiyCQMt.cjs +0 -3
- package/dist/src-CVfTUJQl.mjs +0 -822
- package/dist/src-CVfTUJQl.mjs.map +0 -1
- package/dist/src-D5S86Xpf.cjs +0 -827
- package/dist/src-D5S86Xpf.cjs.map +0 -1
- package/dist/types-B-TLIS13.cjs +0 -212
- package/dist/types-B-TLIS13.cjs.map +0 -1
- package/dist/types-CTm_FHYD.mjs +0 -111
- package/dist/types-CTm_FHYD.mjs.map +0 -1
- package/dist/validation-1xwWVXqE.mjs +0 -3
- package/dist/validation-DnpurN79.cjs +0 -405
- package/dist/validation-DnpurN79.cjs.map +0 -1
- package/dist/validation-IsAUvsvy.mjs +0 -334
- package/dist/validation-IsAUvsvy.mjs.map +0 -1
- package/dist/validation-yCvZCqIs.cjs +0 -6
- package/dist/wrapper-C5NpyacC.cjs +0 -3552
- package/dist/wrapper-C5NpyacC.cjs.map +0 -1
- package/dist/wrapper-CHq_CV4J.mjs +0 -3552
- package/dist/wrapper-CHq_CV4J.mjs.map +0 -1
- package/dist/zkm.service-BrXyI4BS.mjs +0 -3
- package/dist/zkm.service-BvQ01wSH.cjs +0 -3
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nostr-D4E52XRU.mjs","names":["bytesToHex2","hexToBytes2","nip19"],"sources":["../node_modules/nostr-tools/lib/esm/pure.js","../node_modules/@frostr/igloo-core/dist/nostr.js"],"sourcesContent":["// pure.ts\nimport { schnorr } from \"@noble/curves/secp256k1.js\";\nimport { bytesToHex as bytesToHex2, hexToBytes as hexToBytes2 } from \"@noble/hashes/utils.js\";\n\n// core.ts\nvar verifiedSymbol = Symbol(\"verified\");\nvar isRecord = (obj) => obj instanceof Object;\nfunction validateEvent(event) {\n if (!isRecord(event))\n return false;\n if (typeof event.kind !== \"number\")\n return false;\n if (typeof event.content !== \"string\")\n return false;\n if (typeof event.created_at !== \"number\")\n return false;\n if (typeof event.pubkey !== \"string\")\n return false;\n if (!event.pubkey.match(/^[a-f0-9]{64}$/))\n return false;\n if (!Array.isArray(event.tags))\n return false;\n for (let i2 = 0; i2 < event.tags.length; i2++) {\n let tag = event.tags[i2];\n if (!Array.isArray(tag))\n return false;\n for (let j = 0; j < tag.length; j++) {\n if (typeof tag[j] !== \"string\")\n return false;\n }\n }\n return true;\n}\nfunction sortEvents(events) {\n return events.sort((a, b) => {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at;\n }\n return a.id.localeCompare(b.id);\n });\n}\n\n// pure.ts\nimport { sha256 } from \"@noble/hashes/sha2.js\";\n\n// utils.ts\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils.js\";\nvar utf8Decoder = new TextDecoder(\"utf-8\");\nvar utf8Encoder = new TextEncoder();\n\n// pure.ts\nvar JS = class {\n generateSecretKey() {\n return schnorr.utils.randomSecretKey();\n }\n getPublicKey(secretKey) {\n return bytesToHex2(schnorr.getPublicKey(secretKey));\n }\n finalizeEvent(t, secretKey) {\n const event = t;\n event.pubkey = bytesToHex2(schnorr.getPublicKey(secretKey));\n event.id = getEventHash(event);\n event.sig = bytesToHex2(schnorr.sign(hexToBytes2(getEventHash(event)), secretKey));\n event[verifiedSymbol] = true;\n return event;\n }\n verifyEvent(event) {\n if (typeof event[verifiedSymbol] === \"boolean\")\n return event[verifiedSymbol];\n try {\n const hash = getEventHash(event);\n if (hash !== event.id) {\n event[verifiedSymbol] = false;\n return false;\n }\n const valid = schnorr.verify(hexToBytes2(event.sig), hexToBytes2(hash), hexToBytes2(event.pubkey));\n event[verifiedSymbol] = valid;\n return valid;\n } catch (err) {\n event[verifiedSymbol] = false;\n return false;\n }\n }\n};\nfunction serializeEvent(evt) {\n if (!validateEvent(evt))\n throw new Error(\"can't serialize event with wrong or missing properties\");\n return JSON.stringify([0, evt.pubkey, evt.created_at, evt.kind, evt.tags, evt.content]);\n}\nfunction getEventHash(event) {\n let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)));\n return bytesToHex2(eventHash);\n}\nvar i = new JS();\nvar generateSecretKey = i.generateSecretKey;\nvar getPublicKey = i.getPublicKey;\nvar finalizeEvent = i.finalizeEvent;\nvar verifyEvent = i.verifyEvent;\nexport {\n finalizeEvent,\n generateSecretKey,\n getEventHash,\n getPublicKey,\n serializeEvent,\n sortEvents,\n validateEvent,\n verifiedSymbol,\n verifyEvent\n};\n","import { nip19 } from 'nostr-tools';\nimport { generateSecretKey, getPublicKey } from 'nostr-tools/pure';\nimport { NostrError } from './types.js';\n/**\n * Converts a nostr secret key (nsec) to its hex representation\n * @param nsec The nostr secret key in nsec format\n * @returns The secret key in hex format\n */\nexport function nsecToHex(nsec) {\n try {\n const { type, data } = nip19.decode(nsec);\n if (type !== 'nsec') {\n throw new NostrError('Invalid nsec format');\n }\n return Buffer.from(data).toString('hex');\n }\n catch (error) {\n throw new NostrError(`Failed to decode nsec: ${error.message}`, { nsec, error });\n }\n}\n/**\n * Converts a hex secret key to nostr secret key (nsec) format\n * @param hex The secret key in hex format\n * @returns The secret key in nsec format\n */\nexport function hexToNsec(hex) {\n try {\n validateHexKey(hex);\n const bytes = new Uint8Array(Buffer.from(hex, 'hex'));\n return nip19.nsecEncode(bytes);\n }\n catch (error) {\n throw new NostrError(`Failed to encode nsec: ${error.message}`, { hex, error });\n }\n}\n/**\n * Converts a hex public key to nostr public key (npub) format\n * @param hex The public key in hex format\n * @returns The public key in npub format\n */\nexport function hexToNpub(hex) {\n try {\n validateHexKey(hex);\n return nip19.npubEncode(hex);\n }\n catch (error) {\n throw new NostrError(`Failed to encode npub: ${error.message}`, { hex, error });\n }\n}\n/**\n * Converts a nostr public key (npub) to its hex representation\n * @param npub The nostr public key in npub format\n * @returns The public key in hex format\n */\nexport function npubToHex(npub) {\n try {\n const { type, data } = nip19.decode(npub);\n if (type !== 'npub') {\n throw new NostrError('Invalid npub format');\n }\n return data;\n }\n catch (error) {\n throw new NostrError(`Failed to decode npub: ${error.message}`, { npub, error });\n }\n}\n/**\n * Generates a new nostr key pair (nsec and npub)\n * @returns Object containing both nsec and npub, plus hex versions\n */\nexport function generateNostrKeyPair() {\n try {\n const sk = generateSecretKey();\n const hexPublicKey = getPublicKey(sk);\n const hexPrivateKey = Buffer.from(sk).toString('hex');\n return {\n nsec: nip19.nsecEncode(sk),\n npub: nip19.npubEncode(hexPublicKey),\n hexPrivateKey,\n hexPublicKey\n };\n }\n catch (error) {\n throw new NostrError(`Failed to generate nostr key pair: ${error.message}`, { error });\n }\n}\n/**\n * Derives the public key from a private key\n * @param privateKey The private key in hex or nsec format\n * @returns Object containing npub and hex public key\n */\nexport function derivePublicKey(privateKey) {\n try {\n let hexPrivateKey;\n if (privateKey.startsWith('nsec')) {\n hexPrivateKey = nsecToHex(privateKey);\n }\n else {\n validateHexKey(privateKey);\n hexPrivateKey = privateKey;\n }\n const privateKeyBytes = new Uint8Array(Buffer.from(hexPrivateKey, 'hex'));\n const hexPublicKey = getPublicKey(privateKeyBytes);\n return {\n npub: nip19.npubEncode(hexPublicKey),\n hexPublicKey\n };\n }\n catch (error) {\n throw new NostrError(`Failed to derive public key: ${error.message}`, { privateKey: privateKey.startsWith('nsec') ? '[REDACTED]' : privateKey, error });\n }\n}\n/**\n * Validates a hex key format (private or public)\n * @param hex The hex string to validate\n * @param keyType Optional key type for more specific validation\n */\nexport function validateHexKey(hex, keyType) {\n if (!hex || typeof hex !== 'string') {\n throw new NostrError('Hex key must be a non-empty string');\n }\n const expectedLength = keyType === 'public' ? 64 : keyType === 'private' ? 64 : 64;\n const hexRegex = /^[0-9a-fA-F]+$/;\n if (!hexRegex.test(hex)) {\n throw new NostrError('Invalid hex format - must contain only hexadecimal characters');\n }\n if (hex.length !== expectedLength) {\n throw new NostrError(`Invalid hex key length - expected ${expectedLength} characters, got ${hex.length}`);\n }\n}\n/**\n * Validates a nostr key format (nsec or npub)\n * @param key The nostr key to validate\n * @param expectedType Optional expected type ('nsec' or 'npub')\n */\nexport function validateNostrKey(key, expectedType) {\n try {\n const { type } = nip19.decode(key);\n if (expectedType && type !== expectedType) {\n throw new NostrError(`Expected ${expectedType} but got ${type}`);\n }\n if (type !== 'nsec' && type !== 'npub') {\n throw new NostrError(`Invalid nostr key type: ${type}`);\n }\n }\n catch (error) {\n if (error instanceof NostrError) {\n throw error;\n }\n throw new NostrError(`Invalid nostr key format: ${error.message}`, { key: key.substring(0, 10) + '...', error });\n }\n}\n"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;AAKA,IAAI,iBAAiB,OAAO,WAAW;AACvC,IAAI,YAAY,QAAQ,eAAe;AACvC,SAAS,cAAc,OAAO;AAC5B,KAAI,CAAC,SAAS,MAAM,CAClB,QAAO;AACT,KAAI,OAAO,MAAM,SAAS,SACxB,QAAO;AACT,KAAI,OAAO,MAAM,YAAY,SAC3B,QAAO;AACT,KAAI,OAAO,MAAM,eAAe,SAC9B,QAAO;AACT,KAAI,OAAO,MAAM,WAAW,SAC1B,QAAO;AACT,KAAI,CAAC,MAAM,OAAO,MAAM,iBAAiB,CACvC,QAAO;AACT,KAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAC5B,QAAO;AACT,MAAK,IAAI,KAAK,GAAG,KAAK,MAAM,KAAK,QAAQ,MAAM;EAC7C,IAAI,MAAM,MAAM,KAAK;AACrB,MAAI,CAAC,MAAM,QAAQ,IAAI,CACrB,QAAO;AACT,OAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC9B,KAAI,OAAO,IAAI,OAAO,SACpB,QAAO;;AAGb,QAAO;;AAgBS,IAAI,YAAY,QAAQ;AAC1C,IAAI,cAAc,IAAI,aAAa;AAGnC,IAAI,KAAK,MAAM;CACb,oBAAoB;AAClB,SAAO,QAAQ,MAAM,iBAAiB;;CAExC,aAAa,WAAW;AACtB,SAAOA,WAAY,QAAQ,aAAa,UAAU,CAAC;;CAErD,cAAc,GAAG,WAAW;EAC1B,MAAM,QAAQ;AACd,QAAM,SAASA,WAAY,QAAQ,aAAa,UAAU,CAAC;AAC3D,QAAM,KAAK,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AI,WAAW,gCAAgC,MAAM,WAAW;GAAE,YAAY,WAAW,WAAW,OAAO,GAAG,eAAe;GAAY;GAAO,CAAC;;;;;;;;AAQ/J,SAAgB,eAAe,KAAK,SAAS;AACzC,KAAI,CAAC,OAAO,OAAO,QAAQ,SACvB,OAAM,IAAI,WAAW,qCAAqC;CAE9D,MAAM,iBAAiB,YAAY,WAAW,KAAK,YAAY,YAAY,KAAK;AAEhF,KAAI,CADa,iBACH,KAAK,IAAI,CACnB,OAAM,IAAI,WAAW,gEAAgE;AAEzF,KAAI,IAAI,WAAW,eACf,OAAM,IAAI,WAAW,qCAAqC,eAAe,mBAAmB,IAAI,SAAS;;;;;;;AAQjH,SAAgB,iBAAiB,KAAK,cAAc;AAChD,KAAI;EACA,MAAM,EAAE,SAASA,cAAM,OAAO,IAAI;AAClC,MAAI,gBAAgB,SAAS,aACzB,OAAM,IAAI,WAAW,YAAY,aAAa,WAAW,OAAO;AAEpE,MAAI,SAAS,UAAU,SAAS,OAC5B,OAAM,IAAI,WAAW,2BAA2B,OAAO;UAGxD,OAAO;AACV,MAAI,iBAAiB,WACjB,OAAM;AAEV,QAAM,IAAI,WAAW,6BAA6B,MAAM,WAAW;GAAE,KAAK,IAAI,UAAU,GAAG,GAAG,GAAG;GAAO;GAAO,CAAC"}
|
package/dist/nostr-Hv2tsnuI.cjs
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-Bnu9O96Y.cjs');
|
|
2
|
-
const require_dist = require('./dist-BPmSxkxc.cjs');
|
|
3
|
-
const require_types = require('./types-B-TLIS13.cjs');
|
|
4
|
-
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
5
|
-
let _noble_curves_secp256k1_js = require("@noble/curves/secp256k1.js");
|
|
6
|
-
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
7
|
-
|
|
8
|
-
//#region node_modules/nostr-tools/lib/esm/pure.js
|
|
9
|
-
var verifiedSymbol = Symbol("verified");
|
|
10
|
-
var isRecord = (obj) => obj instanceof Object;
|
|
11
|
-
function validateEvent(event) {
|
|
12
|
-
if (!isRecord(event)) return false;
|
|
13
|
-
if (typeof event.kind !== "number") return false;
|
|
14
|
-
if (typeof event.content !== "string") return false;
|
|
15
|
-
if (typeof event.created_at !== "number") return false;
|
|
16
|
-
if (typeof event.pubkey !== "string") return false;
|
|
17
|
-
if (!event.pubkey.match(/^[a-f0-9]{64}$/)) return false;
|
|
18
|
-
if (!Array.isArray(event.tags)) return false;
|
|
19
|
-
for (let i2 = 0; i2 < event.tags.length; i2++) {
|
|
20
|
-
let tag = event.tags[i2];
|
|
21
|
-
if (!Array.isArray(tag)) return false;
|
|
22
|
-
for (let j = 0; j < tag.length; j++) if (typeof tag[j] !== "string") return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
new TextDecoder("utf-8");
|
|
27
|
-
var utf8Encoder = new TextEncoder();
|
|
28
|
-
var JS = class {
|
|
29
|
-
generateSecretKey() {
|
|
30
|
-
return _noble_curves_secp256k1_js.schnorr.utils.randomSecretKey();
|
|
31
|
-
}
|
|
32
|
-
getPublicKey(secretKey) {
|
|
33
|
-
return (0, _noble_hashes_utils_js.bytesToHex)(_noble_curves_secp256k1_js.schnorr.getPublicKey(secretKey));
|
|
34
|
-
}
|
|
35
|
-
finalizeEvent(t, secretKey) {
|
|
36
|
-
const event = t;
|
|
37
|
-
event.pubkey = (0, _noble_hashes_utils_js.bytesToHex)(_noble_curves_secp256k1_js.schnorr.getPublicKey(secretKey));
|
|
38
|
-
event.id = getEventHash(event);
|
|
39
|
-
event.sig = (0, _noble_hashes_utils_js.bytesToHex)(_noble_curves_secp256k1_js.schnorr.sign((0, _noble_hashes_utils_js.hexToBytes)(getEventHash(event)), secretKey));
|
|
40
|
-
event[verifiedSymbol] = true;
|
|
41
|
-
return event;
|
|
42
|
-
}
|
|
43
|
-
verifyEvent(event) {
|
|
44
|
-
if (typeof event[verifiedSymbol] === "boolean") return event[verifiedSymbol];
|
|
45
|
-
try {
|
|
46
|
-
const hash = getEventHash(event);
|
|
47
|
-
if (hash !== event.id) {
|
|
48
|
-
event[verifiedSymbol] = false;
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const valid = _noble_curves_secp256k1_js.schnorr.verify((0, _noble_hashes_utils_js.hexToBytes)(event.sig), (0, _noble_hashes_utils_js.hexToBytes)(hash), (0, _noble_hashes_utils_js.hexToBytes)(event.pubkey));
|
|
52
|
-
event[verifiedSymbol] = valid;
|
|
53
|
-
return valid;
|
|
54
|
-
} catch (err) {
|
|
55
|
-
event[verifiedSymbol] = false;
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function serializeEvent(evt) {
|
|
61
|
-
if (!validateEvent(evt)) throw new Error("can't serialize event with wrong or missing properties");
|
|
62
|
-
return JSON.stringify([
|
|
63
|
-
0,
|
|
64
|
-
evt.pubkey,
|
|
65
|
-
evt.created_at,
|
|
66
|
-
evt.kind,
|
|
67
|
-
evt.tags,
|
|
68
|
-
evt.content
|
|
69
|
-
]);
|
|
70
|
-
}
|
|
71
|
-
function getEventHash(event) {
|
|
72
|
-
return (0, _noble_hashes_utils_js.bytesToHex)((0, _noble_hashes_sha2_js.sha256)(utf8Encoder.encode(serializeEvent(event))));
|
|
73
|
-
}
|
|
74
|
-
var i = new JS();
|
|
75
|
-
var generateSecretKey = i.generateSecretKey;
|
|
76
|
-
var getPublicKey = i.getPublicKey;
|
|
77
|
-
var finalizeEvent = i.finalizeEvent;
|
|
78
|
-
var verifyEvent = i.verifyEvent;
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region node_modules/@frostr/igloo-core/dist/nostr.js
|
|
82
|
-
/**
|
|
83
|
-
* Converts a nostr secret key (nsec) to its hex representation
|
|
84
|
-
* @param nsec The nostr secret key in nsec format
|
|
85
|
-
* @returns The secret key in hex format
|
|
86
|
-
*/
|
|
87
|
-
function nsecToHex(nsec) {
|
|
88
|
-
try {
|
|
89
|
-
const { type, data } = require_dist.nip19_exports.decode(nsec);
|
|
90
|
-
if (type !== "nsec") throw new require_types.NostrError("Invalid nsec format");
|
|
91
|
-
return Buffer.from(data).toString("hex");
|
|
92
|
-
} catch (error) {
|
|
93
|
-
throw new require_types.NostrError(`Failed to decode nsec: ${error.message}`, {
|
|
94
|
-
nsec,
|
|
95
|
-
error
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Converts a hex secret key to nostr secret key (nsec) format
|
|
101
|
-
* @param hex The secret key in hex format
|
|
102
|
-
* @returns The secret key in nsec format
|
|
103
|
-
*/
|
|
104
|
-
function hexToNsec(hex) {
|
|
105
|
-
try {
|
|
106
|
-
validateHexKey(hex);
|
|
107
|
-
const bytes = new Uint8Array(Buffer.from(hex, "hex"));
|
|
108
|
-
return require_dist.nip19_exports.nsecEncode(bytes);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
throw new require_types.NostrError(`Failed to encode nsec: ${error.message}`, {
|
|
111
|
-
hex,
|
|
112
|
-
error
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Converts a hex public key to nostr public key (npub) format
|
|
118
|
-
* @param hex The public key in hex format
|
|
119
|
-
* @returns The public key in npub format
|
|
120
|
-
*/
|
|
121
|
-
function hexToNpub(hex) {
|
|
122
|
-
try {
|
|
123
|
-
validateHexKey(hex);
|
|
124
|
-
return require_dist.nip19_exports.npubEncode(hex);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
throw new require_types.NostrError(`Failed to encode npub: ${error.message}`, {
|
|
127
|
-
hex,
|
|
128
|
-
error
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Converts a nostr public key (npub) to its hex representation
|
|
134
|
-
* @param npub The nostr public key in npub format
|
|
135
|
-
* @returns The public key in hex format
|
|
136
|
-
*/
|
|
137
|
-
function npubToHex(npub) {
|
|
138
|
-
try {
|
|
139
|
-
const { type, data } = require_dist.nip19_exports.decode(npub);
|
|
140
|
-
if (type !== "npub") throw new require_types.NostrError("Invalid npub format");
|
|
141
|
-
return data;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
throw new require_types.NostrError(`Failed to decode npub: ${error.message}`, {
|
|
144
|
-
npub,
|
|
145
|
-
error
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Generates a new nostr key pair (nsec and npub)
|
|
151
|
-
* @returns Object containing both nsec and npub, plus hex versions
|
|
152
|
-
*/
|
|
153
|
-
function generateNostrKeyPair() {
|
|
154
|
-
try {
|
|
155
|
-
const sk = generateSecretKey();
|
|
156
|
-
const hexPublicKey = getPublicKey(sk);
|
|
157
|
-
const hexPrivateKey = Buffer.from(sk).toString("hex");
|
|
158
|
-
return {
|
|
159
|
-
nsec: require_dist.nip19_exports.nsecEncode(sk),
|
|
160
|
-
npub: require_dist.nip19_exports.npubEncode(hexPublicKey),
|
|
161
|
-
hexPrivateKey,
|
|
162
|
-
hexPublicKey
|
|
163
|
-
};
|
|
164
|
-
} catch (error) {
|
|
165
|
-
throw new require_types.NostrError(`Failed to generate nostr key pair: ${error.message}`, { error });
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Derives the public key from a private key
|
|
170
|
-
* @param privateKey The private key in hex or nsec format
|
|
171
|
-
* @returns Object containing npub and hex public key
|
|
172
|
-
*/
|
|
173
|
-
function derivePublicKey(privateKey) {
|
|
174
|
-
try {
|
|
175
|
-
let hexPrivateKey;
|
|
176
|
-
if (privateKey.startsWith("nsec")) hexPrivateKey = nsecToHex(privateKey);
|
|
177
|
-
else {
|
|
178
|
-
validateHexKey(privateKey);
|
|
179
|
-
hexPrivateKey = privateKey;
|
|
180
|
-
}
|
|
181
|
-
const hexPublicKey = getPublicKey(new Uint8Array(Buffer.from(hexPrivateKey, "hex")));
|
|
182
|
-
return {
|
|
183
|
-
npub: require_dist.nip19_exports.npubEncode(hexPublicKey),
|
|
184
|
-
hexPublicKey
|
|
185
|
-
};
|
|
186
|
-
} catch (error) {
|
|
187
|
-
throw new require_types.NostrError(`Failed to derive public key: ${error.message}`, {
|
|
188
|
-
privateKey: privateKey.startsWith("nsec") ? "[REDACTED]" : privateKey,
|
|
189
|
-
error
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Validates a hex key format (private or public)
|
|
195
|
-
* @param hex The hex string to validate
|
|
196
|
-
* @param keyType Optional key type for more specific validation
|
|
197
|
-
*/
|
|
198
|
-
function validateHexKey(hex, keyType) {
|
|
199
|
-
if (!hex || typeof hex !== "string") throw new require_types.NostrError("Hex key must be a non-empty string");
|
|
200
|
-
const expectedLength = keyType === "public" ? 64 : keyType === "private" ? 64 : 64;
|
|
201
|
-
if (!/^[0-9a-fA-F]+$/.test(hex)) throw new require_types.NostrError("Invalid hex format - must contain only hexadecimal characters");
|
|
202
|
-
if (hex.length !== expectedLength) throw new require_types.NostrError(`Invalid hex key length - expected ${expectedLength} characters, got ${hex.length}`);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Validates a nostr key format (nsec or npub)
|
|
206
|
-
* @param key The nostr key to validate
|
|
207
|
-
* @param expectedType Optional expected type ('nsec' or 'npub')
|
|
208
|
-
*/
|
|
209
|
-
function validateNostrKey(key, expectedType) {
|
|
210
|
-
try {
|
|
211
|
-
const { type } = require_dist.nip19_exports.decode(key);
|
|
212
|
-
if (expectedType && type !== expectedType) throw new require_types.NostrError(`Expected ${expectedType} but got ${type}`);
|
|
213
|
-
if (type !== "nsec" && type !== "npub") throw new require_types.NostrError(`Invalid nostr key type: ${type}`);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if (error instanceof require_types.NostrError) throw error;
|
|
216
|
-
throw new require_types.NostrError(`Invalid nostr key format: ${error.message}`, {
|
|
217
|
-
key: key.substring(0, 10) + "...",
|
|
218
|
-
error
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
//#endregion
|
|
224
|
-
Object.defineProperty(exports, 'derivePublicKey', {
|
|
225
|
-
enumerable: true,
|
|
226
|
-
get: function () {
|
|
227
|
-
return derivePublicKey;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
Object.defineProperty(exports, 'generateNostrKeyPair', {
|
|
231
|
-
enumerable: true,
|
|
232
|
-
get: function () {
|
|
233
|
-
return generateNostrKeyPair;
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
Object.defineProperty(exports, 'hexToNpub', {
|
|
237
|
-
enumerable: true,
|
|
238
|
-
get: function () {
|
|
239
|
-
return hexToNpub;
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
Object.defineProperty(exports, 'hexToNsec', {
|
|
243
|
-
enumerable: true,
|
|
244
|
-
get: function () {
|
|
245
|
-
return hexToNsec;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
Object.defineProperty(exports, 'npubToHex', {
|
|
249
|
-
enumerable: true,
|
|
250
|
-
get: function () {
|
|
251
|
-
return npubToHex;
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
Object.defineProperty(exports, 'nsecToHex', {
|
|
255
|
-
enumerable: true,
|
|
256
|
-
get: function () {
|
|
257
|
-
return nsecToHex;
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
Object.defineProperty(exports, 'validateHexKey', {
|
|
261
|
-
enumerable: true,
|
|
262
|
-
get: function () {
|
|
263
|
-
return validateHexKey;
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
Object.defineProperty(exports, 'validateNostrKey', {
|
|
267
|
-
enumerable: true,
|
|
268
|
-
get: function () {
|
|
269
|
-
return validateNostrKey;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
//# sourceMappingURL=nostr-Hv2tsnuI.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nostr-Hv2tsnuI.cjs","names":["schnorr","nip19","NostrError"],"sources":["../node_modules/nostr-tools/lib/esm/pure.js","../node_modules/@frostr/igloo-core/dist/nostr.js"],"sourcesContent":["// pure.ts\nimport { schnorr } from \"@noble/curves/secp256k1.js\";\nimport { bytesToHex as bytesToHex2, hexToBytes as hexToBytes2 } from \"@noble/hashes/utils.js\";\n\n// core.ts\nvar verifiedSymbol = Symbol(\"verified\");\nvar isRecord = (obj) => obj instanceof Object;\nfunction validateEvent(event) {\n if (!isRecord(event))\n return false;\n if (typeof event.kind !== \"number\")\n return false;\n if (typeof event.content !== \"string\")\n return false;\n if (typeof event.created_at !== \"number\")\n return false;\n if (typeof event.pubkey !== \"string\")\n return false;\n if (!event.pubkey.match(/^[a-f0-9]{64}$/))\n return false;\n if (!Array.isArray(event.tags))\n return false;\n for (let i2 = 0; i2 < event.tags.length; i2++) {\n let tag = event.tags[i2];\n if (!Array.isArray(tag))\n return false;\n for (let j = 0; j < tag.length; j++) {\n if (typeof tag[j] !== \"string\")\n return false;\n }\n }\n return true;\n}\nfunction sortEvents(events) {\n return events.sort((a, b) => {\n if (a.created_at !== b.created_at) {\n return b.created_at - a.created_at;\n }\n return a.id.localeCompare(b.id);\n });\n}\n\n// pure.ts\nimport { sha256 } from \"@noble/hashes/sha2.js\";\n\n// utils.ts\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils.js\";\nvar utf8Decoder = new TextDecoder(\"utf-8\");\nvar utf8Encoder = new TextEncoder();\n\n// pure.ts\nvar JS = class {\n generateSecretKey() {\n return schnorr.utils.randomSecretKey();\n }\n getPublicKey(secretKey) {\n return bytesToHex2(schnorr.getPublicKey(secretKey));\n }\n finalizeEvent(t, secretKey) {\n const event = t;\n event.pubkey = bytesToHex2(schnorr.getPublicKey(secretKey));\n event.id = getEventHash(event);\n event.sig = bytesToHex2(schnorr.sign(hexToBytes2(getEventHash(event)), secretKey));\n event[verifiedSymbol] = true;\n return event;\n }\n verifyEvent(event) {\n if (typeof event[verifiedSymbol] === \"boolean\")\n return event[verifiedSymbol];\n try {\n const hash = getEventHash(event);\n if (hash !== event.id) {\n event[verifiedSymbol] = false;\n return false;\n }\n const valid = schnorr.verify(hexToBytes2(event.sig), hexToBytes2(hash), hexToBytes2(event.pubkey));\n event[verifiedSymbol] = valid;\n return valid;\n } catch (err) {\n event[verifiedSymbol] = false;\n return false;\n }\n }\n};\nfunction serializeEvent(evt) {\n if (!validateEvent(evt))\n throw new Error(\"can't serialize event with wrong or missing properties\");\n return JSON.stringify([0, evt.pubkey, evt.created_at, evt.kind, evt.tags, evt.content]);\n}\nfunction getEventHash(event) {\n let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)));\n return bytesToHex2(eventHash);\n}\nvar i = new JS();\nvar generateSecretKey = i.generateSecretKey;\nvar getPublicKey = i.getPublicKey;\nvar finalizeEvent = i.finalizeEvent;\nvar verifyEvent = i.verifyEvent;\nexport {\n finalizeEvent,\n generateSecretKey,\n getEventHash,\n getPublicKey,\n serializeEvent,\n sortEvents,\n validateEvent,\n verifiedSymbol,\n verifyEvent\n};\n","import { nip19 } from 'nostr-tools';\nimport { generateSecretKey, getPublicKey } from 'nostr-tools/pure';\nimport { NostrError } from './types.js';\n/**\n * Converts a nostr secret key (nsec) to its hex representation\n * @param nsec The nostr secret key in nsec format\n * @returns The secret key in hex format\n */\nexport function nsecToHex(nsec) {\n try {\n const { type, data } = nip19.decode(nsec);\n if (type !== 'nsec') {\n throw new NostrError('Invalid nsec format');\n }\n return Buffer.from(data).toString('hex');\n }\n catch (error) {\n throw new NostrError(`Failed to decode nsec: ${error.message}`, { nsec, error });\n }\n}\n/**\n * Converts a hex secret key to nostr secret key (nsec) format\n * @param hex The secret key in hex format\n * @returns The secret key in nsec format\n */\nexport function hexToNsec(hex) {\n try {\n validateHexKey(hex);\n const bytes = new Uint8Array(Buffer.from(hex, 'hex'));\n return nip19.nsecEncode(bytes);\n }\n catch (error) {\n throw new NostrError(`Failed to encode nsec: ${error.message}`, { hex, error });\n }\n}\n/**\n * Converts a hex public key to nostr public key (npub) format\n * @param hex The public key in hex format\n * @returns The public key in npub format\n */\nexport function hexToNpub(hex) {\n try {\n validateHexKey(hex);\n return nip19.npubEncode(hex);\n }\n catch (error) {\n throw new NostrError(`Failed to encode npub: ${error.message}`, { hex, error });\n }\n}\n/**\n * Converts a nostr public key (npub) to its hex representation\n * @param npub The nostr public key in npub format\n * @returns The public key in hex format\n */\nexport function npubToHex(npub) {\n try {\n const { type, data } = nip19.decode(npub);\n if (type !== 'npub') {\n throw new NostrError('Invalid npub format');\n }\n return data;\n }\n catch (error) {\n throw new NostrError(`Failed to decode npub: ${error.message}`, { npub, error });\n }\n}\n/**\n * Generates a new nostr key pair (nsec and npub)\n * @returns Object containing both nsec and npub, plus hex versions\n */\nexport function generateNostrKeyPair() {\n try {\n const sk = generateSecretKey();\n const hexPublicKey = getPublicKey(sk);\n const hexPrivateKey = Buffer.from(sk).toString('hex');\n return {\n nsec: nip19.nsecEncode(sk),\n npub: nip19.npubEncode(hexPublicKey),\n hexPrivateKey,\n hexPublicKey\n };\n }\n catch (error) {\n throw new NostrError(`Failed to generate nostr key pair: ${error.message}`, { error });\n }\n}\n/**\n * Derives the public key from a private key\n * @param privateKey The private key in hex or nsec format\n * @returns Object containing npub and hex public key\n */\nexport function derivePublicKey(privateKey) {\n try {\n let hexPrivateKey;\n if (privateKey.startsWith('nsec')) {\n hexPrivateKey = nsecToHex(privateKey);\n }\n else {\n validateHexKey(privateKey);\n hexPrivateKey = privateKey;\n }\n const privateKeyBytes = new Uint8Array(Buffer.from(hexPrivateKey, 'hex'));\n const hexPublicKey = getPublicKey(privateKeyBytes);\n return {\n npub: nip19.npubEncode(hexPublicKey),\n hexPublicKey\n };\n }\n catch (error) {\n throw new NostrError(`Failed to derive public key: ${error.message}`, { privateKey: privateKey.startsWith('nsec') ? '[REDACTED]' : privateKey, error });\n }\n}\n/**\n * Validates a hex key format (private or public)\n * @param hex The hex string to validate\n * @param keyType Optional key type for more specific validation\n */\nexport function validateHexKey(hex, keyType) {\n if (!hex || typeof hex !== 'string') {\n throw new NostrError('Hex key must be a non-empty string');\n }\n const expectedLength = keyType === 'public' ? 64 : keyType === 'private' ? 64 : 64;\n const hexRegex = /^[0-9a-fA-F]+$/;\n if (!hexRegex.test(hex)) {\n throw new NostrError('Invalid hex format - must contain only hexadecimal characters');\n }\n if (hex.length !== expectedLength) {\n throw new NostrError(`Invalid hex key length - expected ${expectedLength} characters, got ${hex.length}`);\n }\n}\n/**\n * Validates a nostr key format (nsec or npub)\n * @param key The nostr key to validate\n * @param expectedType Optional expected type ('nsec' or 'npub')\n */\nexport function validateNostrKey(key, expectedType) {\n try {\n const { type } = nip19.decode(key);\n if (expectedType && type !== expectedType) {\n throw new NostrError(`Expected ${expectedType} but got ${type}`);\n }\n if (type !== 'nsec' && type !== 'npub') {\n throw new NostrError(`Invalid nostr key type: ${type}`);\n }\n }\n catch (error) {\n if (error instanceof NostrError) {\n throw error;\n }\n throw new NostrError(`Invalid nostr key format: ${error.message}`, { key: key.substring(0, 10) + '...', error });\n }\n}\n"],"x_google_ignoreList":[0,1],"mappings":";;;;;;;;AAKA,IAAI,iBAAiB,OAAO,WAAW;AACvC,IAAI,YAAY,QAAQ,eAAe;AACvC,SAAS,cAAc,OAAO;AAC5B,KAAI,CAAC,SAAS,MAAM,CAClB,QAAO;AACT,KAAI,OAAO,MAAM,SAAS,SACxB,QAAO;AACT,KAAI,OAAO,MAAM,YAAY,SAC3B,QAAO;AACT,KAAI,OAAO,MAAM,eAAe,SAC9B,QAAO;AACT,KAAI,OAAO,MAAM,WAAW,SAC1B,QAAO;AACT,KAAI,CAAC,MAAM,OAAO,MAAM,iBAAiB,CACvC,QAAO;AACT,KAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAC5B,QAAO;AACT,MAAK,IAAI,KAAK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AAM;AAEV,QAAM,IAAIA,yBAAW,6BAA6B,MAAM,WAAW;GAAE,KAAK,IAAI,UAAU,GAAG,GAAG,GAAG;GAAO;GAAO,CAAC"}
|
package/dist/nostr-ZwJe_DlZ.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import "./types-CTm_FHYD.mjs";
|
|
2
|
-
import { a as npubToHex, c as validateNostrKey, i as hexToNsec, n as generateNostrKeyPair, o as nsecToHex, r as hexToNpub, s as validateHexKey, t as derivePublicKey } from "./nostr-D4E52XRU.mjs";
|
|
3
|
-
|
|
4
|
-
export { derivePublicKey, generateNostrKeyPair, hexToNpub, hexToNsec, npubToHex, nsecToHex, validateHexKey, validateNostrKey };
|