nostr-crypto-utils 0.5.1 → 0.5.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.
Files changed (41) hide show
  1. package/dist/browser/crypto.nostr-crypto-utils.min.js +15 -1
  2. package/dist/browser/crypto.nostr-crypto-utils.min.js.map +7 -0
  3. package/dist/browser/main.nostr-crypto-utils.min.js +32 -0
  4. package/dist/browser/main.nostr-crypto-utils.min.js.map +7 -0
  5. package/dist/browser/nip-44.nostr-crypto-utils.min.js +21 -2
  6. package/dist/browser/nip-44.nostr-crypto-utils.min.js.map +7 -0
  7. package/dist/browser/nip-46.nostr-crypto-utils.min.js +21 -2
  8. package/dist/browser/nip-46.nostr-crypto-utils.min.js.map +7 -0
  9. package/dist/browser/nip-49.nostr-crypto-utils.min.js +13 -1
  10. package/dist/browser/nip-49.nostr-crypto-utils.min.js.map +7 -0
  11. package/dist/browser/protocol.nostr-crypto-utils.min.js +2 -1
  12. package/dist/browser/protocol.nostr-crypto-utils.min.js.map +7 -0
  13. package/dist/browser/validation.nostr-crypto-utils.min.js +15 -1
  14. package/dist/browser/validation.nostr-crypto-utils.min.js.map +7 -0
  15. package/package.json +4 -7
  16. package/dist/browser/116.nostr-crypto-utils.min.js +0 -2
  17. package/dist/browser/116.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  18. package/dist/browser/126.nostr-crypto-utils.min.js +0 -2
  19. package/dist/browser/126.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
  20. package/dist/browser/287.nostr-crypto-utils.min.js +0 -2
  21. package/dist/browser/287.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  22. package/dist/browser/343.nostr-crypto-utils.min.js +0 -1
  23. package/dist/browser/348.nostr-crypto-utils.min.js +0 -2
  24. package/dist/browser/348.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  25. package/dist/browser/524.nostr-crypto-utils.min.js +0 -1
  26. package/dist/browser/575.nostr-crypto-utils.min.js +0 -2
  27. package/dist/browser/575.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  28. package/dist/browser/615.nostr-crypto-utils.min.js +0 -2
  29. package/dist/browser/615.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  30. package/dist/browser/668.nostr-crypto-utils.min.js +0 -2
  31. package/dist/browser/668.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  32. package/dist/browser/705.nostr-crypto-utils.min.js +0 -2
  33. package/dist/browser/705.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  34. package/dist/browser/732.nostr-crypto-utils.min.js +0 -1
  35. package/dist/browser/843.nostr-crypto-utils.min.js +0 -2
  36. package/dist/browser/843.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
  37. package/dist/browser/main-31743c5a.nostr-crypto-utils.min.js +0 -1
  38. package/dist/browser/main-96d4916e.nostr-crypto-utils.min.js +0 -1
  39. package/dist/browser/main-9fdc67c2.nostr-crypto-utils.min.js +0 -1
  40. package/dist/browser/nip-44.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  41. package/dist/browser/nip-46.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
