nostr-crypto-utils 0.5.0 → 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 (141) hide show
  1. package/README.md +84 -75
  2. package/dist/browser/crypto.nostr-crypto-utils.min.js +15 -1
  3. package/dist/browser/crypto.nostr-crypto-utils.min.js.map +7 -0
  4. package/dist/browser/main.nostr-crypto-utils.min.js +32 -0
  5. package/dist/browser/main.nostr-crypto-utils.min.js.map +7 -0
  6. package/dist/browser/nip-44.nostr-crypto-utils.min.js +21 -0
  7. package/dist/browser/nip-44.nostr-crypto-utils.min.js.map +7 -0
  8. package/dist/browser/nip-46.nostr-crypto-utils.min.js +21 -0
  9. package/dist/browser/nip-46.nostr-crypto-utils.min.js.map +7 -0
  10. package/dist/browser/nip-49.nostr-crypto-utils.min.js +13 -0
  11. package/dist/browser/nip-49.nostr-crypto-utils.min.js.map +7 -0
  12. package/dist/browser/protocol.nostr-crypto-utils.min.js +2 -1
  13. package/dist/browser/protocol.nostr-crypto-utils.min.js.map +7 -0
  14. package/dist/browser/validation.nostr-crypto-utils.min.js +15 -1
  15. package/dist/browser/validation.nostr-crypto-utils.min.js.map +7 -0
  16. package/dist/cjs/crypto.js +65 -41
  17. package/dist/cjs/crypto.js.map +1 -1
  18. package/dist/cjs/index.js +5 -3
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/cjs/nips/index.js +5 -2
  21. package/dist/cjs/nips/index.js.map +1 -1
  22. package/dist/cjs/nips/nip-04.js +35 -21
  23. package/dist/cjs/nips/nip-04.js.map +1 -1
  24. package/dist/cjs/nips/nip-26.js +14 -13
  25. package/dist/cjs/nips/nip-26.js.map +1 -1
  26. package/dist/cjs/nips/nip-44.js +11 -11
  27. package/dist/cjs/nips/nip-44.js.map +1 -1
  28. package/dist/cjs/nips/nip-46.js +334 -0
  29. package/dist/cjs/nips/nip-46.js.map +1 -0
  30. package/dist/cjs/nips/nip-49.js +3 -3
  31. package/dist/cjs/nips/nip-49.js.map +1 -1
  32. package/dist/cjs/types/index.js +3 -0
  33. package/dist/cjs/types/index.js.map +1 -1
  34. package/dist/cjs/types/nip46.js +24 -0
  35. package/dist/cjs/types/nip46.js.map +1 -0
  36. package/dist/cjs/utils/validation.js +5 -2
  37. package/dist/cjs/utils/validation.js.map +1 -1
  38. package/dist/esm/crypto.js +64 -37
  39. package/dist/esm/crypto.js.map +1 -1
  40. package/dist/esm/index.js +4 -3
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/nips/index.js +5 -2
  43. package/dist/esm/nips/index.js.map +1 -1
  44. package/dist/esm/nips/nip-04.js +35 -18
  45. package/dist/esm/nips/nip-04.js.map +1 -1
  46. package/dist/esm/nips/nip-26.js +13 -12
  47. package/dist/esm/nips/nip-26.js.map +1 -1
  48. package/dist/esm/nips/nip-44.js +2 -2
  49. package/dist/esm/nips/nip-44.js.map +1 -1
  50. package/dist/esm/nips/nip-46.js +309 -0
  51. package/dist/esm/nips/nip-46.js.map +1 -0
  52. package/dist/esm/nips/nip-49.js +1 -1
  53. package/dist/esm/nips/nip-49.js.map +1 -1
  54. package/dist/esm/types/index.js +3 -0
  55. package/dist/esm/types/index.js.map +1 -1
  56. package/dist/esm/types/nip46.js +21 -0
  57. package/dist/esm/types/nip46.js.map +1 -0
  58. package/dist/esm/utils/validation.js +5 -2
  59. package/dist/esm/utils/validation.js.map +1 -1
  60. package/dist/types/crypto.d.ts +13 -13
  61. package/dist/types/crypto.d.ts.map +1 -1
  62. package/dist/types/index.d.ts +4 -2
  63. package/dist/types/index.d.ts.map +1 -1
  64. package/dist/types/nips/index.d.ts +5 -0
  65. package/dist/types/nips/index.d.ts.map +1 -1
  66. package/dist/types/nips/nip-04.d.ts.map +1 -1
  67. package/dist/types/nips/nip-26.d.ts +3 -3
  68. package/dist/types/nips/nip-26.d.ts.map +1 -1
  69. package/dist/types/nips/nip-44.d.ts.map +1 -1
  70. package/dist/types/nips/nip-46.d.ts +146 -0
  71. package/dist/types/nips/nip-46.d.ts.map +1 -0
  72. package/dist/types/types/index.d.ts +3 -0
  73. package/dist/types/types/index.d.ts.map +1 -1
  74. package/dist/types/types/nip46.d.ts +75 -0
  75. package/dist/types/types/nip46.d.ts.map +1 -0
  76. package/dist/types/utils/validation.d.ts.map +1 -1
  77. package/examples/basic-usage.ts +33 -0
  78. package/examples/nip-04.ts +35 -0
  79. package/examples/nip-19.ts +46 -0
  80. package/package.json +40 -26
  81. package/src/__tests__/nips/nip-44.test.ts +67 -87
  82. package/src/__tests__/nips/nip-46.test.ts +340 -0
  83. package/src/__tests__/nips/nip-49.test.ts +43 -63
  84. package/src/crypto.ts +77 -45
  85. package/src/index.ts +12 -3
  86. package/src/nips/index.ts +6 -3
  87. package/src/nips/nip-04.ts +40 -18
  88. package/src/nips/nip-26.ts +15 -13
  89. package/src/nips/nip-44.ts +7 -3
  90. package/src/nips/nip-46.ts +372 -0
  91. package/src/nips/nip-49.ts +1 -1
  92. package/src/types/index.ts +4 -0
  93. package/src/types/nip46.ts +81 -0
  94. package/src/utils/validation.ts +5 -2
  95. package/dist/browser/128.nostr-crypto-utils.min.js +0 -1
  96. package/dist/browser/156.nostr-crypto-utils.min.js +0 -1
  97. package/dist/browser/158.nostr-crypto-utils.min.js +0 -1
  98. package/dist/browser/26.nostr-crypto-utils.min.js +0 -1
  99. package/dist/browser/287.nostr-crypto-utils.min.js +0 -2
  100. package/dist/browser/287.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  101. package/dist/browser/310.nostr-crypto-utils.min.js +0 -1
  102. package/dist/browser/324.nostr-crypto-utils.min.js +0 -2
  103. package/dist/browser/324.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  104. package/dist/browser/330.nostr-crypto-utils.min.js +0 -2
  105. package/dist/browser/330.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  106. package/dist/browser/344.nostr-crypto-utils.min.js +0 -1
  107. package/dist/browser/389.nostr-crypto-utils.min.js +0 -2
  108. package/dist/browser/389.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  109. package/dist/browser/404.nostr-crypto-utils.min.js +0 -1
  110. package/dist/browser/419.nostr-crypto-utils.min.js +0 -1
  111. package/dist/browser/430.nostr-crypto-utils.min.js +0 -2
  112. package/dist/browser/430.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  113. package/dist/browser/473.nostr-crypto-utils.min.js +0 -1
  114. package/dist/browser/490.nostr-crypto-utils.min.js +0 -1
  115. package/dist/browser/503.nostr-crypto-utils.min.js +0 -1
  116. package/dist/browser/509.nostr-crypto-utils.min.js +0 -1
  117. package/dist/browser/510.nostr-crypto-utils.min.js +0 -2
  118. package/dist/browser/510.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  119. package/dist/browser/529.nostr-crypto-utils.min.js +0 -2
  120. package/dist/browser/529.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  121. package/dist/browser/54.nostr-crypto-utils.min.js +0 -1
  122. package/dist/browser/613.nostr-crypto-utils.min.js +0 -1
  123. package/dist/browser/636.nostr-crypto-utils.min.js +0 -1
  124. package/dist/browser/657.nostr-crypto-utils.min.js +0 -2
  125. package/dist/browser/657.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  126. package/dist/browser/668.nostr-crypto-utils.min.js +0 -2
  127. package/dist/browser/668.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  128. package/dist/browser/705.nostr-crypto-utils.min.js +0 -2
  129. package/dist/browser/705.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  130. package/dist/browser/761.nostr-crypto-utils.min.js +0 -2
  131. package/dist/browser/761.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  132. package/dist/browser/801.nostr-crypto-utils.min.js +0 -1
  133. package/dist/browser/802.nostr-crypto-utils.min.js +0 -2
  134. package/dist/browser/802.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  135. package/dist/browser/829.nostr-crypto-utils.min.js +0 -1
  136. package/dist/browser/851.nostr-crypto-utils.min.js +0 -1
  137. package/dist/browser/890.nostr-crypto-utils.min.js +0 -1
  138. package/dist/browser/985.nostr-crypto-utils.min.js +0 -1
  139. package/dist/browser/995.nostr-crypto-utils.min.js +0 -1
  140. package/dist/browser/main-43dd7041.nostr-crypto-utils.min.js +0 -1
  141. package/dist/browser/main-96d4916e.nostr-crypto-utils.min.js +0 -1
package/README.md CHANGED
@@ -10,6 +10,9 @@ This library provides essential cryptographic operations and utilities required
10
10
  - Key management and validation
11
11
  - Event signing and verification
12
12
  - Encrypted direct messages (NIP-04)
13
+ - Versioned encrypted payloads (NIP-44)
14
+ - Remote signing / Nostr Connect (NIP-46)
15
+ - Private key encryption / ncryptsec (NIP-49)
13
16
  - Bech32-encoded entities (NIP-19)
14
17
  - Delegated event signing (NIP-26)
15
18
  - Authentication protocol (NIP-42)
@@ -37,6 +40,9 @@ This library provides essential cryptographic operations and utilities required
37
40
  - NIP-19: Bech32-Encoded Entities
38
41
  - NIP-26: Delegated Event Signing
39
42
  - NIP-42: Authentication Protocol
43
+ - NIP-44: Versioned Encrypted Payloads
44
+ - NIP-46: Nostr Connect (Remote Signing)
45
+ - NIP-49: Private Key Encryption (ncryptsec)
40
46
 
41
47
  ## Project Structure
42
48
 
@@ -63,7 +69,7 @@ This library provides essential cryptographic operations and utilities required
63
69
  - Supports both ESM and CJS formats
64
70
  - Cross-platform compatible (Node.js and browser environments)
65
71
 
66
- [![npm version](https://badge.fury.io/js/%40humanjavaenterprises%2Fnostr-crypto-utils.svg)](https://www.npmjs.com/package/@humanjavaenterprises/nostr-crypto-utils)
72
+ [![npm version](https://badge.fury.io/js/nostr-crypto-utils.svg)](https://www.npmjs.com/package/nostr-crypto-utils)
67
73
  [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
68
74
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/HumanjavaEnterprises/nostr-crypto-utils/blob/main/LICENSE)
69
75
  [![Documentation](https://img.shields.io/badge/docs-TypeDoc-blue.svg)](https://humanjavaenterprises.github.io/nostr-crypto-utils/)
@@ -77,6 +83,12 @@ This library provides essential cryptographic operations and utilities required
77
83
 
78
84
  If you discover a security vulnerability, please follow our [Security Policy](SECURITY.md) and report it through [GitHub's Security Advisory feature](https://github.com/humanjavaenterprises/nostr-crypto-utils/security/advisories/new).
79
85
 
86
+ ### Dependency Vulnerability Status
87
+
88
+ We actively monitor and address security vulnerabilities in this codebase. **`npm audit --omit=dev` reports zero vulnerabilities** for this package — there are no known security issues in production dependencies.
89
+
90
+ Any remaining `npm audit` findings are in development-only tooling (eslint, typescript-eslint, vitest, etc.) and stem from transitive dependencies with no upstream fix available. These are devDependencies that are never included in the published package and pose no risk to consumers of this library. We monitor upstream fixes and update promptly when they become available.
91
+
80
92
  ## Why Choose nostr-crypto-utils?
81
93
 
82
94
  - **Lightweight**: Only 208.7KB unpacked, focusing on essential cryptographic operations
@@ -108,6 +120,9 @@ This library implements the following Nostr Implementation Possibilities (NIPs):
108
120
  | [NIP-19](https://github.com/nostr-protocol/nips/blob/master/19.md) | bech32-encoded Entities | Human-readable encoding for keys, events, and other entities | ✅ Complete |
109
121
  | [NIP-26](https://github.com/nostr-protocol/nips/blob/master/26.md) | Delegated Event Signing | Create and verify delegated event signing capabilities | ✅ Complete |
110
122
  | [NIP-42](https://github.com/nostr-protocol/nips/blob/master/42.md) | Authentication | Client-relay authentication protocol | ✅ Complete |
123
+ | [NIP-44](https://github.com/nostr-protocol/nips/blob/master/44.md) | Versioned Encrypted Payloads | Modern encryption replacing NIP-04 (ChaCha20 + HMAC) | ✅ Complete |
124
+ | [NIP-46](https://github.com/nostr-protocol/nips/blob/master/46.md) | Nostr Connect (Remote Signing) | Protocol layer for remote signing via bunker | ✅ Complete |
125
+ | [NIP-49](https://github.com/nostr-protocol/nips/blob/master/49.md) | Private Key Encryption | ncryptsec password-encrypted key storage | ✅ Complete |
111
126
 
112
127
  ### NIP-01 Features
113
128
  - Event creation and serialization
@@ -148,7 +163,7 @@ import {
148
163
  naddrEncode,
149
164
  nrelayEncode,
150
165
  decode
151
- } from '@humanjavaenterprises/nostr-crypto-utils';
166
+ } from 'nostr-crypto-utils';
152
167
 
153
168
  // Encode a public key
154
169
  const npub = npubEncode('7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0');
@@ -202,6 +217,62 @@ try {
202
217
  } catch (error) {
203
218
  console.error(error); // Error: Invalid hex string
204
219
  }
220
+ ```
221
+
222
+ ### NIP-44 Usage (Encrypted Payloads)
223
+
224
+ ```typescript
225
+ import { nip44 } from 'nostr-crypto-utils';
226
+ // Or via subpath: import * as nip44 from 'nostr-crypto-utils/nip44';
227
+
228
+ // Derive a conversation key from ECDH
229
+ const conversationKey = nip44.getConversationKey(myPrivKeyBytes, theirPubkeyHex);
230
+
231
+ // Encrypt
232
+ const encrypted = nip44.encrypt('Hello!', conversationKey);
233
+
234
+ // Decrypt
235
+ const plaintext = nip44.decrypt(encrypted, conversationKey);
236
+ ```
237
+
238
+ ### NIP-46 Usage (Remote Signing)
239
+
240
+ ```typescript
241
+ import { nip46 } from 'nostr-crypto-utils';
242
+ // Or via subpath: import * as nip46 from 'nostr-crypto-utils/nip46';
243
+
244
+ // Parse a bunker:// URI
245
+ const bunker = nip46.parseBunkerURI('bunker://pubkey...?relay=wss://relay.example.com&secret=abc');
246
+
247
+ // Create a session (ephemeral keypair + NIP-44 conversation key)
248
+ const session = nip46.createSession(bunker.remotePubkey);
249
+
250
+ // Build a request
251
+ const req = nip46.connectRequest(bunker.remotePubkey, bunker.secret);
252
+
253
+ // Wrap into a kind 24133 encrypted event (ready to publish to relay)
254
+ const event = await nip46.wrapEvent(req, session, bunker.remotePubkey);
255
+
256
+ // On receiving a response event, unwrap it
257
+ const response = nip46.unwrapEvent(responseEvent, session);
258
+
259
+ // Create a filter for subscribing to responses
260
+ const filter = nip46.createResponseFilter(session.clientPubkey);
261
+ ```
262
+
263
+ ### NIP-49 Usage (ncryptsec Key Encryption)
264
+
265
+ ```typescript
266
+ import { nip49 } from 'nostr-crypto-utils';
267
+ // Or via subpath: import * as nip49 from 'nostr-crypto-utils/nip49';
268
+
269
+ // Encrypt a private key with a password
270
+ const ncryptsec = nip49.encrypt(secretKeyBytes, 'my-password');
271
+ // Returns: 'ncryptsec1...'
272
+
273
+ // Decrypt it back
274
+ const secretKey = nip49.decrypt(ncryptsec, 'my-password');
275
+ ```
205
276
 
206
277
  ### Type System
207
278
 
@@ -448,11 +519,11 @@ These examples demonstrate real-world usage patterns from production Nostr appli
448
519
 
449
520
  ## Integration with nostr-nsec-seedphrase
450
521
 
451
- This library is designed to work seamlessly with [@humanjavaenterprises/nostr-nsec-seedphrase](https://github.com/HumanjavaEnterprises/nostr-nsec-seedphrase) to provide a complete solution for Nostr key management and cryptographic operations:
522
+ This library is designed to work seamlessly with [nostr-nsec-seedphrase](https://github.com/HumanjavaEnterprises/nostr-nsec-seedphrase) to provide a complete solution for Nostr key management and cryptographic operations:
452
523
 
453
524
  ```typescript
454
- import { generateSeedPhrase } from '@humanjavaenterprises/nostr-nsec-seedphrase';
455
- import { createTextNoteEvent, signEvent } from '@humanjavaenterprises/nostr-crypto-utils';
525
+ import { generateSeedPhrase } from 'nostr-nsec-seedphrase';
526
+ import { createTextNoteEvent, signEvent } from 'nostr-crypto-utils';
456
527
 
457
528
  // Generate keys using nostr-nsec-seedphrase
458
529
  const seedPhrase = generateSeedPhrase();
@@ -481,7 +552,7 @@ You can use this library to create delegate tokens for use on web servers or oth
481
552
  ### Basic Delegation Example
482
553
 
483
554
  ```typescript
484
- import { createDelegation, validateDelegation } from '@humanjavaenterprises/nostr-crypto-utils';
555
+ import { createDelegation, validateDelegation } from 'nostr-crypto-utils';
485
556
 
486
557
  // Create a delegation token (delegator's perspective)
487
558
  const delegatorKeyPair = await generateKeyPair();
@@ -510,7 +581,7 @@ const isValid = await validateDelegation({
510
581
  Here's how to use delegation tokens in a web server context:
511
582
 
512
583
  ```typescript
513
- import { createEvent, signEventWithDelegation } from '@humanjavaenterprises/nostr-crypto-utils';
584
+ import { createEvent, signEventWithDelegation } from 'nostr-crypto-utils';
514
585
 
515
586
  // On your server, store these securely
516
587
  const DELEGATE_PRIVKEY = 'nsec1...'; // Your server's private key
@@ -589,7 +660,7 @@ For more details on delegation, see the [NIP-26 specification](https://github.co
589
660
  Enable debug mode to get detailed logging:
590
661
 
591
662
  ```typescript
592
- import { setDebugLevel } from '@humanjavaenterprises/nostr-crypto-utils';
663
+ import { setDebugLevel } from 'nostr-crypto-utils';
593
664
 
594
665
  // Enable debug logging
595
666
  setDebugLevel('debug');
@@ -671,53 +742,6 @@ const testEventSigning = async (event, delegation) => {
671
742
 
672
743
  For more help, join our [Discord community](https://discord.gg/nostr) or [open an issue](https://github.com/humanjavaenterprises/nostr-crypto-utils/issues).
673
744
 
674
- ## Installation
675
-
676
- ```bash
677
- npm install @humanjavaenterprises/nostr-crypto-utils
678
- ```
679
-
680
- ## Quick Start
681
-
682
- ```typescript
683
- import { createKeyPair, createTextNoteEvent, signEvent } from '@humanjavaenterprises/nostr-crypto-utils';
684
-
685
- // Generate a new key pair
686
- const keyPair = createKeyPair();
687
-
688
- // Create a text note event
689
- const event = createTextNoteEvent({
690
- content: 'Hello Nostr!',
691
- pubkey: keyPair.publicKey,
692
- created_at: Math.floor(Date.now() / 1000)
693
- });
694
-
695
- // Sign the event
696
- const signedEvent = signEvent(event, keyPair.privateKey);
697
- ```
698
-
699
- ## Documentation
700
-
701
- Comprehensive documentation is available at [https://humanjavaenterprises.github.io/nostr-crypto-utils/](https://humanjavaenterprises.github.io/nostr-crypto-utils/)
702
-
703
- ## Type Safety
704
-
705
- This library is written in TypeScript and provides comprehensive type definitions for all functions and data structures. Type checking is enforced at compile time to catch potential errors early.
706
-
707
- ```typescript
708
- import { NostrEvent, NostrFilter, ValidationResult } from '@humanjavaenterprises/nostr-crypto-utils';
709
-
710
- // All types are properly defined
711
- const filter: NostrFilter = {
712
- kinds: [NostrEventKind.TEXT_NOTE],
713
- "#t": ["nostr", "crypto"], // Filter by custom tag
714
- limit: 10
715
- };
716
-
717
- // Validation results include type information
718
- const result: ValidationResult = validateEvent(event);
719
- ```
720
-
721
745
  ## Contributing
722
746
 
723
747
  We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.
@@ -728,29 +752,14 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
728
752
 
729
753
  ## Changelog
730
754
 
731
- ### v0.3.0 (2024-12-28)
732
- - 🔒 Improved type safety with stricter TypeScript checks
733
- - 🐛 Fixed crypto implementation for cross-platform compatibility
734
- - ✨ Added comprehensive validation for all message types
735
- - 📝 Updated documentation with more examples
736
-
737
- ### v0.2.0 (2024-12-26)
738
- - 🎉 Initial public release
739
- - ✨ Added support for NIP-01 and NIP-04
740
- - 🔑 Implemented key pair generation and management
741
- - 📝 Added comprehensive documentation
755
+ See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.
742
756
 
743
757
  ## Support
744
758
 
745
- - 📖 [Documentation](https://humanjavaenterprises.github.io/nostr-crypto-utils/)
746
- - 🐛 [Issue Tracker](https://github.com/humanjavaenterprises/nostr-crypto-utils/issues)
747
- - 💬 [Discussions](https://github.com/humanjavaenterprises/nostr-crypto-utils/discussions)
759
+ - [Documentation](https://humanjavaenterprises.github.io/nostr-crypto-utils/)
760
+ - [Issue Tracker](https://github.com/HumanjavaEnterprises/nostr-crypto-utils/issues)
761
+ - [Discussions](https://github.com/HumanjavaEnterprises/nostr-crypto-utils/discussions)
748
762
 
749
763
  ## Related Projects
750
764
 
751
- - [@humanjavaenterprises/nostr-nsec-seedphrase](https://github.com/HumanjavaEnterprises/nostr-nsec-seedphrase) - Generate and manage Nostr private keys using BIP-39 seed phrases
752
-
753
- ---
754
- <div align="center">
755
- Made with ❤️ by <a href="https://github.com/humanjavaenterprises">Humanjava Enterprises</a>
756
- </div>
765
+ - [nostr-nsec-seedphrase](https://github.com/HumanjavaEnterprises/nostr-nsec-seedphrase) - Generate and manage Nostr private keys using BIP-39 seed phrases
@@ -1 +1,15 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NostrCryptoUtils=e():(t.NostrCryptoUtils=t.NostrCryptoUtils||{},t.NostrCryptoUtils.crypto=e())}(this,(()=>(()=>{var t,e,r,o={8300:(t,e,r)=>{"use strict";var o=r(8510),n=r(3039),i=r(1565);new class{constructor(){this.cryptoInstance=null,this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await(async()=>{if("undefined"!=typeof window)return{};if(void 0!==r.g)return{};try{const t=await Promise.resolve().then(r.t.bind(r,1565,19));if(t.webcrypto)return t.webcrypto}catch{n.vF.debug("Node crypto not available, falling back to crypto-browserify")}return i})()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(t){return(await this.ensureInitialized()).getRandomValues(t)}},o.ko.sign,o.ko.verify},3039:(t,e,r)=>{"use strict";r.d(e,{vF:()=>a});var o,n=r(4874),i=r.n(n),s=r(5606);!function(t){t[t.DEBUG=0]="DEBUG",t[t.INFO=1]="INFO",t[t.WARN=2]="WARN",t[t.ERROR=3]="ERROR"}(o||(o={}));const a=i()({name:"nostr-crypto-utils",level:s.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:t=>({level:t.toUpperCase()}),log:t=>{if(t&&"object"==typeof t&&"err"in t){const e={...t};if(e.err instanceof Error){const t=e.err;e.err={message:t.message,stack:t.stack,name:t.name}}return e}return t}}})},8982:()=>{},7790:()=>{},1638:()=>{},2668:()=>{},7965:()=>{},6089:()=>{},9368:()=>{},4688:()=>{},1069:()=>{},3779:()=>{},7199:()=>{}},n={};function i(t){var e=n[t];if(void 0!==e)return e.exports;var r=n[t]={id:t,loaded:!1,exports:{}};return o[t].call(r.exports,r,r.exports,i),r.loaded=!0,r.exports}i.m=o,t=[],i.O=(e,r,o,n)=>{if(!r){var s=1/0;for(u=0;u<t.length;u++){for(var[r,o,n]=t[u],a=!0,l=0;l<r.length;l++)(!1&n||s>=n)&&Object.keys(i.O).every((t=>i.O[t](r[l])))?r.splice(l--,1):(a=!1,n<s&&(s=n));if(a){t.splice(u--,1);var c=o();void 0!==c&&(e=c)}}return e}n=n||0;for(var u=t.length;u>0&&t[u-1][2]>n;u--)t[u]=t[u-1];t[u]=[r,o,n]},i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},r=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__proto__,i.t=function(t,o){if(1&o&&(t=this(t)),8&o)return t;if("object"==typeof t&&t){if(4&o&&t.__esModule)return t;if(16&o&&"function"==typeof t.then)return t}var n=Object.create(null);i.r(n);var s={};e=e||[null,r({}),r([]),r(r)];for(var a=2&o&&t;"object"==typeof a&&!~e.indexOf(a);a=r(a))Object.getOwnPropertyNames(a).forEach((e=>s[e]=()=>t[e]));return s.default=()=>t,i.d(n,s),n},i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.nmd=t=>(t.paths=[],t.children||(t.children=[]),t),(()=>{var t={584:0};i.O.j=e=>0===t[e];var e=(e,r)=>{var o,n,[s,a,l]=r,c=0;if(s.some((e=>0!==t[e]))){for(o in a)i.o(a,o)&&(i.m[o]=a[o]);if(l)var u=l(i)}for(e&&e(r);c<s.length;c++)n=s[c],i.o(t,n)&&t[n]&&t[n][0](),t[n]=0;return i.O(u)},r=this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))})();var s=i.O(void 0,[851,344,404,156,503,636,419,801,995,473,26,128,54,490,430,657,158,761,510,705,613,985,509,802,310,829,890,287,389],(()=>i(8300)));return(s=i.O(s)).default})()));
1
+ "use strict";var NostrCryptoUtils=NostrCryptoUtils||{};NostrCryptoUtils.Crypto=(()=>{var Zr=Object.create;var Nt=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var $r=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,Wr=Object.prototype.hasOwnProperty;var Xr=(t,e,n)=>e in t?Nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Jr=(t,e)=>()=>(t&&(e=t(t=0)),e);var $e=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ye=(t,e)=>{for(var n in e)Nt(t,n,{get:e[n],enumerable:!0})},We=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $r(e))!Wr.call(t,o)&&o!==n&&Nt(t,o,{get:()=>e[o],enumerable:!(r=Gr(e,o))||r.enumerable});return t};var Qr=(t,e,n)=>(n=t!=null?Zr(Yr(t)):{},We(e||!t||!t.__esModule?Nt(n,"default",{value:t,enumerable:!0}):n,t)),Fr=t=>We(Nt({},"__esModule",{value:!0}),t);var Wt=(t,e,n)=>Xr(t,typeof e!="symbol"?e+"":e,n);var kr=$e((os,Ur)=>{"use strict";function On(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}Ur.exports=Hn;function Hn(t,e,n){var r=n&&n.stringify||On,o=1;if(typeof t=="object"&&t!==null){var s=e.length+o;if(s===1)return t;var i=new Array(s);i[0]=r(t);for(var c=1;c<s;c++)i[c]=r(e[c]);return i.join(" ")}if(typeof t!="string")return t;var f=e.length;if(f===0)return t;for(var a="",d=1-o,b=-1,l=t&&t.length||0,u=0;u<l;){if(t.charCodeAt(u)===37&&u+1<l){switch(b=b>-1?b:0,t.charCodeAt(u+1)){case 100:case 102:if(d>=f||e[d]==null)break;b<u&&(a+=t.slice(b,u)),a+=Number(e[d]),b=u+2,u++;break;case 105:if(d>=f||e[d]==null)break;b<u&&(a+=t.slice(b,u)),a+=Math.floor(Number(e[d])),b=u+2,u++;break;case 79:case 111:case 106:if(d>=f||e[d]===void 0)break;b<u&&(a+=t.slice(b,u));var x=typeof e[d];if(x==="string"){a+="'"+e[d]+"'",b=u+2,u++;break}if(x==="function"){a+=e[d].name||"<anonymous>",b=u+2,u++;break}a+=r(e[d]),b=u+2,u++;break;case 115:if(d>=f)break;b<u&&(a+=t.slice(b,u)),a+=String(e[d]),b=u+2,u++;break;case 37:b<u&&(a+=t.slice(b,u)),a+="%",b=u+2,u++,d--;break}++d}++u}return b===-1?t:(b<l&&(a+=t.slice(b)),a)}});var Vr=$e((ss,ye)=>{"use strict";var Rr=kr();ye.exports=ct;var Dt=Mn().console||{},Tn={mapHttpRequest:de,mapHttpResponse:de,wrapRequestSerializer:qe,wrapResponseSerializer:qe,wrapErrorSerializer:qe,req:de,res:de,err:Cr,errWithCause:Cr};function he(t,e){return t==="silent"?1/0:e.levels.values[t]}var Pe=Symbol("pino.logFuncs"),Ke=Symbol("pino.hierarchy"),Ln={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Nr(t,e){let n={logger:e,parent:t[Ke]};e[Ke]=n}function Un(t,e,n){let r={};e.forEach(o=>{r[o]=n[o]?n[o]:Dt[o]||Dt[Ln[o]||"log"]||Mt}),t[Pe]=r}function kn(t,e){return Array.isArray(t)?t.filter(function(r){return r!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function ct(t){t=t||{},t.browser=t.browser||{};let e=t.browser.transmit;if(e&&typeof e.send!="function")throw Error("pino: transmit option must have a send function");let n=t.browser.write||Dt;t.browser.write&&(t.browser.asObject=!0);let r=t.serializers||{},o=kn(t.browser.serialize,r),s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);let i=Object.keys(t.customLevels||{}),c=["error","fatal","warn","info","debug","trace"].concat(i);typeof n=="function"&&c.forEach(function(m){n[m]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");let f=t.level||"info",a=Object.create(n);a.log||(a.log=Mt),Un(a,c,n),Nr({},a),Object.defineProperty(a,"levelVal",{get:b}),Object.defineProperty(a,"level",{get:l,set:u});let d={transmit:e,serialize:o,asObject:t.browser.asObject,formatters:t.browser.formatters,levels:c,timestamp:jn(t)};a.levels=Rn(t),a.level=f,a.setMaxListeners=a.getMaxListeners=a.emit=a.addListener=a.on=a.prependListener=a.once=a.prependOnceListener=a.removeListener=a.removeAllListeners=a.listeners=a.listenerCount=a.eventNames=a.write=a.flush=Mt,a.serializers=r,a._serialize=o,a._stdErrSerialize=s,a.child=x,e&&(a._logEvent=Ve());function b(){return he(this.level,this)}function l(){return this._level}function u(m){if(m!=="silent"&&!this.levels.values[m])throw Error("unknown level "+m);this._level=m,Bt(this,d,a,"error"),Bt(this,d,a,"fatal"),Bt(this,d,a,"warn"),Bt(this,d,a,"info"),Bt(this,d,a,"debug"),Bt(this,d,a,"trace"),i.forEach(_=>{Bt(this,d,a,_)})}function x(m,_){if(!m)throw new Error("missing bindings for child Pino");_=_||{},o&&m.serializers&&(_.serializers=m.serializers);let L=_.serializers;if(o&&L){var J=Object.assign({},r,L),U=t.browser.serialize===!0?Object.keys(J):o;delete m.serializers,be([m],U,J,this._stdErrSerialize)}function Q(tt){this._childLevel=(tt._childLevel|0)+1,this.bindings=m,J&&(this.serializers=J,this._serialize=U),e&&(this._logEvent=Ve([].concat(tt._logEvent.bindings,m)))}Q.prototype=this;let Z=new Q(this);return Nr(this,Z),Z.level=this.level,Z}return a}function Rn(t){let e=t.customLevels||{},n=Object.assign({},ct.levels.values,e),r=Object.assign({},ct.levels.labels,Nn(e));return{values:n,labels:r}}function Nn(t){let e={};return Object.keys(t).forEach(function(n){e[t[n]]=n}),e}ct.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}};ct.stdSerializers=Tn;ct.stdTimeFunctions=Object.assign({},{nullTime:qr,epochTime:Kr,unixTime:zn,isoTime:Dn});function Cn(t){let e=[];t.bindings&&e.push(t.bindings);let n=t[Ke];for(;n.parent;)n=n.parent,n.logger.bindings&&e.push(n.logger.bindings);return e.reverse()}function Bt(t,e,n,r){if(Object.defineProperty(t,r,{value:he(t.level,n)>he(r,n)?Mt:n[Pe][r],writable:!0,enumerable:!0,configurable:!0}),!e.transmit&&t[r]===Mt)return;t[r]=Kn(t,e,n,r);let o=Cn(t);o.length!==0&&(t[r]=qn(o,t[r]))}function qn(t,e){return function(){return e.apply(this,[...t,...arguments])}}function Kn(t,e,n,r){return(function(o){return function(){let i=e.timestamp(),c=new Array(arguments.length),f=Object.getPrototypeOf&&Object.getPrototypeOf(this)===Dt?Dt:this;for(var a=0;a<c.length;a++)c[a]=arguments[a];if(e.serialize&&!e.asObject&&be(c,this._serialize,this.serializers,this._stdErrSerialize),e.asObject||e.formatters?o.call(f,Vn(this,r,c,i,e.formatters)):o.apply(f,c),e.transmit){let d=e.transmit.level||t._level,b=n.levels.values[d],l=n.levels.values[r];if(l<b)return;Pn(this,{ts:i,methodLevel:r,methodValue:l,transmitLevel:d,transmitValue:n.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:he(t._level,n)},c)}}})(t[Pe][r])}function Vn(t,e,n,r,o={}){let{level:s=()=>t.levels.values[e],log:i=l=>l}=o;t._serialize&&be(n,t._serialize,t.serializers,t._stdErrSerialize);let c=n.slice(),f=c[0],a={};r&&(a.time=r),a.level=s(e,t.levels.values[e]);let d=(t._childLevel|0)+1;if(d<1&&(d=1),f!==null&&typeof f=="object"){for(;d--&&typeof c[0]=="object";)Object.assign(a,c.shift());f=c.length?Rr(c.shift(),c):void 0}else typeof f=="string"&&(f=Rr(c.shift(),c));return f!==void 0&&(a.msg=f),i(a)}function be(t,e,n,r){for(let o in t)if(r&&t[o]instanceof Error)t[o]=ct.stdSerializers.err(t[o]);else if(typeof t[o]=="object"&&!Array.isArray(t[o]))for(let s in t[o])e&&e.indexOf(s)>-1&&s in n&&(t[o][s]=n[s](t[o][s]))}function Pn(t,e,n){let r=e.send,o=e.ts,s=e.methodLevel,i=e.methodValue,c=e.val,f=t._logEvent.bindings;be(n,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=o,t._logEvent.messages=n.filter(function(a){return f.indexOf(a)===-1}),t._logEvent.level.label=s,t._logEvent.level.value=i,r(s,t._logEvent,c),t._logEvent=Ve(f)}function Ve(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function Cr(t){let e={type:t.constructor.name,msg:t.message,stack:t.stack};for(let n in t)e[n]===void 0&&(e[n]=t[n]);return e}function jn(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?qr:Kr}function de(){return{}}function qe(t){return t}function Mt(){}function qr(){return!1}function Kr(){return Date.now()}function zn(){return Math.round(Date.now()/1e3)}function Dn(){return new Date(Date.now()).toISOString()}function Mn(){function t(e){return typeof e<"u"&&e}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return t(self)||t(window)||t(this)||{}}}ye.exports.default=ct;ye.exports.pino=ct});var jr={};Ye(jr,{default:()=>Gn});var Gn,zr=Jr(()=>{Gn={}});var so={};Ye(so,{createEvent:()=>to,customCrypto:()=>Zt,decrypt:()=>oo,encrypt:()=>no,finalizeEvent:()=>eo,generateKeyPair:()=>Qn,getCompressedPublicKey:()=>Xn,getPublicKey:()=>Me,getPublicKeySync:()=>Mr,getSchnorrPublicKey:()=>Jn,signEvent:()=>Dr,signSchnorr:()=>Yn,validateKeyPair:()=>Fn,verifySchnorrSignature:()=>Wn,verifySignature:()=>ro});var pt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ft(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function St(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function G(t,...e){if(!ft(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Xt(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");St(t.outputLen),St(t.blockLen)}function _t(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Je(t,e){G(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function gt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Jt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function $(t,e){return t<<32-e|t>>>e}var Qe=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Y(t){if(G(t),Qe)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=tn[t[n]];return e}var et={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xe(t){if(t>=et._0&&t<=et._9)return t-et._0;if(t>=et.A&&t<=et.F)return t-(et.A-10);if(t>=et.a&&t<=et.f)return t-(et.a-10)}function rt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Qe)return Uint8Array.fromHex(t);let e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){let i=Xe(t.charCodeAt(s)),c=Xe(t.charCodeAt(s+1));if(i===void 0||c===void 0){let f=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}r[o]=i*16+c}return r}function Ct(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function qt(t){return typeof t=="string"&&(t=Ct(t)),G(t),t}function P(...t){let e=0;for(let r=0;r<t.length;r++){let o=t[r];G(o),e+=o.length}let n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){let s=t[r];n.set(s,o),o+=s.length}return n}var At=class{};function Fe(t){let e=r=>t().update(qt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function W(t=32){if(pt&&typeof pt.getRandomValues=="function")return pt.getRandomValues(new Uint8Array(t));if(pt&&typeof pt.randomBytes=="function")return Uint8Array.from(pt.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function en(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),s=BigInt(4294967295),i=Number(n>>o&s),c=Number(n&s),f=r?4:0,a=r?0:4;t.setUint32(e+f,i,r),t.setUint32(e+a,c,r)}function tr(t,e,n){return t&e^~t&n}function er(t,e,n){return t&e^t&n^e&n}var Qt=class extends At{constructor(e,n,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Jt(this.buffer)}update(e){_t(this),e=qt(e),G(e);let{view:n,buffer:r,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=Jt(e);for(;o<=s-i;i+=o)this.process(f,i);continue}r.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){_t(this),Je(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:s}=this,{pos:i}=this;n[i++]=128,gt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(r,0),i=0);for(let b=i;b<o;b++)n[b]=0;en(r,o-8,BigInt(this.length*8),s),this.process(r,0);let c=Jt(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=f/4,d=this.get();if(a>d.length)throw new Error("_sha2: outputLen bigger than state");for(let b=0;b<a;b++)c.setUint32(4*b,d[b],s)}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}},nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var rn=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]),ut=new Uint32Array(64),Ft=class extends Qt{constructor(e=32){super(64,e,8,!1),this.A=nt[0]|0,this.B=nt[1]|0,this.C=nt[2]|0,this.D=nt[3]|0,this.E=nt[4]|0,this.F=nt[5]|0,this.G=nt[6]|0,this.H=nt[7]|0}get(){let{A:e,B:n,C:r,D:o,E:s,F:i,G:c,H:f}=this;return[e,n,r,o,s,i,c,f]}set(e,n,r,o,s,i,c,f){this.A=e|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=f|0}process(e,n){for(let b=0;b<16;b++,n+=4)ut[b]=e.getUint32(n,!1);for(let b=16;b<64;b++){let l=ut[b-15],u=ut[b-2],x=$(l,7)^$(l,18)^l>>>3,m=$(u,17)^$(u,19)^u>>>10;ut[b]=m+ut[b-7]+x+ut[b-16]|0}let{A:r,B:o,C:s,D:i,E:c,F:f,G:a,H:d}=this;for(let b=0;b<64;b++){let l=$(c,6)^$(c,11)^$(c,25),u=d+l+tr(c,f,a)+rn[b]+ut[b]|0,m=($(r,2)^$(r,13)^$(r,22))+er(r,o,s)|0;d=a,a=f,f=c,c=i+u|0,i=s,s=o,o=r,r=u+m|0}r=r+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,a=a+this.G|0,d=d+this.H|0,this.set(r,o,s,i,c,f,a,d)}roundClean(){gt(ut)}destroy(){this.set(0,0,0,0,0,0,0,0),gt(this.buffer)}};var It=Fe(()=>new Ft);var te=class extends At{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Xt(e);let r=qt(n);if(this.iHash=e.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(r.length>o?e.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),gt(s)}update(e){return _t(this),this.iHash.update(e),this}digestInto(e){_t(this),G(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:r,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.oHash=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},pe=(t,e,n)=>new te(t,e).update(n).digest();pe.create=(t,e)=>new te(t,e);var xe=BigInt(0),me=BigInt(1);function Kt(t,e=""){if(typeof t!="boolean"){let n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function lt(t,e,n=""){let r=ft(t),o=t?.length,s=e!==void 0;if(!r||s&&o!==e){let i=n&&`"${n}" `,c=s?` of length ${e}`:"",f=r?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return t}function Ot(t){let e=t.toString(16);return e.length&1?"0"+e:e}function we(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?xe:BigInt("0x"+t)}function F(t){return we(Y(t))}function ee(t){return G(t),we(Y(Uint8Array.from(t).reverse()))}function mt(t,e){return rt(t.toString(16).padStart(e*2,"0"))}function re(t,e){return mt(t,e).reverse()}function k(t,e,n){let r;if(typeof e=="string")try{r=rt(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(ft(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=r.length;if(typeof n=="number"&&o!==n)throw new Error(t+" of length "+n+" expected, got "+o);return r}var ge=t=>typeof t=="bigint"&&xe<=t;function Ht(t,e,n){return ge(t)&&ge(e)&&ge(n)&&e<=t&&t<n}function Ee(t,e,n,r){if(!Ht(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Vt(t){let e;for(e=0;t>xe;t>>=me,e+=1);return e}var ot=t=>(me<<BigInt(t))-me;function Be(t,e,n){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=u=>new Uint8Array(u),o=u=>Uint8Array.of(u),s=r(t),i=r(t),c=0,f=()=>{s.fill(1),i.fill(0),c=0},a=(...u)=>n(i,s,...u),d=(u=r(0))=>{i=a(o(0),u),s=a(),u.length!==0&&(i=a(o(1),u),s=a())},b=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,x=[];for(;u<e;){s=a();let m=s.slice();x.push(m),u+=s.length}return P(...x)};return(u,x)=>{f(),d(u);let m;for(;!(m=x(b()));)d();return f(),m}}function Pt(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(o,s,i){let c=t[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(e).forEach(([o,s])=>r(o,s,!1)),Object.entries(n).forEach(([o,s])=>r(o,s,!0))}function ne(t){let e=new WeakMap;return(n,...r)=>{let o=e.get(n);if(o!==void 0)return o;let s=t(n,...r);return e.set(n,s),s}}var j=BigInt(0),V=BigInt(1),xt=BigInt(2),or=BigInt(3),sr=BigInt(4),ir=BigInt(5),sn=BigInt(7),cr=BigInt(8),cn=BigInt(9),ar=BigInt(16);function D(t,e){let n=t%e;return n>=j?n:e+n}function M(t,e,n){let r=t;for(;e-- >j;)r*=r,r%=n;return r}function rr(t,e){if(t===j)throw new Error("invert: expected non-zero number");if(e<=j)throw new Error("invert: expected positive modulus, got "+e);let n=D(t,e),r=e,o=j,s=V,i=V,c=j;for(;n!==j;){let a=r/n,d=r%n,b=o-i*a,l=s-c*a;r=n,n=d,o=i,s=c,i=b,c=l}if(r!==V)throw new Error("invert: does not exist");return D(o,e)}function ve(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function fr(t,e){let n=(t.ORDER+V)/sr,r=t.pow(e,n);return ve(t,r,e),r}function an(t,e){let n=(t.ORDER-ir)/cr,r=t.mul(e,xt),o=t.pow(r,n),s=t.mul(e,o),i=t.mul(t.mul(s,xt),o),c=t.mul(s,t.sub(i,t.ONE));return ve(t,c,e),c}function fn(t){let e=dt(t),n=ur(t),r=n(e,e.neg(e.ONE)),o=n(e,r),s=n(e,e.neg(r)),i=(t+sn)/ar;return(c,f)=>{let a=c.pow(f,i),d=c.mul(a,r),b=c.mul(a,o),l=c.mul(a,s),u=c.eql(c.sqr(d),f),x=c.eql(c.sqr(b),f);a=c.cmov(a,d,u),d=c.cmov(l,b,x);let m=c.eql(c.sqr(d),f),_=c.cmov(a,d,m);return ve(c,_,f),_}}function ur(t){if(t<or)throw new Error("sqrt is not defined for small field");let e=t-V,n=0;for(;e%xt===j;)e/=xt,n++;let r=xt,o=dt(t);for(;nr(o,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return fr;let s=o.pow(r,e),i=(e+V)/xt;return function(f,a){if(f.is0(a))return a;if(nr(f,a)!==1)throw new Error("Cannot find square root");let d=n,b=f.mul(f.ONE,s),l=f.pow(a,e),u=f.pow(a,i);for(;!f.eql(l,f.ONE);){if(f.is0(l))return f.ZERO;let x=1,m=f.sqr(l);for(;!f.eql(m,f.ONE);)if(x++,m=f.sqr(m),x===d)throw new Error("Cannot find square root");let _=V<<BigInt(d-x-1),L=f.pow(b,_);d=x,b=f.sqr(L),l=f.mul(l,b),u=f.mul(u,L)}return u}}function un(t){return t%sr===or?fr:t%cr===ir?an:t%ar===cn?fn(t):ur(t)}var ln=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Se(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=ln.reduce((r,o)=>(r[o]="function",r),e);return Pt(t,n),t}function dn(t,e,n){if(n<j)throw new Error("invalid exponent, negatives unsupported");if(n===j)return t.ONE;if(n===V)return e;let r=t.ONE,o=e;for(;n>j;)n&V&&(r=t.mul(r,o)),o=t.sqr(o),n>>=V;return r}function oe(t,e,n=!1){let r=new Array(e.length).fill(n?t.ZERO:void 0),o=e.reduce((i,c,f)=>t.is0(c)?i:(r[f]=i,t.mul(i,c)),t.ONE),s=t.inv(o);return e.reduceRight((i,c,f)=>t.is0(c)?i:(r[f]=t.mul(i,r[f]),t.mul(i,c)),s),r}function nr(t,e){let n=(t.ORDER-V)/xt,r=t.pow(e,n),o=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),i=t.eql(r,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function se(t,e){e!==void 0&&St(e);let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function dt(t,e,n=!1,r={}){if(t<=j)throw new Error("invalid field: expected ORDER > 0, got "+t);let o,s,i=!1,c;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");let l=e;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(n=l.isLE),typeof l.modFromBytes=="boolean"&&(i=l.modFromBytes),c=l.allowedLengths}else typeof e=="number"&&(o=e),r.sqrt&&(s=r.sqrt);let{nBitLength:f,nByteLength:a}=se(t,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,b=Object.freeze({ORDER:t,isLE:n,BITS:f,BYTES:a,MASK:ot(f),ZERO:j,ONE:V,allowedLengths:c,create:l=>D(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return j<=l&&l<t},is0:l=>l===j,isValidNot0:l=>!b.is0(l)&&b.isValid(l),isOdd:l=>(l&V)===V,neg:l=>D(-l,t),eql:(l,u)=>l===u,sqr:l=>D(l*l,t),add:(l,u)=>D(l+u,t),sub:(l,u)=>D(l-u,t),mul:(l,u)=>D(l*u,t),pow:(l,u)=>dn(b,l,u),div:(l,u)=>D(l*rr(u,t),t),sqrN:l=>l*l,addN:(l,u)=>l+u,subN:(l,u)=>l-u,mulN:(l,u)=>l*u,inv:l=>rr(l,t),sqrt:s||(l=>(d||(d=un(t)),d(b,l))),toBytes:l=>n?re(l,a):mt(l,a),fromBytes:(l,u=!0)=>{if(c){if(!c.includes(l.length)||l.length>a)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+l.length);let m=new Uint8Array(a);m.set(l,n?0:m.length-l.length),l=m}if(l.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let x=n?ee(l):F(l);if(i&&(x=D(x,t)),!u&&!b.isValid(x))throw new Error("invalid field element: outside of range 0..ORDER");return x},invertBatch:l=>oe(b,l),cmov:(l,u,x)=>x?u:l});return Object.freeze(b)}function lr(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ae(t){let e=lr(t);return e+Math.ceil(e/2)}function ie(t,e,n=!1){let r=t.length,o=lr(e),s=Ae(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);let i=n?ee(t):F(t),c=D(i,e-V)+V;return n?re(c,o):mt(c,o)}var Tt=BigInt(0),wt=BigInt(1);function jt(t,e){let n=e.negate();return t?n:e}function ae(t,e){let n=oe(t.Fp,e.map(r=>r.Z));return e.map((r,o)=>t.fromAffine(r.toAffine(n[o])))}function yr(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function _e(t,e){yr(t,e);let n=Math.ceil(e/t)+1,r=2**(t-1),o=2**t,s=ot(t),i=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:o,shiftBy:i}}function dr(t,e,n){let{windowSize:r,mask:o,maxNumber:s,shiftBy:i}=n,c=Number(t&o),f=t>>i;c>r&&(c-=s,f+=wt);let a=e*r,d=a+Math.abs(c)-1,b=c===0,l=c<0,u=e%2!==0;return{nextN:f,offset:d,isZero:b,isNeg:l,isNegF:u,offsetF:a}}function bn(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function yn(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}var Ie=new WeakMap,pr=new WeakMap;function Oe(t){return pr.get(t)||1}function hr(t){if(t!==Tt)throw new Error("invalid wNAF")}var ce=class{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let o=e;for(;n>Tt;)n&wt&&(r=r.add(o)),o=o.double(),n>>=wt;return r}precomputeWindow(e,n){let{windows:r,windowSize:o}=_e(n,this.bits),s=[],i=e,c=i;for(let f=0;f<r;f++){c=i,s.push(c);for(let a=1;a<o;a++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=_e(e,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:d,isNeg:b,isNegF:l,offsetF:u}=dr(r,c,i);r=f,d?s=s.add(jt(l,n[u])):o=o.add(jt(b,n[a]))}return hr(r),{p:o,f:s}}wNAFUnsafe(e,n,r,o=this.ZERO){let s=_e(e,this.bits);for(let i=0;i<s.windows&&r!==Tt;i++){let{nextN:c,offset:f,isZero:a,isNeg:d}=dr(r,i,s);if(r=c,!a){let b=n[f];o=o.add(d?b.negate():b)}}return hr(r),o}getPrecomputes(e,n,r){let o=Ie.get(n);return o||(o=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(o=r(o)),Ie.set(n,o))),o}cached(e,n,r){let o=Oe(e);return this.wNAF(o,this.getPrecomputes(o,e,r),n)}unsafe(e,n,r,o){let s=Oe(e);return s===1?this._unsafeLadder(e,n,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,o)}createCache(e,n){yr(n,this.bits),pr.set(e,n),Ie.delete(e)}hasCache(e){return Oe(e)!==1}};function gr(t,e,n,r){let o=e,s=t.ZERO,i=t.ZERO;for(;n>Tt||r>Tt;)n&wt&&(s=s.add(o)),r&wt&&(i=i.add(o)),o=o.double(),n>>=wt,r>>=wt;return{p1:s,p2:i}}function mr(t,e,n,r){bn(n,t),yn(r,e);let o=n.length,s=r.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,c=Vt(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let a=ot(f),d=new Array(Number(a)+1).fill(i),b=Math.floor((e.BITS-1)/f)*f,l=i;for(let u=b;u>=0;u-=f){d.fill(i);for(let m=0;m<s;m++){let _=r[m],L=Number(_>>BigInt(u)&a);d[L]=d[L].add(n[m])}let x=i;for(let m=d.length-1,_=i;m>0;m--)_=_.add(d[m]),x=x.add(_);if(l=l.add(x),u!==0)for(let m=0;m<f;m++)l=l.double()}return l}function br(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Se(e),e}else return dt(t,{isLE:n})}function xr(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let f of["p","n","h"]){let a=e[f];if(!(typeof a=="bigint"&&a>Tt))throw new Error(`CURVE.${f} must be positive bigint`)}let o=br(e.p,n.Fp,r),s=br(e.n,n.Fn,r),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let f of c)if(!o.isValid(e[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}var wr=(t,e)=>(t+(t>=0?e:-e)/Er)/e;function pn(t,e,n){let[[r,o],[s,i]]=e,c=wr(i*t,n),f=wr(-o*t,n),a=t-c*r-f*s,d=-c*o-f*i,b=a<it,l=d<it;b&&(a=-a),l&&(d=-d);let u=ot(Math.ceil(Vt(n)/2))+Lt;if(a<it||a>=u||d<it||d>=u)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:b,k1:a,k2neg:l,k2:d}}function Te(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function He(t,e){let n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return Kt(n.lowS,"lowS"),Kt(n.prehash,"prehash"),n.format!==void 0&&Te(n.format),n}var Le=class extends Error{constructor(e=""){super(e)}},st={Err:Le,_tlv:{encode:(t,e)=>{let{Err:n}=st;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");let r=e.length/2,o=Ot(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");let s=r>127?Ot(o.length/2|128):"";return Ot(t)+s+o+e},decode(t,e){let{Err:n}=st,r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");let o=e[r++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new n("tlv.decode(long): indefinite length not supported");if(f>4)throw new n("tlv.decode(long): byte length is too big");let a=e.subarray(r,r+f);if(a.length!==f)throw new n("tlv.decode: length bytes not complete");if(a[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(let d of a)i=i<<8|d;if(r+=f,i<128)throw new n("tlv.decode(long): not minimal encoding")}let c=e.subarray(r,r+i);if(c.length!==i)throw new n("tlv.decode: wrong value length");return{v:c,l:e.subarray(r+i)}}},_int:{encode(t){let{Err:e}=st;if(t<it)throw new e("integer: negative integers are not allowed");let n=Ot(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){let{Err:e}=st;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return F(t)}},toSig(t){let{Err:e,_int:n,_tlv:r}=st,o=k("signature",t),{v:s,l:i}=r.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:f}=r.decode(2,s),{v:a,l:d}=r.decode(2,f);if(d.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(c),s:n.decode(a)}},hexFromSig(t){let{_tlv:e,_int:n}=st,r=e.encode(2,n.encode(t.r)),o=e.encode(2,n.encode(t.s)),s=r+o;return e.encode(48,s)}},it=BigInt(0),Lt=BigInt(1),Er=BigInt(2),fe=BigInt(3),gn=BigInt(4);function ht(t,e){let{BYTES:n}=t,r;if(typeof e=="bigint")r=e;else{let o=k("private key",e);try{r=t.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function mn(t,e={}){let n=xr("weierstrass",t,e),{Fp:r,Fn:o}=n,s=n.CURVE,{h:i,n:c}=s;Pt(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:f}=e;if(f&&(!r.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let a=vr(r,o);function d(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function b(H,p,y){let{x:h,y:g}=p.toAffine(),w=r.toBytes(h);if(Kt(y,"isCompressed"),y){d();let v=!r.isOdd(g);return P(Br(v),w)}else return P(Uint8Array.of(4),w,r.toBytes(g))}function l(H){lt(H,void 0,"Point");let{publicKey:p,publicKeyUncompressed:y}=a,h=H.length,g=H[0],w=H.subarray(1);if(h===p&&(g===2||g===3)){let v=r.fromBytes(w);if(!r.isValid(v))throw new Error("bad point: is not on curve, wrong x");let B=m(v),E;try{E=r.sqrt(B)}catch(C){let T=C instanceof Error?": "+C.message:"";throw new Error("bad point: is not on curve, sqrt error"+T)}d();let S=r.isOdd(E);return(g&1)===1!==S&&(E=r.neg(E)),{x:v,y:E}}else if(h===y&&g===4){let v=r.BYTES,B=r.fromBytes(w.subarray(0,v)),E=r.fromBytes(w.subarray(v,v*2));if(!_(B,E))throw new Error("bad point: is not on curve");return{x:B,y:E}}else throw new Error(`bad point: got length ${h}, expected compressed=${p} or uncompressed=${y}`)}let u=e.toBytes||b,x=e.fromBytes||l;function m(H){let p=r.sqr(H),y=r.mul(p,H);return r.add(r.add(y,r.mul(H,s.a)),s.b)}function _(H,p){let y=r.sqr(p),h=m(H);return r.eql(y,h)}if(!_(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let L=r.mul(r.pow(s.a,fe),gn),J=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(L,J)))throw new Error("bad curve params: a or b");function U(H,p,y=!1){if(!r.isValid(p)||y&&r.is0(p))throw new Error(`bad point coordinate ${H}`);return p}function Q(H){if(!(H instanceof I))throw new Error("ProjectivePoint expected")}function Z(H){if(!f||!f.basises)throw new Error("no endo");return pn(H,f.basises,o.ORDER)}let tt=ne((H,p)=>{let{X:y,Y:h,Z:g}=H;if(r.eql(g,r.ONE))return{x:y,y:h};let w=H.is0();p==null&&(p=w?r.ONE:r.inv(g));let v=r.mul(y,p),B=r.mul(h,p),E=r.mul(g,p);if(w)return{x:r.ZERO,y:r.ZERO};if(!r.eql(E,r.ONE))throw new Error("invZ was invalid");return{x:v,y:B}}),Gt=ne(H=>{if(H.is0()){if(e.allowInfinityPoint&&!r.is0(H.Y))return;throw new Error("bad point: ZERO")}let{x:p,y}=H.toAffine();if(!r.isValid(p)||!r.isValid(y))throw new Error("bad point: x or y not field elements");if(!_(p,y))throw new Error("bad point: equation left != right");if(!H.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function vt(H,p,y,h,g){return y=new I(r.mul(y.X,H),y.Y,y.Z),p=jt(h,p),y=jt(g,y),p.add(y)}class I{constructor(p,y,h){this.X=U("x",p),this.Y=U("y",y,!0),this.Z=U("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:y,y:h}=p||{};if(!p||!r.isValid(y)||!r.isValid(h))throw new Error("invalid affine point");if(p instanceof I)throw new Error("projective point not allowed");return r.is0(y)&&r.is0(h)?I.ZERO:new I(y,h,r.ONE)}static fromBytes(p){let y=I.fromAffine(x(lt(p,void 0,"point")));return y.assertValidity(),y}static fromHex(p){return I.fromBytes(k("pointHex",p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,y=!0){return yt.createCache(this,p),y||this.multiply(fe),this}assertValidity(){Gt(this)}hasEvenY(){let{y:p}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(p)}equals(p){Q(p);let{X:y,Y:h,Z:g}=this,{X:w,Y:v,Z:B}=p,E=r.eql(r.mul(y,B),r.mul(w,g)),S=r.eql(r.mul(h,B),r.mul(v,g));return E&&S}negate(){return new I(this.X,r.neg(this.Y),this.Z)}double(){let{a:p,b:y}=s,h=r.mul(y,fe),{X:g,Y:w,Z:v}=this,B=r.ZERO,E=r.ZERO,S=r.ZERO,A=r.mul(g,g),C=r.mul(w,w),T=r.mul(v,v),O=r.mul(g,w);return O=r.add(O,O),S=r.mul(g,v),S=r.add(S,S),B=r.mul(p,S),E=r.mul(h,T),E=r.add(B,E),B=r.sub(C,E),E=r.add(C,E),E=r.mul(B,E),B=r.mul(O,B),S=r.mul(h,S),T=r.mul(p,T),O=r.sub(A,T),O=r.mul(p,O),O=r.add(O,S),S=r.add(A,A),A=r.add(S,A),A=r.add(A,T),A=r.mul(A,O),E=r.add(E,A),T=r.mul(w,v),T=r.add(T,T),A=r.mul(T,O),B=r.sub(B,A),S=r.mul(T,C),S=r.add(S,S),S=r.add(S,S),new I(B,E,S)}add(p){Q(p);let{X:y,Y:h,Z:g}=this,{X:w,Y:v,Z:B}=p,E=r.ZERO,S=r.ZERO,A=r.ZERO,C=s.a,T=r.mul(s.b,fe),O=r.mul(y,w),R=r.mul(h,v),q=r.mul(g,B),z=r.add(y,h),N=r.add(w,v);z=r.mul(z,N),N=r.add(O,R),z=r.sub(z,N),N=r.add(y,g);let K=r.add(w,B);return N=r.mul(N,K),K=r.add(O,q),N=r.sub(N,K),K=r.add(h,g),E=r.add(v,B),K=r.mul(K,E),E=r.add(R,q),K=r.sub(K,E),A=r.mul(C,N),E=r.mul(T,q),A=r.add(E,A),E=r.sub(R,A),A=r.add(R,A),S=r.mul(E,A),R=r.add(O,O),R=r.add(R,O),q=r.mul(C,q),N=r.mul(T,N),R=r.add(R,q),q=r.sub(O,q),q=r.mul(C,q),N=r.add(N,q),O=r.mul(R,N),S=r.add(S,O),O=r.mul(K,N),E=r.mul(z,E),E=r.sub(E,O),O=r.mul(z,R),A=r.mul(K,A),A=r.add(A,O),new I(E,S,A)}subtract(p){return this.add(p.negate())}is0(){return this.equals(I.ZERO)}multiply(p){let{endo:y}=e;if(!o.isValidNot0(p))throw new Error("invalid scalar: out of range");let h,g,w=v=>yt.cached(this,v,B=>ae(I,B));if(y){let{k1neg:v,k1:B,k2neg:E,k2:S}=Z(p),{p:A,f:C}=w(B),{p:T,f:O}=w(S);g=C.add(O),h=vt(y.beta,A,T,v,E)}else{let{p:v,f:B}=w(p);h=v,g=B}return ae(I,[h,g])[0]}multiplyUnsafe(p){let{endo:y}=e,h=this;if(!o.isValid(p))throw new Error("invalid scalar: out of range");if(p===it||h.is0())return I.ZERO;if(p===Lt)return h;if(yt.hasCache(this))return this.multiply(p);if(y){let{k1neg:g,k1:w,k2neg:v,k2:B}=Z(p),{p1:E,p2:S}=gr(I,h,w,B);return vt(y.beta,E,S,g,v)}else return yt.unsafe(h,p)}multiplyAndAddUnsafe(p,y,h){let g=this.multiplyUnsafe(y).add(p.multiplyUnsafe(h));return g.is0()?void 0:g}toAffine(p){return tt(this,p)}isTorsionFree(){let{isTorsionFree:p}=e;return i===Lt?!0:p?p(I,this):yt.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===Lt?this:p?p(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(p=!0){return Kt(p,"isCompressed"),this.assertValidity(),u(I,this,p)}toHex(p=!0){return Y(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(p=!0){return this.toBytes(p)}_setWindowSize(p){this.precompute(p)}static normalizeZ(p){return ae(I,p)}static msm(p,y){return mr(I,o,p,y)}static fromPrivateKey(p){return I.BASE.multiply(ht(o,p))}}I.BASE=new I(s.Gx,s.Gy,r.ONE),I.ZERO=new I(r.ZERO,r.ONE,r.ZERO),I.Fp=r,I.Fn=o;let $t=o.BITS,yt=new ce(I,e.endo?Math.ceil($t/2):$t);return I.BASE.precompute(8),I}function Br(t){return Uint8Array.of(t?2:3)}function vr(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function xn(t,e={}){let{Fn:n}=t,r=e.randomBytes||W,o=Object.assign(vr(t.Fp,n),{seed:Ae(n.ORDER)});function s(u){try{return!!ht(n,u)}catch{return!1}}function i(u,x){let{publicKey:m,publicKeyUncompressed:_}=o;try{let L=u.length;return x===!0&&L!==m||x===!1&&L!==_?!1:!!t.fromBytes(u)}catch{return!1}}function c(u=r(o.seed)){return ie(lt(u,o.seed,"seed"),n.ORDER)}function f(u,x=!0){return t.BASE.multiply(ht(n,u)).toBytes(x)}function a(u){let x=c(u);return{secretKey:x,publicKey:f(x)}}function d(u){if(typeof u=="bigint")return!1;if(u instanceof t)return!0;let{secretKey:x,publicKey:m,publicKeyUncompressed:_}=o;if(n.allowedLengths||x===m)return;let L=k("key",u).length;return L===m||L===_}function b(u,x,m=!0){if(d(u)===!0)throw new Error("first arg must be private key");if(d(x)===!1)throw new Error("second arg must be public key");let _=ht(n,u);return t.fromHex(x).multiply(_).toBytes(m)}return Object.freeze({getPublicKey:f,getSharedSecret:b,keygen:a,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:u=>ht(n,u),precompute(u=8,x=t.BASE){return x.precompute(u,!1)}},lengths:o})}function wn(t,e,n={}){Xt(e),Pt(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let r=n.randomBytes||W,o=n.hmac||((y,...h)=>pe(e,y,P(...h))),{Fp:s,Fn:i}=t,{ORDER:c,BITS:f}=i,{keygen:a,getPublicKey:d,getSharedSecret:b,utils:l,lengths:u}=xn(t,n),x={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},m="compact";function _(y){let h=c>>Lt;return y>h}function L(y,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return h}function J(y,h){Te(h);let g=u.signature,w=h==="compact"?g:h==="recovered"?g+1:void 0;return lt(y,w,`${h} signature`)}class U{constructor(h,g,w){this.r=L("r",h),this.s=L("s",g),w!=null&&(this.recovery=w),Object.freeze(this)}static fromBytes(h,g=m){J(h,g);let w;if(g==="der"){let{r:S,s:A}=st.toSig(lt(h));return new U(S,A)}g==="recovered"&&(w=h[0],g="compact",h=h.subarray(1));let v=i.BYTES,B=h.subarray(0,v),E=h.subarray(v,v*2);return new U(i.fromBytes(B),i.fromBytes(E),w)}static fromHex(h,g){return this.fromBytes(rt(h),g)}addRecoveryBit(h){return new U(this.r,this.s,h)}recoverPublicKey(h){let g=s.ORDER,{r:w,s:v,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(c*Er<g&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let S=B===2||B===3?w+c:w;if(!s.isValid(S))throw new Error("recovery id 2 or 3 invalid");let A=s.toBytes(S),C=t.fromBytes(P(Br((B&1)===0),A)),T=i.inv(S),O=Z(k("msgHash",h)),R=i.create(-O*T),q=i.create(v*T),z=t.BASE.multiplyUnsafe(R).add(C.multiplyUnsafe(q));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return _(this.s)}toBytes(h=m){if(Te(h),h==="der")return rt(st.hexFromSig(this));let g=i.toBytes(this.r),w=i.toBytes(this.s);if(h==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return P(Uint8Array.of(this.recovery),g,w)}return P(g,w)}toHex(h){return Y(this.toBytes(h))}assertValidity(){}static fromCompact(h){return U.fromBytes(k("sig",h),"compact")}static fromDER(h){return U.fromBytes(k("sig",h),"der")}normalizeS(){return this.hasHighS()?new U(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Y(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Y(this.toBytes("compact"))}}let Q=n.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let g=F(h),w=h.length*8-f;return w>0?g>>BigInt(w):g},Z=n.bits2int_modN||function(h){return i.create(Q(h))},tt=ot(f);function Gt(y){return Ee("num < 2^"+f,y,it,tt),i.toBytes(y)}function vt(y,h){return lt(y,void 0,"message"),h?lt(e(y),void 0,"prehashed message"):y}function I(y,h,g){if(["recovered","canonical"].some(R=>R in g))throw new Error("sign() legacy options not supported");let{lowS:w,prehash:v,extraEntropy:B}=He(g,x);y=vt(y,v);let E=Z(y),S=ht(i,h),A=[Gt(S),Gt(E)];if(B!=null&&B!==!1){let R=B===!0?r(u.secretKey):B;A.push(k("extraEntropy",R))}let C=P(...A),T=E;function O(R){let q=Q(R);if(!i.isValidNot0(q))return;let z=i.inv(q),N=t.BASE.multiply(q).toAffine(),K=i.create(N.x);if(K===it)return;let Yt=i.create(z*i.create(T+K*S));if(Yt===it)return;let Ze=(N.x===K?0:2)|Number(N.y&Lt),Ge=Yt;return w&&_(Yt)&&(Ge=i.neg(Yt),Ze^=1),new U(K,Ge,Ze)}return{seed:C,k2sig:O}}function $t(y,h,g={}){y=k("message",y);let{seed:w,k2sig:v}=I(y,h,g);return Be(e.outputLen,i.BYTES,o)(w,v)}function yt(y){let h,g=typeof y=="string"||ft(y),w=!g&&y!==null&&typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint";if(!g&&!w)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(w)h=new U(y.r,y.s);else if(g){try{h=U.fromBytes(k("sig",y),"der")}catch(v){if(!(v instanceof st.Err))throw v}if(!h)try{h=U.fromBytes(k("sig",y),"compact")}catch{return!1}}return h||!1}function H(y,h,g,w={}){let{lowS:v,prehash:B,format:E}=He(w,x);if(g=k("publicKey",g),h=vt(k("message",h),B),"strict"in w)throw new Error("options.strict was renamed to lowS");let S=E===void 0?yt(y):U.fromBytes(k("sig",y),E);if(S===!1)return!1;try{let A=t.fromBytes(g);if(v&&S.hasHighS())return!1;let{r:C,s:T}=S,O=Z(h),R=i.inv(T),q=i.create(O*R),z=i.create(C*R),N=t.BASE.multiplyUnsafe(q).add(A.multiplyUnsafe(z));return N.is0()?!1:i.create(N.x)===C}catch{return!1}}function p(y,h,g={}){let{prehash:w}=He(g,x);return h=vt(h,w),U.fromBytes(y,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:a,getPublicKey:d,getSharedSecret:b,utils:l,lengths:u,Point:t,sign:$t,verify:H,recoverPublicKey:p,Signature:U,hash:e})}function En(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp,r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=dt(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:o,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function Bn(t){let{CURVE:e,curveOpts:n}=En(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function vn(t,e){let n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,se(n.Fn.ORDER,n.Fn.BITS))})}function Sr(t){let{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:o}=Bn(t),s=mn(e,n),i=wn(s,r,o);return vn(t,i)}function Ar(t,e){let n=r=>Sr({...t,hash:r});return{...n(e),create:n}}var Ut={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Sn={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},An=BigInt(0),_r=BigInt(1),Ue=BigInt(2);function _n(t){let e=Ut.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),a=t*t*t%e,d=a*a*t%e,b=M(d,n,e)*d%e,l=M(b,n,e)*d%e,u=M(l,Ue,e)*a%e,x=M(u,o,e)*u%e,m=M(x,s,e)*x%e,_=M(m,c,e)*m%e,L=M(_,f,e)*_%e,J=M(L,c,e)*m%e,U=M(J,n,e)*d%e,Q=M(U,i,e)*x%e,Z=M(Q,r,e)*a%e,tt=M(Z,Ue,e);if(!ue.eql(ue.sqr(tt),t))throw new Error("Cannot find square root");return tt}var ue=dt(Ut.p,{sqrt:_n}),kt=Ar({...Ut,Fp:ue,lowS:!0,endo:Sn},It),Ir={};function le(t,...e){let n=Ir[t];if(n===void 0){let r=It(Ct(t));n=P(r,r),Ir[t]=n}return It(P(n,...e))}var Re=t=>t.toBytes(!0).slice(1),Rt=kt.Point,Ne=t=>t%Ue===An;function ke(t){let{Fn:e,BASE:n}=Rt,r=ht(e,t),o=n.multiply(r);return{scalar:Ne(o.y)?r:e.neg(r),bytes:Re(o)}}function Hr(t){let e=ue;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let n=e.create(t*t),r=e.create(n*t+BigInt(7)),o=e.sqrt(r);Ne(o)||(o=e.neg(o));let s=Rt.fromAffine({x:t,y:o});return s.assertValidity(),s}var zt=F;function Tr(...t){return Rt.Fn.create(zt(le("BIP0340/challenge",...t)))}function Or(t){return ke(t).bytes}function In(t,e,n=W(32)){let{Fn:r}=Rt,o=k("message",t),{bytes:s,scalar:i}=ke(e),c=k("auxRand",n,32),f=r.toBytes(i^zt(le("BIP0340/aux",c))),a=le("BIP0340/nonce",f,s,o),{bytes:d,scalar:b}=ke(a),l=Tr(d,s,o),u=new Uint8Array(64);if(u.set(d,0),u.set(r.toBytes(r.create(b+l*i)),32),!Lr(u,o,s))throw new Error("sign: Invalid signature produced");return u}function Lr(t,e,n){let{Fn:r,BASE:o}=Rt,s=k("signature",t,64),i=k("message",e),c=k("publicKey",n,32);try{let f=Hr(zt(c)),a=zt(s.subarray(0,32));if(!Ht(a,_r,Ut.p))return!1;let d=zt(s.subarray(32,64));if(!Ht(d,_r,Ut.n))return!1;let b=Tr(r.toBytes(a),Re(f),i),l=o.multiplyUnsafe(d).add(f.multiplyUnsafe(r.neg(b))),{x:u,y:x}=l.toAffine();return!(l.is0()||!Ne(x)||u!==a)}catch{return!1}}var bt=(()=>{let n=(o=W(48))=>ie(o,Ut.n);kt.utils.randomSecretKey;function r(o){let s=n(o);return{secretKey:s,publicKey:Or(s)}}return{keygen:r,getPublicKey:Or,sign:In,verify:Lr,Point:Rt,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:le,lift_x:Hr,pointToBytes:Re,numberToBytesBE:mt,bytesToNumberBE:F,mod:D},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Et=Y;var X=rt;var Ce=It;var Pr=Qr(Vr());var at=(0,Pr.default)({name:"nostr-crypto-utils",level:process.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:t=>({level:t.toUpperCase()}),log:t=>{if(t&&typeof t=="object"&&"err"in t){let e={...t};if(e.err instanceof Error){let n=e.err;e.err={message:n.message,stack:n.stack,name:n.name}}return e}return t}}});function Zn(t){try{return!!t.match(/^[A-Za-z0-9+/]*={0,2}$/)}catch{return!1}}function je(t){return Buffer.from(t).toString("base64")}function ze(t){if(!Zn(t))throw new Error("Invalid base64 string");return new Uint8Array(Buffer.from(t,"base64"))}var $n=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let t=await Promise.resolve().then(()=>(zr(),jr));if(t.webcrypto)return t.webcrypto}catch{at.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},De=class{constructor(){Wt(this,"cryptoInstance",null);Wt(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await $n()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(e){return(await this.ensureInitialized()).getRandomValues(e)}},Zt=new De,Yn=bt.sign,Wn=bt.verify;function Xn(t){return kt.getPublicKey(t,!0)}function Jn(t){return bt.getPublicKey(t)}async function Qn(){let t=W(32),e=Et(t);t.fill(0);let n=await Me(e);return{privateKey:e,publicKey:n}}async function Me(t){try{let e=X(t),n=bt.getPublicKey(e);return{hex:Et(n),bytes:n}}catch(e){throw at.error({error:e},"Failed to get public key"),e}}async function Fn(t){try{return(await Me(t.privateKey)).hex===t.publicKey.hex}catch(e){return at.error({error:e},"Failed to validate key pair"),!1}}function to(t){let e=Math.floor(Date.now()/1e3);return{...t,created_at:t.created_at||e,tags:t.tags||[],content:t.content||"",kind:t.kind||1}}async function Dr(t,e){try{let n=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),r=Ce(new TextEncoder().encode(n)),o=X(e),s=bt.sign(r,o);return{...t,id:Et(r),sig:Et(s)}}catch(n){throw at.error({error:n},"Failed to sign event"),n}}function Mr(t){let e=X(t),n=bt.getPublicKey(e);return Et(n)}async function eo(t,e){let n=t.pubkey||Mr(e),r=t.created_at||Math.floor(Date.now()/1e3),o={kind:t.kind||1,created_at:r,tags:t.tags||[],content:t.content||"",pubkey:n};return Dr(o,e)}async function ro(t){try{let e=JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content]),n=Ce(new TextEncoder().encode(e));if(Et(n)!==t.id)return at.error("Event ID mismatch"),!1;let o=X(t.sig),s=X(t.pubkey);return bt.verify(o,n,s)}catch(e){return at.error({error:e},"Failed to verify signature"),!1}}async function no(t,e,n){try{let r=typeof e=="string"?e:e.hex,o=kt.getSharedSecret(X(n),X(r)),s=o.slice(1,33),i=W(16),c=await Zt.getSubtle().then(l=>l.importKey("raw",s.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]));s.fill(0),o.fill(0);let f=new TextEncoder().encode(t),a=await Zt.getSubtle().then(l=>l.encrypt({name:"AES-CBC",iv:i},c,f.buffer)),d=je(new Uint8Array(a)),b=je(i);return d+"?iv="+b}catch(r){throw at.error({error:r},"Failed to encrypt message"),r}}async function oo(t,e,n){try{let r=typeof e=="string"?e:e.hex,o=kt.getSharedSecret(X(n),X(r)),s=o.slice(1,33),i,c;if(t.includes("?iv=")){let[d,b]=t.split("?iv=");c=ze(d),i=ze(b)}else{let d=X(t);i=d.slice(0,16),c=d.slice(16)}let f=await Zt.getSubtle().then(d=>d.importKey("raw",s.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]));s.fill(0),o.fill(0);let a=await Zt.getSubtle().then(d=>d.decrypt({name:"AES-CBC",iv:i},f,c.buffer));return new TextDecoder().decode(a)}catch(r){throw at.error({error:r},"Failed to decrypt message"),r}}return Fr(so);})();
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=crypto.nostr-crypto-utils.min.js.map