@@ -1 +1,2 @@
1
- !function(E,N){"object"==typeof exports&&"object"==typeof module?module.exports=N():"function"==typeof define&&define.amd?define([],N):"object"==typeof exports?exports.NostrCryptoUtils=N():(E.NostrCryptoUtils=E.NostrCryptoUtils||{},E.NostrCryptoUtils.protocol=N())}(this,()=>(()=>{"use strict";var E,N,T={};return function(E){E[E.SET_METADATA=0]="SET_METADATA",E[E.TEXT_NOTE=1]="TEXT_NOTE",E[E.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",E[E.CONTACTS=3]="CONTACTS",E[E.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",E[E.EVENT_DELETION=5]="EVENT_DELETION",E[E.REPOST=6]="REPOST",E[E.REACTION=7]="REACTION",E[E.CHANNEL_CREATION=40]="CHANNEL_CREATION",E[E.CHANNEL_METADATA=41]="CHANNEL_METADATA",E[E.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",E[E.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",E[E.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",E[E.AUTH=22242]="AUTH",E[E.AUTH_RESPONSE=22243]="AUTH_RESPONSE"}(E||(E={})),function(E){E.EVENT="EVENT",E.NOTICE="NOTICE",E.OK="OK",E.EOSE="EOSE",E.REQ="REQ",E.CLOSE="CLOSE",E.AUTH="AUTH"}(N||(N={})),T.default})());
1
+ "use strict";var NostrCryptoUtils=NostrCryptoUtils||{};NostrCryptoUtils.Protocol=(()=>{var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},p=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of c(e))!E.call(t,i)&&i!==r&&o(t,i,{get:()=>e[i],enumerable:!(n=g(e,i))||n.enumerable});return t};var l=t=>p(o({},"__esModule",{value:!0}),t);var F={};u(F,{createAuthorFilter:()=>_,createChannelMessageEvent:()=>A,createDirectMessageEvent:()=>T,createFilter:()=>C,createKindFilter:()=>O,createMetadataEvent:()=>b,createReplyFilter:()=>h,createTextNoteEvent:()=>d,extractMentionedPubkeys:()=>R,extractReferencedEvents:()=>m,formatAuthForRelay:()=>S,formatCloseForRelay:()=>y,formatEventForRelay:()=>f,formatSubscriptionForRelay:()=>x,parseMessage:()=>N});function f(t){return["EVENT",t]}function x(t){return["REQ",t.id,...t.filters]}function y(t){return["CLOSE",t]}function S(t){return["AUTH",t]}function N(t){try{let e=JSON.parse(t);if(!Array.isArray(e)||e.length<2)throw new Error("Invalid message format");let[r,...n]=e;switch(r){case"EVENT":return{type:"EVENT",event:n[0]};case"REQ":return{type:"REQ",subscriptionId:n[0],filters:n.slice(1)};case"CLOSE":return{type:"CLOSE",subscriptionId:n[0]};case"OK":return{type:"OK",eventId:n[0],accepted:n[1],message:n[2]};case"EOSE":return{type:"EOSE",subscriptionId:n[0]};default:throw new Error(`Unknown message type: ${r}`)}}catch(e){let r=e instanceof Error?e.message:String(e);throw new Error(`Failed to parse message: ${r}`)}}function b(t,e){let r=typeof e=="string"?e:e.hex;return{kind:0,content:JSON.stringify(t),created_at:Math.floor(Date.now()/1e3),tags:[],pubkey:r}}function d(t,e,r,n){let i=typeof e=="string"?e:e.hex,s=[];return r&&s.push(["e",r]),n&&n.forEach(a=>{s.push(["p",a])}),{kind:1,content:t,created_at:Math.floor(Date.now()/1e3),tags:s,pubkey:i}}function T(t,e,r){let n=typeof t=="string"?t:t.hex,i=typeof r=="string"?r:r.hex;return{kind:4,content:e,created_at:Math.floor(Date.now()/1e3),tags:[["p",n]],pubkey:i}}function A(t,e,r,n){let i=typeof r=="string"?r:r.hex,s=[["e",t,"","root"]];return n&&s.push(["e",n,"","reply"]),{kind:42,content:e,created_at:Math.floor(Date.now()/1e3),tags:s,pubkey:i}}function m(t){return t.tags.filter(e=>e[0]==="e").map(e=>e[1])}function R(t){return t.tags.filter(e=>e[0]==="p").map(e=>e[1])}function O(t,e){return{kinds:[t],limit:e}}function _(t,e,r){return{authors:[t],kinds:e,limit:r}}function h(t,e){return{"#e":[t],kinds:[1,42],limit:e}}function C(t){return{authors:[t],kinds:[1,42]}}return l(F);})();
2
+ //# sourceMappingURL=protocol.nostr-crypto-utils.min.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/protocol/index.ts"],
4
+ "sourcesContent": ["/**\n * @module protocol\n * @description Core Nostr protocol implementation\n */\n\nimport { \n NostrEvent, \n NostrFilter, \n NostrEventKind, \n SignedNostrEvent,\n NostrMessageType,\n UnsignedEvent,\n PublicKey,\n NostrResponse,\n NostrSubscription\n} from '../types/base';\n\n/**\n * Formats an event for relay transmission according to NIP-01\n * @category Message Handling\n * @param {SignedNostrEvent} event - The signed Nostr event to format\n * @returns {[string, SignedNostrEvent]} A tuple of ['EVENT', event] ready for relay transmission\n */\nexport function formatEventForRelay(event: SignedNostrEvent): [string, SignedNostrEvent] {\n return ['EVENT', event];\n}\n\n/**\n * Formats a subscription request for relay transmission according to NIP-01\n * @category Message Handling\n * @param {NostrSubscription} subscription - The subscription request containing filters\n * @returns {[string, string, ...NostrFilter[]]} A tuple of ['REQ', subscriptionId, ...filters] ready for relay transmission\n */\nexport function formatSubscriptionForRelay(subscription: NostrSubscription): [string, string, ...NostrFilter[]] {\n return ['REQ', subscription.id, ...subscription.filters];\n}\n\n/**\n * Formats a close request for relay transmission according to NIP-01\n * @category Message Handling\n * @param {string} subscriptionId - The ID of the subscription to close\n * @returns {[string, string]} A tuple of ['CLOSE', subscriptionId] ready for relay transmission\n */\nexport function formatCloseForRelay(subscriptionId: string): [string, string] {\n return ['CLOSE', subscriptionId];\n}\n\n/**\n * Formats an auth request for relay transmission according to NIP-42\n * @category Message Handling\n * @param {SignedNostrEvent} event - The signed authentication event\n * @returns {[string, SignedNostrEvent]} A tuple of ['AUTH', event] ready for relay transmission\n */\nexport function formatAuthForRelay(event: SignedNostrEvent): [string, SignedNostrEvent] {\n return ['AUTH', event];\n}\n\n/**\n * Parses a Nostr message from a relay\n * @category Message Handling\n * @param {string} message - The message to parse\n * @returns {NostrResponse} Parsed message\n */\nexport function parseMessage(message: string): NostrResponse {\n try {\n const parsed = JSON.parse(message);\n if (!Array.isArray(parsed) || parsed.length < 2) {\n throw new Error('Invalid message format');\n }\n\n const [type, ...payload] = parsed;\n\n switch (type) {\n case 'EVENT':\n return {\n type: NostrMessageType.EVENT,\n event: payload[0]\n };\n\n case 'REQ':\n return {\n type: NostrMessageType.REQ,\n subscriptionId: payload[0],\n filters: payload.slice(1)\n };\n\n case 'CLOSE':\n return {\n type: NostrMessageType.CLOSE,\n subscriptionId: payload[0]\n };\n\n case 'OK':\n return {\n type: NostrMessageType.OK,\n eventId: payload[0],\n accepted: payload[1],\n message: payload[2]\n };\n\n case 'EOSE':\n return {\n type: NostrMessageType.EOSE,\n subscriptionId: payload[0]\n };\n\n default:\n throw new Error(`Unknown message type: ${type}`);\n }\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to parse message: ${errorMessage}`);\n }\n}\n\n/**\n * Creates a metadata event according to NIP-01\n * @category Event Creation\n * @param {Record<string, string>} metadata - User metadata (name, about, picture, etc.)\n * @param {string | PublicKey} pubkey - Public key of the user\n * @returns {UnsignedEvent} Created metadata event\n */\nexport function createMetadataEvent(metadata: Record<string, string>, pubkey: string | PublicKey): UnsignedEvent {\n const pubkeyValue = typeof pubkey === 'string' ? pubkey : pubkey.hex;\n return {\n kind: NostrEventKind.SET_METADATA,\n content: JSON.stringify(metadata),\n created_at: Math.floor(Date.now() / 1000),\n tags: [],\n pubkey: pubkeyValue\n };\n}\n\n/**\n * Creates a text note event according to NIP-01\n * @category Event Creation\n * @param {string} content - The text content of the note\n * @param {string | PublicKey} pubkey - Public key of the author\n * @param {string} [replyTo] - Optional ID of event being replied to\n * @param {string[]} [mentions] - Optional array of pubkeys to mention\n * @returns {UnsignedEvent} Created text note event\n */\nexport function createTextNoteEvent(\n content: string,\n pubkey: string | PublicKey,\n replyTo?: string,\n mentions?: string[]\n): UnsignedEvent {\n const pubkeyValue = typeof pubkey === 'string' ? pubkey : pubkey.hex;\n const tags: string[][] = [];\n \n if (replyTo) {\n tags.push(['e', replyTo]);\n }\n \n if (mentions) {\n mentions.forEach(pubkey => {\n tags.push(['p', pubkey]);\n });\n }\n\n return {\n kind: NostrEventKind.TEXT_NOTE,\n content,\n created_at: Math.floor(Date.now() / 1000),\n tags,\n pubkey: pubkeyValue\n };\n}\n\n/**\n * Creates a direct message event according to NIP-04\n * @category Event Creation\n * @param {string | PublicKey} recipientPubkey - Public key of message recipient\n * @param {string} content - Message content (will be encrypted)\n * @param {string | PublicKey} senderPubkey - Public key of the sender\n * @returns {UnsignedEvent} Created direct message event\n */\nexport function createDirectMessageEvent(\n recipientPubkey: string | PublicKey,\n content: string,\n senderPubkey: string | PublicKey\n): UnsignedEvent {\n const recipientKey = typeof recipientPubkey === 'string' ? recipientPubkey : recipientPubkey.hex;\n const senderKey = typeof senderPubkey === 'string' ? senderPubkey : senderPubkey.hex;\n \n return {\n kind: NostrEventKind.ENCRYPTED_DIRECT_MESSAGE,\n content,\n created_at: Math.floor(Date.now() / 1000),\n tags: [['p', recipientKey]],\n pubkey: senderKey\n };\n}\n\n/**\n * Creates a channel message event according to NIP-28\n * @category Event Creation\n * @param {string} channelId - ID of the channel\n * @param {string} content - Message content\n * @param {string | PublicKey} authorPubkey - Public key of the message author\n * @param {string} [replyTo] - Optional ID of message being replied to\n * @returns {UnsignedEvent} Created channel message event\n */\nexport function createChannelMessageEvent(\n channelId: string,\n content: string,\n authorPubkey: string | PublicKey,\n replyTo?: string\n): UnsignedEvent {\n const pubkeyValue = typeof authorPubkey === 'string' ? authorPubkey : authorPubkey.hex;\n const tags = [['e', channelId, '', 'root']];\n if (replyTo) {\n tags.push(['e', replyTo, '', 'reply']);\n }\n return {\n kind: NostrEventKind.CHANNEL_MESSAGE,\n content,\n created_at: Math.floor(Date.now() / 1000),\n tags,\n pubkey: pubkeyValue\n };\n}\n\n/**\n * Extracts referenced event IDs from an event's tags\n * @category Event Operations\n * @param {NostrEvent} event - Event to extract references from\n * @returns {string[]} Array of referenced event IDs\n */\nexport function extractReferencedEvents(event: NostrEvent): string[] {\n return event.tags\n .filter((tag: string[]) => tag[0] === 'e')\n .map((tag: string[]) => tag[1]);\n}\n\n/**\n * Extracts mentioned pubkeys from an event's tags\n * @category Event Operations\n * @param {NostrEvent} event - Event to extract mentions from\n * @returns {string[]} Array of mentioned pubkeys\n */\nexport function extractMentionedPubkeys(event: NostrEvent): string[] {\n return event.tags\n .filter((tag: string[]) => tag[0] === 'p')\n .map((tag: string[]) => tag[1]);\n}\n\n/**\n * Creates a subscription filter for a specific event kind\n * @category Filter Creation\n * @param {number} kind - Event kind to filter for\n * @param {number} [limit] - Optional maximum number of events to receive\n * @returns {NostrFilter} Created filter\n */\nexport function createKindFilter(kind: number, limit?: number): NostrFilter {\n return {\n kinds: [kind],\n limit\n };\n}\n\n/**\n * Creates a subscription filter for events by a specific author\n * @category Filter Creation\n * @param {string} pubkey - Author's public key\n * @param {number[]} [kinds] - Optional array of event kinds to filter\n * @param {number} [limit] - Optional maximum number of events to receive\n * @returns {NostrFilter} Created filter\n */\nexport function createAuthorFilter(pubkey: string, kinds?: number[], limit?: number): NostrFilter {\n return {\n authors: [pubkey],\n kinds,\n limit\n };\n}\n\n/**\n * Creates a subscription filter for replies to a specific event\n * @category Filter Creation\n * @param {string} eventId - ID of the event to find replies to\n * @param {number} [limit] - Optional maximum number of replies to receive\n * @returns {NostrFilter} Created filter\n */\nexport function createReplyFilter(eventId: string, limit?: number): NostrFilter {\n return {\n '#e': [eventId],\n kinds: [1, 42],\n limit\n };\n}\n\n/**\n * Creates a subscription filter for a specific author\n * @category Filter Creation\n * @param {string} pubkey - Author's public key\n * @returns {NostrFilter} Created filter\n */\nexport function createFilter(pubkey: string): NostrFilter {\n return {\n authors: [pubkey],\n kinds: [\n NostrEventKind.TEXT_NOTE,\n NostrEventKind.CHANNEL_MESSAGE\n ]\n };\n}\n"],
5
+ "mappings": "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",
6
+ "names": ["index_exports", "__export", "createAuthorFilter", "createChannelMessageEvent", "createDirectMessageEvent", "createFilter", "createKindFilter", "createMetadataEvent", "createReplyFilter", "createTextNoteEvent", "extractMentionedPubkeys", "extractReferencedEvents", "formatAuthForRelay", "formatCloseForRelay", "formatEventForRelay", "formatSubscriptionForRelay", "parseMessage", "formatEventForRelay", "event", "formatSubscriptionForRelay", "subscription", "formatCloseForRelay", "subscriptionId", "formatAuthForRelay", "parseMessage", "message", "parsed", "type", "payload", "error", "errorMessage", "createMetadataEvent", "metadata", "pubkey", "pubkeyValue", "createTextNoteEvent", "content", "replyTo", "mentions", "tags", "createDirectMessageEvent", "recipientPubkey", "senderPubkey", "recipientKey", "senderKey", "createChannelMessageEvent", "channelId", "authorPubkey", "extractReferencedEvents", "tag", "extractMentionedPubkeys", "createKindFilter", "kind", "limit", "createAuthorFilter", "kinds", "createReplyFilter", "eventId", "createFilter"]
7
+ }
@@ -1 +1,15 @@
1
- !function(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.NostrCryptoUtils=o():(t.NostrCryptoUtils=t.NostrCryptoUtils||{},t.NostrCryptoUtils.validation=o())}(this,()=>(()=>{"use strict";var t={};return t.default})());
1
+ "use strict";var NostrCryptoUtils=NostrCryptoUtils||{};NostrCryptoUtils.Validation=(()=>{var Qt=Object.defineProperty;var bn=Object.getOwnPropertyDescriptor;var pn=Object.getOwnPropertyNames;var xn=Object.prototype.hasOwnProperty;var yn=(e,t)=>{for(var r in t)Qt(e,r,{get:t[r],enumerable:!0})},gn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pn(t))!xn.call(e,o)&&o!==r&&Qt(e,o,{get:()=>t[o],enumerable:!(n=bn(t,o))||n.enumerable});return e};var mn=e=>gn(Qt({},"__esModule",{value:!0}),e);var Pn={};yn(Pn,{getPublicKeyHex:()=>Gn,validateEvent:()=>dn,validateFilter:()=>hn,validatePublicKey:()=>zn,validateSignedEvent:()=>Yn,validateSubscription:()=>$n});function Jt(e){if(typeof e!="object"||e===null)return!1;let t=e;if(typeof t.kind!="number"||!Number.isInteger(t.kind)||t.kind<0||typeof t.content!="string"||typeof t.created_at!="number"||!Number.isInteger(t.created_at))return!1;if(t.pubkey!==void 0)if(typeof t.pubkey=="string"){if(!t.pubkey)return!1}else if(typeof t.pubkey=="object"&&t.pubkey!==null){let r=t.pubkey;if(typeof r.hex!="string"||!r.hex)return!1}else return!1;return!(!Array.isArray(t.tags)||!t.tags.every(r=>Array.isArray(r)&&r.every(n=>typeof n=="string")))}function Ee(e){if(!e||typeof e!="object")return!1;let t=e;if(!Jt(e))return!1;if(typeof t.pubkey=="string"){if(!t.pubkey)return!1}else if(typeof t.pubkey=="object"&&t.pubkey!==null){let r=t.pubkey;if(typeof r.hex!="string"||!r.hex)return!1}else return!1;return!(typeof t.id!="string"||!t.id||typeof t.sig!="string"||!t.sig)}function Be(e){if(typeof e!="object"||e===null)return!1;let t=e,r=["ids","authors","kinds","since","until","limit","#e","#p","#t"];return!(!Object.keys(t).every(o=>r.includes(o))||t.ids!==void 0&&(!Array.isArray(t.ids)||!t.ids.every(o=>typeof o=="string"))||t.authors!==void 0&&(!Array.isArray(t.authors)||!t.authors.every(o=>typeof o=="string"))||t.kinds!==void 0&&(!Array.isArray(t.kinds)||!t.kinds.every(o=>typeof o=="number"&&Number.isInteger(o)&&o>=0))||t["#e"]!==void 0&&(!Array.isArray(t["#e"])||!t["#e"].every(o=>typeof o=="string"))||t["#p"]!==void 0&&(!Array.isArray(t["#p"])||!t["#p"].every(o=>typeof o=="string"))||t["#t"]!==void 0&&(!Array.isArray(t["#t"])||!t["#t"].every(o=>typeof o=="string"))||t.since!==void 0&&typeof t.since!="number"||t.until!==void 0&&typeof t.until!="number"||t.limit!==void 0&&typeof t.limit!="number")}var ft=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function at(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function At(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function z(e,...t){if(!at(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Tt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");At(e.outputLen),At(e.blockLen)}function yt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Se(e,t){z(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Vt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function $(e,t){return e<<32-t|e>>>t}var Ae=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function P(e){if(z(e),Ae)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=wn[e[r]];return t}var W={_0:48,_9:57,A:65,F:70,a:97,f:102};function ve(e){if(e>=W._0&&e<=W._9)return e-W._0;if(e>=W.A&&e<=W.F)return e-(W.A-10);if(e>=W.a&&e<=W.f)return e-(W.a-10)}function Y(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ae)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ve(e.charCodeAt(s)),c=ve(e.charCodeAt(s+1));if(i===void 0||c===void 0){let f=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+c}return n}function Ct(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function It(e){return typeof e=="string"&&(e=Ct(e)),z(e),e}function K(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];z(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var xt=class{};function Ie(e){let t=n=>e().update(It(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function lt(e=32){if(ft&&typeof ft.getRandomValues=="function")return ft.getRandomValues(new Uint8Array(e));if(ft&&typeof ft.randomBytes=="function")return Uint8Array.from(ft.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function En(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),f=n?4:0,b=n?0:4;e.setUint32(t+f,i,n),e.setUint32(t+b,c,n)}function _e(e,t,r){return e&t^~e&r}function He(e,t,r){return e&t^e&r^t&r}var Dt=class extends xt{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Vt(this.buffer)}update(t){yt(this),t=It(t),z(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=Vt(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){yt(this),Se(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let y=i;y<o;y++)r[y]=0;En(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Vt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let b=f/4,p=this.get();if(b>p.length)throw new Error("_sha2: outputLen bigger than state");for(let y=0;y<b;y++)c.setUint32(4*y,p[y],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},X=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Bn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),et=new Uint32Array(64),Zt=class extends Dt{constructor(t=32){super(64,t,8,!1),this.A=X[0]|0,this.B=X[1]|0,this.C=X[2]|0,this.D=X[3]|0,this.E=X[4]|0,this.F=X[5]|0,this.G=X[6]|0,this.H=X[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:f}=this;return[t,r,n,o,s,i,c,f]}set(t,r,n,o,s,i,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=f|0}process(t,r){for(let y=0;y<16;y++,r+=4)et[y]=t.getUint32(r,!1);for(let y=16;y<64;y++){let a=et[y-15],l=et[y-2],m=$(a,7)^$(a,18)^a>>>3,B=$(l,17)^$(l,19)^l>>>10;et[y]=B+et[y-7]+m+et[y-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:b,H:p}=this;for(let y=0;y<64;y++){let a=$(c,6)^$(c,11)^$(c,25),l=p+a+_e(c,f,b)+Bn[y]+et[y]|0,B=($(n,2)^$(n,13)^$(n,22))+He(n,o,s)|0;p=b,b=f,f=c,c=i+l|0,i=s,s=o,o=n,n=l+B|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,b=b+this.G|0,p=p+this.H|0,this.set(n,o,s,i,c,f,b,p)}roundClean(){ut(et)}destroy(){this.set(0,0,0,0,0,0,0,0),ut(this.buffer)}};var gt=Ie(()=>new Zt);var jt=class extends xt{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Tt(t);let n=It(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ut(s)}update(t){return yt(this),this.iHash.update(t),this}digestInto(t){yt(this),z(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ft=(e,t,r)=>new jt(e,t).update(r).digest();Ft.create=(e,t)=>new jt(e,t);var ne=BigInt(0),ee=BigInt(1);function _t(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function nt(e,t,r=""){let n=at(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return e}function Ht(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ne(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ne:BigInt("0x"+e)}function Q(e){return Ne(P(e))}function re(e){return z(e),Ne(P(Uint8Array.from(e).reverse()))}function mt(e,t){return Y(e.toString(16).padStart(t*2,"0"))}function oe(e,t){return mt(e,t).reverse()}function U(e,t,r){let n;if(typeof t=="string")try{n=Y(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(at(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var te=e=>typeof e=="bigint"&&ne<=e;function Nt(e,t,r){return te(e)&&te(t)&&te(r)&&t<=e&&e<r}function Re(e,t,r,n){if(!Nt(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Kt(e){let t;for(t=0;e>ne;e>>=ee,t+=1);return t}var rt=e=>(ee<<BigInt(e))-ee;function Oe(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=l=>new Uint8Array(l),o=l=>Uint8Array.of(l),s=n(e),i=n(e),c=0,f=()=>{s.fill(1),i.fill(0),c=0},b=(...l)=>r(i,s,...l),p=(l=n(0))=>{i=b(o(0),l),s=b(),l.length!==0&&(i=b(o(1),l),s=b())},y=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,m=[];for(;l<t;){s=b();let B=s.slice();m.push(B),l+=s.length}return K(...m)};return(l,m)=>{f(),p(l);let B;for(;!(B=m(y()));)p();return f(),B}}function Rt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function se(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Z=BigInt(0),D=BigInt(1),dt=BigInt(2),Le=BigInt(3),qe=BigInt(4),Te=BigInt(5),vn=BigInt(7),Ve=BigInt(8),Sn=BigInt(9),Ce=BigInt(16);function M(e,t){let r=e%t;return r>=Z?r:t+r}function G(e,t,r){let n=e;for(;t-- >Z;)n*=n,n%=r;return n}function ke(e,t){if(e===Z)throw new Error("invert: expected non-zero number");if(t<=Z)throw new Error("invert: expected positive modulus, got "+t);let r=M(e,t),n=t,o=Z,s=D,i=D,c=Z;for(;r!==Z;){let b=n/r,p=n%r,y=o-i*b,a=s-c*b;n=r,r=p,o=i,s=c,i=y,c=a}if(n!==D)throw new Error("invert: does not exist");return M(o,t)}function ie(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function De(e,t){let r=(e.ORDER+D)/qe,n=e.pow(t,r);return ie(e,n,t),n}function An(e,t){let r=(e.ORDER-Te)/Ve,n=e.mul(t,dt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,dt),o),c=e.mul(s,e.sub(i,e.ONE));return ie(e,c,t),c}function In(e){let t=ot(e),r=Ze(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+vn)/Ce;return(c,f)=>{let b=c.pow(f,i),p=c.mul(b,n),y=c.mul(b,o),a=c.mul(b,s),l=c.eql(c.sqr(p),f),m=c.eql(c.sqr(y),f);b=c.cmov(b,p,l),p=c.cmov(a,y,m);let B=c.eql(c.sqr(p),f),N=c.cmov(b,p,B);return ie(c,N,f),N}}function Ze(e){if(e<Le)throw new Error("sqrt is not defined for small field");let t=e-D,r=0;for(;t%dt===Z;)t/=dt,r++;let n=dt,o=ot(e);for(;Ue(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return De;let s=o.pow(n,t),i=(t+D)/dt;return function(f,b){if(f.is0(b))return b;if(Ue(f,b)!==1)throw new Error("Cannot find square root");let p=r,y=f.mul(f.ONE,s),a=f.pow(b,t),l=f.pow(b,i);for(;!f.eql(a,f.ONE);){if(f.is0(a))return f.ZERO;let m=1,B=f.sqr(a);for(;!f.eql(B,f.ONE);)if(m++,B=f.sqr(B),m===p)throw new Error("Cannot find square root");let N=D<<BigInt(p-m-1),L=f.pow(y,N);p=m,y=f.sqr(L),a=f.mul(a,y),l=f.mul(l,L)}return l}}function _n(e){return e%qe===Le?De:e%Ve===Te?An:e%Ce===Sn?In(e):Ze(e)}var Hn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ce(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Hn.reduce((n,o)=>(n[o]="function",n),t);return Rt(e,r),e}function Nn(e,t,r){if(r<Z)throw new Error("invalid exponent, negatives unsupported");if(r===Z)return e.ONE;if(r===D)return t;let n=e.ONE,o=t;for(;r>Z;)r&D&&(n=e.mul(n,o)),o=e.sqr(o),r>>=D;return n}function Mt(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,f)=>e.is0(c)?i:(n[f]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,f)=>e.is0(c)?i:(n[f]=e.mul(i,n[f]),e.mul(i,c)),s),n}function Ue(e,t){let r=(e.ORDER-D)/dt,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Gt(e,t){t!==void 0&&At(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ot(e,t,r=!1,n={}){if(e<=Z)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let a=t;a.BITS&&(o=a.BITS),a.sqrt&&(s=a.sqrt),typeof a.isLE=="boolean"&&(r=a.isLE),typeof a.modFromBytes=="boolean"&&(i=a.modFromBytes),c=a.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:f,nByteLength:b}=Gt(e,o);if(b>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,y=Object.freeze({ORDER:e,isLE:r,BITS:f,BYTES:b,MASK:rt(f),ZERO:Z,ONE:D,allowedLengths:c,create:a=>M(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return Z<=a&&a<e},is0:a=>a===Z,isValidNot0:a=>!y.is0(a)&&y.isValid(a),isOdd:a=>(a&D)===D,neg:a=>M(-a,e),eql:(a,l)=>a===l,sqr:a=>M(a*a,e),add:(a,l)=>M(a+l,e),sub:(a,l)=>M(a-l,e),mul:(a,l)=>M(a*l,e),pow:(a,l)=>Nn(y,a,l),div:(a,l)=>M(a*ke(l,e),e),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>ke(a,e),sqrt:s||(a=>(p||(p=_n(e)),p(y,a))),toBytes:a=>r?oe(a,b):mt(a,b),fromBytes:(a,l=!0)=>{if(c){if(!c.includes(a.length)||a.length>b)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+a.length);let B=new Uint8Array(b);B.set(a,r?0:B.length-a.length),a=B}if(a.length!==b)throw new Error("Field.fromBytes: expected "+b+" bytes, got "+a.length);let m=r?re(a):Q(a);if(i&&(m=M(m,e)),!l&&!y.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:a=>Mt(y,a),cmov:(a,l,m)=>m?l:a});return Object.freeze(y)}function je(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function fe(e){let t=je(e);return t+Math.ceil(t/2)}function Yt(e,t,r=!1){let n=e.length,o=je(t),s=fe(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?re(e):Q(e),c=M(i,t-D)+D;return r?oe(c,o):mt(c,o)}var wt=BigInt(0),ht=BigInt(1);function Ot(e,t){let r=t.negate();return e?r:t}function $t(e,t){let r=Mt(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ye(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ae(e,t){Ye(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=rt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Ke(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),f=e>>i;c>n&&(c-=s,f+=ht);let b=t*n,p=b+Math.abs(c)-1,y=c===0,a=c<0,l=t%2!==0;return{nextN:f,offset:p,isZero:y,isNeg:a,isNegF:l,offsetF:b}}function Rn(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function On(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ue=new WeakMap,ze=new WeakMap;function le(e){return ze.get(e)||1}function Me(e){if(e!==wt)throw new Error("invalid wNAF")}var zt=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>wt;)r&ht&&(n=n.add(o)),o=o.double(),r>>=ht;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=ae(r,this.bits),s=[],i=t,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let b=1;b<o;b++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=ae(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:b,isZero:p,isNeg:y,isNegF:a,offsetF:l}=Ke(n,c,i);n=f,p?s=s.add(Ot(a,r[l])):o=o.add(Ot(y,r[b]))}return Me(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=ae(t,this.bits);for(let i=0;i<s.windows&&n!==wt;i++){let{nextN:c,offset:f,isZero:b,isNeg:p}=Ke(n,i,s);if(n=c,!b){let y=r[f];o=o.add(p?y.negate():y)}}return Me(n),o}getPrecomputes(t,r,n){let o=ue.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ue.set(r,o))),o}cached(t,r,n){let o=le(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=le(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ye(r,this.bits),ze.set(t,r),ue.delete(t)}hasCache(t){return le(t)!==1}};function $e(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>wt||n>wt;)r&ht&&(s=s.add(o)),n&ht&&(i=i.add(o)),o=o.double(),r>>=ht,n>>=ht;return{p1:s,p2:i}}function Pe(e,t,r,n){Rn(r,e),On(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Kt(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let b=rt(f),p=new Array(Number(b)+1).fill(i),y=Math.floor((t.BITS-1)/f)*f,a=i;for(let l=y;l>=0;l-=f){p.fill(i);for(let B=0;B<s;B++){let N=n[B],L=Number(N>>BigInt(l)&b);p[L]=p[L].add(r[B])}let m=i;for(let B=p.length-1,N=i;B>0;B--)N=N.add(p[B]),m=m.add(N);if(a=a.add(m),l!==0)for(let B=0;B<f;B++)a=a.double()}return a}function Ge(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ce(t),t}else return ot(e,{isLE:r})}function We(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let b=t[f];if(!(typeof b=="bigint"&&b>wt))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Ge(t.p,r.Fp,n),s=Ge(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of c)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var Xe=(e,t)=>(e+(e>=0?t:-t)/Qe)/t;function kn(e,t,r){let[[n,o],[s,i]]=t,c=Xe(i*e,r),f=Xe(-o*e,r),b=e-c*n-f*s,p=-c*o-f*i,y=b<F,a=p<F;y&&(b=-b),a&&(p=-p);let l=rt(Math.ceil(Kt(r)/2))+Et;if(b<F||b>=l||p<F||p>=l)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:y,k1:b,k2neg:a,k2:p}}function he(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function de(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return _t(r.lowS,"lowS"),_t(r.prehash,"prehash"),r.format!==void 0&&he(r.format),r}var be=class extends Error{constructor(t=""){super(t)}},J={Err:be,_tlv:{encode:(e,t)=>{let{Err:r}=J;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Ht(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ht(o.length/2|128):"";return Ht(e)+s+o+t},decode(e,t){let{Err:r}=J,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let b=t.subarray(n,n+f);if(b.length!==f)throw new r("tlv.decode: length bytes not complete");if(b[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let p of b)i=i<<8|p;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=J;if(e<F)throw new t("integer: negative integers are not allowed");let r=Ht(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=J;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Q(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=J,o=U("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:f}=n.decode(2,s),{v:b,l:p}=n.decode(2,f);if(p.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(b)}},hexFromSig(e){let{_tlv:t,_int:r}=J,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},F=BigInt(0),Et=BigInt(1),Qe=BigInt(2),Pt=BigInt(3),Un=BigInt(4);function st(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=U("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Ln(e,t={}){let r=We("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Rt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:f}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=Fe(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(H,h,d){let{x:u,y:x}=h.toAffine(),g=n.toBytes(u);if(_t(d,"isCompressed"),d){p();let v=!n.isOdd(x);return K(Je(v),g)}else return K(Uint8Array.of(4),g,n.toBytes(x))}function a(H){nt(H,void 0,"Point");let{publicKey:h,publicKeyUncompressed:d}=b,u=H.length,x=H[0],g=H.subarray(1);if(u===h&&(x===2||x===3)){let v=n.fromBytes(g);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let E=B(v),w;try{w=n.sqrt(E)}catch(T){let R=T instanceof Error?": "+T.message:"";throw new Error("bad point: is not on curve, sqrt error"+R)}p();let S=n.isOdd(w);return(x&1)===1!==S&&(w=n.neg(w)),{x:v,y:w}}else if(u===d&&x===4){let v=n.BYTES,E=n.fromBytes(g.subarray(0,v)),w=n.fromBytes(g.subarray(v,v*2));if(!N(E,w))throw new Error("bad point: is not on curve");return{x:E,y:w}}else throw new Error(`bad point: got length ${u}, expected compressed=${h} or uncompressed=${d}`)}let l=t.toBytes||y,m=t.fromBytes||a;function B(H){let h=n.sqr(H),d=n.mul(h,H);return n.add(n.add(d,n.mul(H,s.a)),s.b)}function N(H,h){let d=n.sqr(h),u=B(H);return n.eql(d,u)}if(!N(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let L=n.mul(n.pow(s.a,Pt),Un),St=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(L,St)))throw new Error("bad curve params: a or b");function q(H,h,d=!1){if(!n.isValid(h)||d&&n.is0(h))throw new Error(`bad point coordinate ${H}`);return h}function it(H){if(!(H instanceof I))throw new Error("ProjectivePoint expected")}function tt(H){if(!f||!f.basises)throw new Error("no endo");return kn(H,f.basises,o.ORDER)}let bt=se((H,h)=>{let{X:d,Y:u,Z:x}=H;if(n.eql(x,n.ONE))return{x:d,y:u};let g=H.is0();h==null&&(h=g?n.ONE:n.inv(x));let v=n.mul(d,h),E=n.mul(u,h),w=n.mul(x,h);if(g)return{x:n.ZERO,y:n.ZERO};if(!n.eql(w,n.ONE))throw new Error("invZ was invalid");return{x:v,y:E}}),Ut=se(H=>{if(H.is0()){if(t.allowInfinityPoint&&!n.is0(H.Y))return;throw new Error("bad point: ZERO")}let{x:h,y:d}=H.toAffine();if(!n.isValid(h)||!n.isValid(d))throw new Error("bad point: x or y not field elements");if(!N(h,d))throw new Error("bad point: equation left != right");if(!H.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function pt(H,h,d,u,x){return d=new I(n.mul(d.X,H),d.Y,d.Z),h=Ot(u,h),d=Ot(x,d),h.add(d)}class I{constructor(h,d,u){this.X=q("x",h),this.Y=q("y",d,!0),this.Z=q("z",u),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:d,y:u}=h||{};if(!h||!n.isValid(d)||!n.isValid(u))throw new Error("invalid affine point");if(h instanceof I)throw new Error("projective point not allowed");return n.is0(d)&&n.is0(u)?I.ZERO:new I(d,u,n.ONE)}static fromBytes(h){let d=I.fromAffine(m(nt(h,void 0,"point")));return d.assertValidity(),d}static fromHex(h){return I.fromBytes(U("pointHex",h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,d=!0){return ct.createCache(this,h),d||this.multiply(Pt),this}assertValidity(){Ut(this)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){it(h);let{X:d,Y:u,Z:x}=this,{X:g,Y:v,Z:E}=h,w=n.eql(n.mul(d,E),n.mul(g,x)),S=n.eql(n.mul(u,E),n.mul(v,x));return w&&S}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:d}=s,u=n.mul(d,Pt),{X:x,Y:g,Z:v}=this,E=n.ZERO,w=n.ZERO,S=n.ZERO,A=n.mul(x,x),T=n.mul(g,g),R=n.mul(v,v),_=n.mul(x,g);return _=n.add(_,_),S=n.mul(x,v),S=n.add(S,S),E=n.mul(h,S),w=n.mul(u,R),w=n.add(E,w),E=n.sub(T,w),w=n.add(T,w),w=n.mul(E,w),E=n.mul(_,E),S=n.mul(u,S),R=n.mul(h,R),_=n.sub(A,R),_=n.mul(h,_),_=n.add(_,S),S=n.add(A,A),A=n.add(S,A),A=n.add(A,R),A=n.mul(A,_),w=n.add(w,A),R=n.mul(g,v),R=n.add(R,R),A=n.mul(R,_),E=n.sub(E,A),S=n.mul(R,T),S=n.add(S,S),S=n.add(S,S),new I(E,w,S)}add(h){it(h);let{X:d,Y:u,Z:x}=this,{X:g,Y:v,Z:E}=h,w=n.ZERO,S=n.ZERO,A=n.ZERO,T=s.a,R=n.mul(s.b,Pt),_=n.mul(d,g),O=n.mul(u,v),V=n.mul(x,E),j=n.add(d,u),k=n.add(g,v);j=n.mul(j,k),k=n.add(_,O),j=n.sub(j,k),k=n.add(d,x);let C=n.add(g,E);return k=n.mul(k,C),C=n.add(_,V),k=n.sub(k,C),C=n.add(u,x),w=n.add(v,E),C=n.mul(C,w),w=n.add(O,V),C=n.sub(C,w),A=n.mul(T,k),w=n.mul(R,V),A=n.add(w,A),w=n.sub(O,A),A=n.add(O,A),S=n.mul(w,A),O=n.add(_,_),O=n.add(O,_),V=n.mul(T,V),k=n.mul(R,k),O=n.add(O,V),V=n.sub(_,V),V=n.mul(T,V),k=n.add(k,V),_=n.mul(O,k),S=n.add(S,_),_=n.mul(C,k),w=n.mul(j,w),w=n.sub(w,_),_=n.mul(j,O),A=n.mul(C,A),A=n.add(A,_),new I(w,S,A)}subtract(h){return this.add(h.negate())}is0(){return this.equals(I.ZERO)}multiply(h){let{endo:d}=t;if(!o.isValidNot0(h))throw new Error("invalid scalar: out of range");let u,x,g=v=>ct.cached(this,v,E=>$t(I,E));if(d){let{k1neg:v,k1:E,k2neg:w,k2:S}=tt(h),{p:A,f:T}=g(E),{p:R,f:_}=g(S);x=T.add(_),u=pt(d.beta,A,R,v,w)}else{let{p:v,f:E}=g(h);u=v,x=E}return $t(I,[u,x])[0]}multiplyUnsafe(h){let{endo:d}=t,u=this;if(!o.isValid(h))throw new Error("invalid scalar: out of range");if(h===F||u.is0())return I.ZERO;if(h===Et)return u;if(ct.hasCache(this))return this.multiply(h);if(d){let{k1neg:x,k1:g,k2neg:v,k2:E}=tt(h),{p1:w,p2:S}=$e(I,u,g,E);return pt(d.beta,w,S,x,v)}else return ct.unsafe(u,h)}multiplyAndAddUnsafe(h,d,u){let x=this.multiplyUnsafe(d).add(h.multiplyUnsafe(u));return x.is0()?void 0:x}toAffine(h){return bt(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return i===Et?!0:h?h(I,this):ct.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===Et?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(h=!0){return _t(h,"isCompressed"),this.assertValidity(),l(I,this,h)}toHex(h=!0){return P(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(h=!0){return this.toBytes(h)}_setWindowSize(h){this.precompute(h)}static normalizeZ(h){return $t(I,h)}static msm(h,d){return Pe(I,o,h,d)}static fromPrivateKey(h){return I.BASE.multiply(st(o,h))}}I.BASE=new I(s.Gx,s.Gy,n.ONE),I.ZERO=new I(n.ZERO,n.ONE,n.ZERO),I.Fp=n,I.Fn=o;let Lt=o.BITS,ct=new zt(I,t.endo?Math.ceil(Lt/2):Lt);return I.BASE.precompute(8),I}function Je(e){return Uint8Array.of(e?2:3)}function Fe(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function qn(e,t={}){let{Fn:r}=e,n=t.randomBytes||lt,o=Object.assign(Fe(e.Fp,r),{seed:fe(r.ORDER)});function s(l){try{return!!st(r,l)}catch{return!1}}function i(l,m){let{publicKey:B,publicKeyUncompressed:N}=o;try{let L=l.length;return m===!0&&L!==B||m===!1&&L!==N?!1:!!e.fromBytes(l)}catch{return!1}}function c(l=n(o.seed)){return Yt(nt(l,o.seed,"seed"),r.ORDER)}function f(l,m=!0){return e.BASE.multiply(st(r,l)).toBytes(m)}function b(l){let m=c(l);return{secretKey:m,publicKey:f(m)}}function p(l){if(typeof l=="bigint")return!1;if(l instanceof e)return!0;let{secretKey:m,publicKey:B,publicKeyUncompressed:N}=o;if(r.allowedLengths||m===B)return;let L=U("key",l).length;return L===B||L===N}function y(l,m,B=!0){if(p(l)===!0)throw new Error("first arg must be private key");if(p(m)===!1)throw new Error("second arg must be public key");let N=st(r,l);return e.fromHex(m).multiply(N).toBytes(B)}return Object.freeze({getPublicKey:f,getSharedSecret:y,keygen:b,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:l=>st(r,l),precompute(l=8,m=e.BASE){return m.precompute(l,!1)}},lengths:o})}function Tn(e,t,r={}){Tt(t),Rt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||lt,o=r.hmac||((d,...u)=>Ft(t,d,K(...u))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:f}=i,{keygen:b,getPublicKey:p,getSharedSecret:y,utils:a,lengths:l}=qn(e,r),m={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},B="compact";function N(d){let u=c>>Et;return d>u}function L(d,u){if(!i.isValidNot0(u))throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);return u}function St(d,u){he(u);let x=l.signature,g=u==="compact"?x:u==="recovered"?x+1:void 0;return nt(d,g,`${u} signature`)}class q{constructor(u,x,g){this.r=L("r",u),this.s=L("s",x),g!=null&&(this.recovery=g),Object.freeze(this)}static fromBytes(u,x=B){St(u,x);let g;if(x==="der"){let{r:S,s:A}=J.toSig(nt(u));return new q(S,A)}x==="recovered"&&(g=u[0],x="compact",u=u.subarray(1));let v=i.BYTES,E=u.subarray(0,v),w=u.subarray(v,v*2);return new q(i.fromBytes(E),i.fromBytes(w),g)}static fromHex(u,x){return this.fromBytes(Y(u),x)}addRecoveryBit(u){return new q(this.r,this.s,u)}recoverPublicKey(u){let x=s.ORDER,{r:g,s:v,recovery:E}=this;if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");if(c*Qe<x&&E>1)throw new Error("recovery id is ambiguous for h>1 curve");let S=E===2||E===3?g+c:g;if(!s.isValid(S))throw new Error("recovery id 2 or 3 invalid");let A=s.toBytes(S),T=e.fromBytes(K(Je((E&1)===0),A)),R=i.inv(S),_=tt(U("msgHash",u)),O=i.create(-_*R),V=i.create(v*R),j=e.BASE.multiplyUnsafe(O).add(T.multiplyUnsafe(V));if(j.is0())throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return N(this.s)}toBytes(u=B){if(he(u),u==="der")return Y(J.hexFromSig(this));let x=i.toBytes(this.r),g=i.toBytes(this.s);if(u==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return K(Uint8Array.of(this.recovery),x,g)}return K(x,g)}toHex(u){return P(this.toBytes(u))}assertValidity(){}static fromCompact(u){return q.fromBytes(U("sig",u),"compact")}static fromDER(u){return q.fromBytes(U("sig",u),"der")}normalizeS(){return this.hasHighS()?new q(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return P(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return P(this.toBytes("compact"))}}let it=r.bits2int||function(u){if(u.length>8192)throw new Error("input is too large");let x=Q(u),g=u.length*8-f;return g>0?x>>BigInt(g):x},tt=r.bits2int_modN||function(u){return i.create(it(u))},bt=rt(f);function Ut(d){return Re("num < 2^"+f,d,F,bt),i.toBytes(d)}function pt(d,u){return nt(d,void 0,"message"),u?nt(t(d),void 0,"prehashed message"):d}function I(d,u,x){if(["recovered","canonical"].some(O=>O in x))throw new Error("sign() legacy options not supported");let{lowS:g,prehash:v,extraEntropy:E}=de(x,m);d=pt(d,v);let w=tt(d),S=st(i,u),A=[Ut(S),Ut(w)];if(E!=null&&E!==!1){let O=E===!0?n(l.secretKey):E;A.push(U("extraEntropy",O))}let T=K(...A),R=w;function _(O){let V=it(O);if(!i.isValidNot0(V))return;let j=i.inv(V),k=e.BASE.multiply(V).toAffine(),C=i.create(k.x);if(C===F)return;let qt=i.create(j*i.create(R+C*S));if(qt===F)return;let me=(k.x===C?0:2)|Number(k.y&Et),we=qt;return g&&N(qt)&&(we=i.neg(qt),me^=1),new q(C,we,me)}return{seed:T,k2sig:_}}function Lt(d,u,x={}){d=U("message",d);let{seed:g,k2sig:v}=I(d,u,x);return Oe(t.outputLen,i.BYTES,o)(g,v)}function ct(d){let u,x=typeof d=="string"||at(d),g=!x&&d!==null&&typeof d=="object"&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!x&&!g)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(g)u=new q(d.r,d.s);else if(x){try{u=q.fromBytes(U("sig",d),"der")}catch(v){if(!(v instanceof J.Err))throw v}if(!u)try{u=q.fromBytes(U("sig",d),"compact")}catch{return!1}}return u||!1}function H(d,u,x,g={}){let{lowS:v,prehash:E,format:w}=de(g,m);if(x=U("publicKey",x),u=pt(U("message",u),E),"strict"in g)throw new Error("options.strict was renamed to lowS");let S=w===void 0?ct(d):q.fromBytes(U("sig",d),w);if(S===!1)return!1;try{let A=e.fromBytes(x);if(v&&S.hasHighS())return!1;let{r:T,s:R}=S,_=tt(u),O=i.inv(R),V=i.create(_*O),j=i.create(T*O),k=e.BASE.multiplyUnsafe(V).add(A.multiplyUnsafe(j));return k.is0()?!1:i.create(k.x)===T}catch{return!1}}function h(d,u,x={}){let{prehash:g}=de(x,m);return u=pt(u,g),q.fromBytes(d,"recovered").recoverPublicKey(u).toBytes()}return Object.freeze({keygen:b,getPublicKey:p,getSharedSecret:y,utils:a,lengths:l,Point:e,sign:Lt,verify:H,recoverPublicKey:h,Signature:q,hash:t})}function Vn(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=ot(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Cn(e){let{CURVE:t,curveOpts:r}=Vn(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Dn(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Gt(r.Fn.ORDER,r.Fn.BITS))})}function tn(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Cn(e),s=Ln(t,r),i=Tn(s,n,o);return Dn(e,i)}function en(e,t){let r=n=>tn({...e,hash:n});return{...r(t),create:r}}var Bt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zn={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},jn=BigInt(0),nn=BigInt(1),pe=BigInt(2);function Kn(e){let t=Bt.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),b=e*e*e%t,p=b*b*e%t,y=G(p,r,t)*p%t,a=G(y,r,t)*p%t,l=G(a,pe,t)*b%t,m=G(l,o,t)*l%t,B=G(m,s,t)*m%t,N=G(B,c,t)*B%t,L=G(N,f,t)*N%t,St=G(L,c,t)*B%t,q=G(St,r,t)*p%t,it=G(q,i,t)*m%t,tt=G(it,n,t)*b%t,bt=G(tt,pe,t);if(!Wt.eql(Wt.sqr(bt),e))throw new Error("Cannot find square root");return bt}var Wt=ot(Bt.p,{sqrt:Kn}),sn=en({...Bt,Fp:Wt,lowS:!0,endo:Zn},gt),rn={};function Xt(e,...t){let r=rn[e];if(r===void 0){let n=gt(Ct(e));r=K(n,n),rn[e]=r}return gt(K(r,...t))}var ye=e=>e.toBytes(!0).slice(1),vt=sn.Point,ge=e=>e%pe===jn;function xe(e){let{Fn:t,BASE:r}=vt,n=st(t,e),o=r.multiply(n);return{scalar:ge(o.y)?n:t.neg(n),bytes:ye(o)}}function cn(e){let t=Wt;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x \u2265 p");let r=t.create(e*e),n=t.create(r*e+BigInt(7)),o=t.sqrt(n);ge(o)||(o=t.neg(o));let s=vt.fromAffine({x:e,y:o});return s.assertValidity(),s}var kt=Q;function fn(...e){return vt.Fn.create(kt(Xt("BIP0340/challenge",...e)))}function on(e){return xe(e).bytes}function Mn(e,t,r=lt(32)){let{Fn:n}=vt,o=U("message",e),{bytes:s,scalar:i}=xe(t),c=U("auxRand",r,32),f=n.toBytes(i^kt(Xt("BIP0340/aux",c))),b=Xt("BIP0340/nonce",f,s,o),{bytes:p,scalar:y}=xe(b),a=fn(p,s,o),l=new Uint8Array(64);if(l.set(p,0),l.set(n.toBytes(n.create(y+a*i)),32),!an(l,o,s))throw new Error("sign: Invalid signature produced");return l}function an(e,t,r){let{Fn:n,BASE:o}=vt,s=U("signature",e,64),i=U("message",t),c=U("publicKey",r,32);try{let f=cn(kt(c)),b=kt(s.subarray(0,32));if(!Nt(b,nn,Bt.p))return!1;let p=kt(s.subarray(32,64));if(!Nt(p,nn,Bt.n))return!1;let y=fn(n.toBytes(b),ye(f),i),a=o.multiplyUnsafe(p).add(f.multiplyUnsafe(n.neg(y))),{x:l,y:m}=a.toAffine();return!(a.is0()||!ge(m)||l!==b)}catch{return!1}}var un=(()=>{let r=(o=lt(48))=>Yt(o,Bt.n);sn.utils.randomSecretKey;function n(o){let s=r(o);return{secretKey:s,publicKey:on(s)}}return{keygen:n,getPublicKey:on,sign:Mn,verify:an,Point:vt,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:Xt,lift_x:cn,pointToBytes:ye,numberToBytesBE:mt,bytesToNumberBE:Q,mod:M},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var ln=gt;function dn(e){let t=[];if(Jt(e)||t.push("Invalid event structure"),(typeof e.kind!="number"||e.kind<0)&&t.push("Event kind must be a non-negative integer"),(!e.content||typeof e.content!="string")&&t.push("Event content must be a non-empty string"),e.created_at!==void 0){let r=Math.floor(Date.now()/1e3);e.created_at>r+60&&t.push("Event timestamp is too far in the future"),e.created_at<0&&t.push("Invalid timestamp: must be non-negative")}return Array.isArray(e.tags)?e.tags.every(r=>Array.isArray(r)&&r.every(n=>typeof n=="string"))||t.push("Each tag must be an array of strings"):t.push("Event tags must be an array"),{isValid:t.length===0,error:t.length>0?t[0]:void 0}}function Gn(e){if(e.startsWith("npub1"))throw new Error("npub inputs require bech32 decoding \u2014 use nip19.decode() instead");return e}function Yn(e){let t=[];Ee(e)||t.push("Invalid signed event structure");let r=dn(e);if(r.isValid||t.push(r.error||""),/^[0-9a-f]{64}$/i.test(e.pubkey)||t.push("Invalid public key format"),/^[0-9a-f]{64}$/i.test(e.id)||t.push("Invalid event ID format"),/^[0-9a-f]{128,130}$/i.test(e.sig)||t.push("Invalid signature format"),t.length===0){let n=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),o=P(ln(new TextEncoder().encode(n)));e.id!==o&&t.push("Invalid event ID");try{un.verify(Y(e.sig),Y(e.id),Y(e.pubkey))||t.push("Invalid signature")}catch(s){t.push(`Signature verification failed: ${s instanceof Error?s.message:"unknown error"}`)}}return{isValid:t.length===0,error:t.length>0?t[0]:void 0}}function zn(e){try{if(!/^[0-9a-f]{64}$/i.test(e))return{isValid:!1,error:"Public key must be a 32-byte hex string"};try{Y(e)}catch{return{isValid:!1,error:"Invalid hex encoding"}}return{isValid:!0,error:void 0}}catch(t){return{isValid:!1,error:t instanceof Error?t.message:"Unknown error validating public key"}}}function hn(e){return Be(e)?{isValid:!0,error:void 0}:{isValid:!1,error:"Filter kinds must be non-negative integers"}}function $n(e){if(!e.id)return{isValid:!1,error:"Subscription must have an id"};if(!e.filters||!Array.isArray(e.filters)||e.filters.length===0)return{isValid:!1,error:"Subscription must have at least one filter"};for(let t of e.filters){let r=hn(t);if(!r.isValid)return r}return{isValid:!0,error:void 0}}return mn(Pn);})();
2
+ /*! Bundled license information:
3
+
4
+ @noble/hashes/esm/utils.js:
5
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6
+
7
+ @noble/curves/esm/utils.js:
8
+ @noble/curves/esm/abstract/modular.js:
9
+ @noble/curves/esm/abstract/curve.js:
10
+ @noble/curves/esm/abstract/weierstrass.js:
11
+ @noble/curves/esm/_shortw_utils.js:
12
+ @noble/curves/esm/secp256k1.js:
13
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
14
+ */
15
+ //# sourceMappingURL=validation.nostr-crypto-utils.min.js.map