signet-verify 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/signet-verify.d.ts +112 -0
- package/dist/signet-verify.iife.js +32 -0
- package/dist/signet-verify.js +570 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 forgesworn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Signet Verify — Age Verification SDK
|
|
2
|
+
|
|
3
|
+
Add privacy-preserving age verification to any website. One script tag, one function call. No personal data collected.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script src="https://cdn.signet.forgesworn.dev/signet-verify.js"></script>
|
|
9
|
+
<script>
|
|
10
|
+
document.getElementById('verify-btn').addEventListener('click', async () => {
|
|
11
|
+
const result = await Signet.verifyAge('18+');
|
|
12
|
+
if (result.verified) {
|
|
13
|
+
// User is verified as 18+ by a confirmed professional
|
|
14
|
+
console.log('Verified! Tier:', result.tier);
|
|
15
|
+
} else {
|
|
16
|
+
console.log('Not verified:', result.error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
<button id="verify-btn">Verify your age</button>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How It Works
|
|
24
|
+
|
|
25
|
+
1. Website calls `Signet.verifyAge('18+')`
|
|
26
|
+
2. A modal appears with a QR code
|
|
27
|
+
3. User scans with their Signet app and approves
|
|
28
|
+
4. The app sends a cryptographic proof (no PII)
|
|
29
|
+
5. The SDK verifies the proof AND checks the verifier's professional registration
|
|
30
|
+
6. Returns the result — the user's app can be closed
|
|
31
|
+
|
|
32
|
+
## Verifier Trust
|
|
33
|
+
|
|
34
|
+
By default, the SDK checks the verifier's professional registration against public registers (GMC, SRA, TRA, etc.) via the Signet verification bot. This prevents fake professional rings from issuing accepted credentials.
|
|
35
|
+
|
|
36
|
+
- **Default:** `verified: true` only when the verifier is confirmed against a public register
|
|
37
|
+
- **Configurable:** websites can accept unconfirmed verifiers or point to their own verification bot
|
|
38
|
+
- **Decentralised:** the verification bot is open source — anyone can run their own
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// Default: safe — only confirmed verifiers pass
|
|
42
|
+
const result = await Signet.verifyAge('18+');
|
|
43
|
+
|
|
44
|
+
// Accept unconfirmed verifiers (less safe, more permissive)
|
|
45
|
+
const result = await Signet.verifyAge('18+', { acceptUnconfirmed: true });
|
|
46
|
+
|
|
47
|
+
// Use your own verification bot
|
|
48
|
+
const result = await Signet.verifyAge('18+', { verifierCheckUrl: 'https://my-bot.example.com' });
|
|
49
|
+
|
|
50
|
+
// Skip verifier checking entirely
|
|
51
|
+
const result = await Signet.verifyAge('18+', { verifierCheckUrl: null });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
### `Signet.verifyAge(requiredAgeRange, options?)`
|
|
57
|
+
|
|
58
|
+
Returns `Promise<SignetVerifyResult>`
|
|
59
|
+
|
|
60
|
+
**Options:**
|
|
61
|
+
|
|
62
|
+
| Option | Type | Default | Description |
|
|
63
|
+
|--------|------|---------|-------------|
|
|
64
|
+
| `relayUrl` | `string` | `wss://relay.damus.io` | Relay URL for cross-device communication |
|
|
65
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Modal colour scheme |
|
|
66
|
+
| `timeout` | `number` | `120000` | Timeout in milliseconds |
|
|
67
|
+
| `verifierCheckUrl` | `string \| null` | `'https://verify.signet.forgesworn.dev'` | Verification bot URL. Set to `null` to skip. |
|
|
68
|
+
| `acceptUnconfirmed` | `boolean` | `false` | Accept credentials from unconfirmed verifiers |
|
|
69
|
+
|
|
70
|
+
**Result:**
|
|
71
|
+
|
|
72
|
+
| Field | Type | Description |
|
|
73
|
+
|-------|------|-------------|
|
|
74
|
+
| `verified` | `boolean` | `true` if credential valid, age range met, AND verifier confirmed (or `acceptUnconfirmed` is true) |
|
|
75
|
+
| `ageRange` | `string \| null` | Age range from the credential (e.g. `'18+'`) |
|
|
76
|
+
| `tier` | `number \| null` | Verification tier (1–4) |
|
|
77
|
+
| `entityType` | `string \| null` | `'natural_person'`, `'persona'`, etc. |
|
|
78
|
+
| `verifierPubkey` | `string \| null` | Professional keypair of the issuing verifier |
|
|
79
|
+
| `verifierConfirmed` | `boolean \| null` | Whether the verifier is confirmed against a public register. `null` if check unavailable. |
|
|
80
|
+
| `verifierMethod` | `'A' \| 'B' \| 'C' \| 'D' \| null` | How the verifier was confirmed: A=NIP-05 on body domain, B=body-issued, C=cross-verified, D=website |
|
|
81
|
+
| `issuedAt` | `number \| null` | Unix timestamp of credential issuance |
|
|
82
|
+
| `expiresAt` | `number \| null` | Unix timestamp of credential expiry |
|
|
83
|
+
| `error` | `string \| undefined` | Error code (see below) |
|
|
84
|
+
|
|
85
|
+
**Error codes:**
|
|
86
|
+
|
|
87
|
+
| Error | Meaning |
|
|
88
|
+
|-------|---------|
|
|
89
|
+
| `'cancelled'` | User cancelled the verification |
|
|
90
|
+
| `'timeout'` | Verification timed out (default: 2 minutes) |
|
|
91
|
+
| `'invalid-credential'` | Credential signature failed verification |
|
|
92
|
+
| `'age-range-not-met'` | Credential age range doesn't satisfy the requirement |
|
|
93
|
+
| `'verifier-not-confirmed'` | Verifier is not confirmed against a public register |
|
|
94
|
+
| `'verifier-check-unavailable'` | Verification bot unreachable (credential valid but verifier status unknown) |
|
|
95
|
+
|
|
96
|
+
## Age Range Values
|
|
97
|
+
|
|
98
|
+
| Value | Meaning |
|
|
99
|
+
|-------|---------|
|
|
100
|
+
| `'0-3'` | Ages 0–3 |
|
|
101
|
+
| `'4-7'` | Ages 4–7 |
|
|
102
|
+
| `'8-12'` | Ages 8–12 |
|
|
103
|
+
| `'13-17'` | Ages 13–17 |
|
|
104
|
+
| `'18+'` | Adult (18 and over) |
|
|
105
|
+
|
|
106
|
+
## Privacy
|
|
107
|
+
|
|
108
|
+
- No personal data is transmitted — only a cryptographic proof of age range
|
|
109
|
+
- No account creation required on the website
|
|
110
|
+
- No cookies beyond session management
|
|
111
|
+
- The proof is verified entirely in the browser — no server-side API calls needed
|
|
112
|
+
- Verifier check is a single GET request returning confirmed/not — no user data sent
|
|
113
|
+
- Compliant with GDPR, COPPA, UK Online Safety Act, France SREN law
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signet Verify SDK — website age verification and cross-device Sign-in-with-Signet.
|
|
3
|
+
*
|
|
4
|
+
* ESM / bundler usage (npm):
|
|
5
|
+
* import { verifyAge, waitForAuthResponse } from 'signet-verify';
|
|
6
|
+
*
|
|
7
|
+
* Script-tag / CDN usage (IIFE bundle exposes `window.Signet`):
|
|
8
|
+
* <script src="https://cdn.signet.forgesworn.dev/signet-verify.iife.js"></script>
|
|
9
|
+
* <script>
|
|
10
|
+
* const result = await Signet.verifyAge('18+');
|
|
11
|
+
* if (result.verified) { // allow access }
|
|
12
|
+
* </script>
|
|
13
|
+
*/
|
|
14
|
+
export interface SignetVerifyResult {
|
|
15
|
+
verified: boolean;
|
|
16
|
+
ageRange: string | null;
|
|
17
|
+
tier: number | null;
|
|
18
|
+
entityType: string | null;
|
|
19
|
+
credentialId: string | null;
|
|
20
|
+
verifierPubkey: string | null;
|
|
21
|
+
/** Whether the verifier is confirmed against a public professional register */
|
|
22
|
+
verifierConfirmed: boolean | null;
|
|
23
|
+
/** Verifier's confirmation method: A (NIP-05 on body domain), B (body-issued), C (cross-verified), D (website), null if unknown */
|
|
24
|
+
verifierMethod: 'A' | 'B' | 'C' | 'D' | null;
|
|
25
|
+
issuedAt: number | null;
|
|
26
|
+
expiresAt: number | null;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SignetVerifyOptions {
|
|
30
|
+
/** Required age range to verify (e.g., '18+', '13-17') */
|
|
31
|
+
requiredAgeRange: string;
|
|
32
|
+
/** Relay URL for cross-device communication */
|
|
33
|
+
relayUrl?: string;
|
|
34
|
+
/** Callback URL for same-device flow */
|
|
35
|
+
callbackUrl?: string;
|
|
36
|
+
/** Custom styling for the verification modal */
|
|
37
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
38
|
+
/** Timeout in milliseconds (default: 120000 — 2 minutes) */
|
|
39
|
+
timeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* URL of the verification bot that checks verifier credentials against public registers.
|
|
42
|
+
* Default: 'https://verify.signet.forgesworn.dev'
|
|
43
|
+
* Set to null to skip verifier checking (accept any signed credential).
|
|
44
|
+
* Anyone can run their own bot — the URL is configurable, not a central authority.
|
|
45
|
+
*/
|
|
46
|
+
verifierCheckUrl?: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Accept credentials from unconfirmed verifiers.
|
|
49
|
+
* Default: false (safe — only confirmed verifiers pass).
|
|
50
|
+
* Set to true to accept any valid credential regardless of verifier status.
|
|
51
|
+
*/
|
|
52
|
+
acceptUnconfirmed?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Main verification function.
|
|
56
|
+
* Shows a modal with QR code, waits for the user's app to respond.
|
|
57
|
+
*/
|
|
58
|
+
export declare function verifyAge(requiredAgeRange: string, options?: Partial<SignetVerifyOptions>): Promise<SignetVerifyResult>;
|
|
59
|
+
/** Options for waiting on a cross-device Sign-in-with-Signet response. */
|
|
60
|
+
export interface WaitForAuthOptions {
|
|
61
|
+
/** The challenge (also the `requestId`) sent in the auth URL. 64-char hex. */
|
|
62
|
+
requestId: string;
|
|
63
|
+
/** The `wss://` relay URL the consumer subscribed on. */
|
|
64
|
+
relayUrl: string;
|
|
65
|
+
/** The consumer's ephemeral session private key (32 bytes). Used to NIP-17 unwrap the response. */
|
|
66
|
+
sessionPrivKey: Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* The consumer origin (e.g. `https://example.com`). The signed auth event must
|
|
69
|
+
* carry a matching `origin` tag — this prevents a response addressed to a different
|
|
70
|
+
* site from being accepted. Must be supplied verbatim (scheme + host + optional port).
|
|
71
|
+
*/
|
|
72
|
+
expectedOrigin: string;
|
|
73
|
+
/** Timeout in milliseconds. Clamped to [5_000, 600_000]. Default 120_000. */
|
|
74
|
+
timeout?: number;
|
|
75
|
+
}
|
|
76
|
+
/** Full signed Kind-21236 auth event as carried in the AuthResponse. */
|
|
77
|
+
export interface SignetAuthEvent {
|
|
78
|
+
id: string;
|
|
79
|
+
pubkey: string;
|
|
80
|
+
kind: 21236;
|
|
81
|
+
created_at: number;
|
|
82
|
+
tags: string[][];
|
|
83
|
+
content: string;
|
|
84
|
+
sig: string;
|
|
85
|
+
}
|
|
86
|
+
/** Successful auth response — the user's signed proof of login. */
|
|
87
|
+
export interface SignetAuthResult {
|
|
88
|
+
/** The user's pubkey (64-char hex x-only) — copy of `authEvent.pubkey` for convenience. */
|
|
89
|
+
pubkey: string;
|
|
90
|
+
/** The verified, signed Kind-21236 auth event — the raw cryptographic proof. */
|
|
91
|
+
authEvent: SignetAuthEvent;
|
|
92
|
+
/** Optional credential included in the response (Signet Login flows). */
|
|
93
|
+
credential?: unknown;
|
|
94
|
+
/** Unix timestamp the auth event was signed. */
|
|
95
|
+
createdAt: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Wait for a cross-device Sign-in-with-Signet response on a Nostr relay.
|
|
99
|
+
*
|
|
100
|
+
* Consumer workflow: generate a session keypair, put the pubkey in the auth URL
|
|
101
|
+
* via the `sessionPubkey` param alongside `relay`, render the QR, then call this
|
|
102
|
+
* function with the matching private key. When the user approves on their phone,
|
|
103
|
+
* the Signet app publishes a NIP-17 gift-wrapped response to the relay and this
|
|
104
|
+
* function resolves with the verified auth result.
|
|
105
|
+
*
|
|
106
|
+
* Rejects with `Error(message)` where message is one of:
|
|
107
|
+
* - `'denied'` — user rejected the request
|
|
108
|
+
* - `'timeout'` — no valid response within the timeout
|
|
109
|
+
* - `'relay-error'` — WebSocket connection failure
|
|
110
|
+
* - `'invalid-request-id'` / `'invalid-session-privkey'` / `'invalid-relay-url'` — bad input
|
|
111
|
+
*/
|
|
112
|
+
export declare function waitForAuthResponse(options: WaitForAuthOptions): Promise<SignetAuthResult>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";var Signet=(()=>{var Le=Object.defineProperty;var Fo=Object.getOwnPropertyDescriptor;var ts=Object.getOwnPropertyNames;var es=Object.prototype.hasOwnProperty;var ns=(e,t,r)=>t in e?Le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var rs=(e,t)=>{for(var r in t)Le(e,r,{get:t[r],enumerable:!0})},os=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ts(t))!es.call(e,o)&&o!==r&&Le(e,o,{get:()=>t[o],enumerable:!(n=Fo(t,o))||n.enumerable});return e};var ss=e=>os(Le({},"__esModule",{value:!0}),e);var T=(e,t,r)=>ns(e,typeof t!="symbol"?t+"":t,r);var ki={};rs(ki,{verifyAge:()=>Jo,waitForAuthResponse:()=>Qo});var qt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ue(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function lt(e,...t){if(!Ct(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 _e(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ue(e.outputLen),ue(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 ar(e,t){lt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Re(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function dt(e,t){return e<<32-t|e>>>t}var ur=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",is=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function st(e){if(lt(e),ur)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=is[e[r]];return t}var gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function fr(e){if(e>=gt._0&&e<=gt._9)return e-gt._0;if(e>=gt.A&&e<=gt.F)return e-(gt.A-10);if(e>=gt.a&&e<=gt.f)return e-(gt.a-10)}function Dt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ur)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=fr(e.charCodeAt(s)),c=fr(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 Ue(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function le(e){return typeof e=="string"&&(e=Ue(e)),lt(e),e}function ot(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];lt(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 zt=class{};function lr(e){let t=n=>e().update(le(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Mt(e=32){if(qt&&typeof qt.getRandomValues=="function")return qt.getRandomValues(new Uint8Array(e));if(qt&&typeof qt.randomBytes=="function")return Uint8Array.from(qt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function cs(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,u=n?0:4;e.setUint32(t+f,i,n),e.setUint32(t+u,c,n)}function dr(e,t,r){return e&t^~e&r}function hr(e,t,r){return e&t^e&r^t&r}var Oe=class extends zt{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=Re(this.buffer)}update(t){Yt(this),t=le(t),lt(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=Re(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),ar(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let g=i;g<o;g++)r[g]=0;cs(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Re(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=f/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<u;g++)c.setUint32(4*g,h[g],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()}},xt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var fs=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]),_t=new Uint32Array(64),He=class extends Oe{constructor(t=32){super(64,t,8,!1),this.A=xt[0]|0,this.B=xt[1]|0,this.C=xt[2]|0,this.D=xt[3]|0,this.E=xt[4]|0,this.F=xt[5]|0,this.G=xt[6]|0,this.H=xt[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 g=0;g<16;g++,r+=4)_t[g]=t.getUint32(r,!1);for(let g=16;g<64;g++){let b=_t[g-15],d=_t[g-2],w=dt(b,7)^dt(b,18)^b>>>3,B=dt(d,17)^dt(d,19)^d>>>10;_t[g]=B+_t[g-7]+w+_t[g-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:u,H:h}=this;for(let g=0;g<64;g++){let b=dt(c,6)^dt(c,11)^dt(c,25),d=h+b+dr(c,f,u)+fs[g]+_t[g]|0,B=(dt(n,2)^dt(n,13)^dt(n,22))+hr(n,o,s)|0;h=u,u=f,f=c,c=i+d|0,i=s,s=o,o=n,n=d+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,u=u+this.G|0,h=h+this.H|0,this.set(n,o,s,i,c,f,u,h)}roundClean(){Vt(_t)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}};var Wt=lr(()=>new He);var ke=class extends zt{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,_e(t);let n=le(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),Vt(s)}update(t){return Yt(this),this.iHash.update(t),this}digestInto(t){Yt(this),lt(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()}},on=(e,t,r)=>new ke(e,t).update(r).digest();on.create=(e,t)=>new ke(e,t);var fn=BigInt(0),cn=BigInt(1);function de(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Rt(e,t,r=""){let n=Ct(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 he(e){let t=e.toString(16);return t.length&1?"0"+t:t}function br(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?fn:BigInt("0x"+e)}function pt(e){return br(st(e))}function an(e){return lt(e),br(st(Uint8Array.from(e).reverse()))}function Xt(e,t){return Dt(e.toString(16).padStart(t*2,"0"))}function un(e,t){return Xt(e,t).reverse()}function X(e,t,r){let n;if(typeof t=="string")try{n=Dt(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ct(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 sn=e=>typeof e=="bigint"&&fn<=e;function be(e,t,r){return sn(e)&&sn(t)&&sn(r)&&t<=e&&e<r}function gr(e,t,r,n){if(!be(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Te(e){let t;for(t=0;e>fn;e>>=cn,t+=1);return t}var Ut=e=>(cn<<BigInt(e))-cn;function xr(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=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(e),i=n(e),c=0,f=()=>{s.fill(1),i.fill(0),c=0},u=(...d)=>r(i,s,...d),h=(d=n(0))=>{i=u(o(0),d),s=u(),d.length!==0&&(i=u(o(1),d),s=u())},g=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,w=[];for(;d<t;){s=u();let B=s.slice();w.push(B),d+=s.length}return ot(...w)};return(d,w)=>{f(),h(d);let B;for(;!(B=w(g()));)h();return f(),B}}function ge(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 ln(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 nt=BigInt(0),tt=BigInt(1),Zt=BigInt(2),wr=BigInt(3),mr=BigInt(4),Er=BigInt(5),as=BigInt(7),Br=BigInt(8),us=BigInt(9),vr=BigInt(16);function it(e,t){let r=e%t;return r>=nt?r:t+r}function ct(e,t,r){let n=e;for(;t-- >nt;)n*=n,n%=r;return n}function pr(e,t){if(e===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let r=it(e,t),n=t,o=nt,s=tt,i=tt,c=nt;for(;r!==nt;){let u=n/r,h=n%r,g=o-i*u,b=s-c*u;n=r,r=h,o=i,s=c,i=g,c=b}if(n!==tt)throw new Error("invert: does not exist");return it(o,t)}function dn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ar(e,t){let r=(e.ORDER+tt)/mr,n=e.pow(t,r);return dn(e,n,t),n}function ls(e,t){let r=(e.ORDER-Er)/Br,n=e.mul(t,Zt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Zt),o),c=e.mul(s,e.sub(i,e.ONE));return dn(e,c,t),c}function ds(e){let t=Ot(e),r=Sr(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+as)/vr;return(c,f)=>{let u=c.pow(f,i),h=c.mul(u,n),g=c.mul(u,o),b=c.mul(u,s),d=c.eql(c.sqr(h),f),w=c.eql(c.sqr(g),f);u=c.cmov(u,h,d),h=c.cmov(b,g,w);let B=c.eql(c.sqr(h),f),S=c.cmov(u,h,B);return dn(c,S,f),S}}function Sr(e){if(e<wr)throw new Error("sqrt is not defined for small field");let t=e-tt,r=0;for(;t%Zt===nt;)t/=Zt,r++;let n=Zt,o=Ot(e);for(;yr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ar;let s=o.pow(n,t),i=(t+tt)/Zt;return function(f,u){if(f.is0(u))return u;if(yr(f,u)!==1)throw new Error("Cannot find square root");let h=r,g=f.mul(f.ONE,s),b=f.pow(u,t),d=f.pow(u,i);for(;!f.eql(b,f.ONE);){if(f.is0(b))return f.ZERO;let w=1,B=f.sqr(b);for(;!f.eql(B,f.ONE);)if(w++,B=f.sqr(B),w===h)throw new Error("Cannot find square root");let S=tt<<BigInt(h-w-1),_=f.pow(g,S);h=w,g=f.sqr(_),b=f.mul(b,g),d=f.mul(d,_)}return d}}function hs(e){return e%mr===wr?Ar:e%Br===Er?ls:e%vr===us?ds(e):Sr(e)}var bs=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=bs.reduce((n,o)=>(n[o]="function",n),t);return ge(e,r),e}function gs(e,t,r){if(r<nt)throw new Error("invalid exponent, negatives unsupported");if(r===nt)return e.ONE;if(r===tt)return t;let n=e.ONE,o=t;for(;r>nt;)r&tt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=tt;return n}function Ne(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 yr(e,t){let r=(e.ORDER-tt)/Zt,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 qe(e,t){t!==void 0&&ue(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<=nt)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 b=t;b.BITS&&(o=b.BITS),b.sqrt&&(s=b.sqrt),typeof b.isLE=="boolean"&&(r=b.isLE),typeof b.modFromBytes=="boolean"&&(i=b.modFromBytes),c=b.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:f,nByteLength:u}=qe(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let h,g=Object.freeze({ORDER:e,isLE:r,BITS:f,BYTES:u,MASK:Ut(f),ZERO:nt,ONE:tt,allowedLengths:c,create:b=>it(b,e),isValid:b=>{if(typeof b!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof b);return nt<=b&&b<e},is0:b=>b===nt,isValidNot0:b=>!g.is0(b)&&g.isValid(b),isOdd:b=>(b&tt)===tt,neg:b=>it(-b,e),eql:(b,d)=>b===d,sqr:b=>it(b*b,e),add:(b,d)=>it(b+d,e),sub:(b,d)=>it(b-d,e),mul:(b,d)=>it(b*d,e),pow:(b,d)=>gs(g,b,d),div:(b,d)=>it(b*pr(d,e),e),sqrN:b=>b*b,addN:(b,d)=>b+d,subN:(b,d)=>b-d,mulN:(b,d)=>b*d,inv:b=>pr(b,e),sqrt:s||(b=>(h||(h=hs(e)),h(g,b))),toBytes:b=>r?un(b,u):Xt(b,u),fromBytes:(b,d=!0)=>{if(c){if(!c.includes(b.length)||b.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+b.length);let B=new Uint8Array(u);B.set(b,r?0:B.length-b.length),b=B}if(b.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+b.length);let w=r?an(b):pt(b);if(i&&(w=it(w,e)),!d&&!g.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:b=>Ne(g,b),cmov:(b,d,w)=>w?d:b});return Object.freeze(g)}function Ir(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 bn(e){let t=Ir(e);return t+Math.ceil(t/2)}function Ce(e,t,r=!1){let n=e.length,o=Ir(t),s=bn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?an(e):pt(e),c=it(i,t-tt)+tt;return r?un(c,o):Xt(c,o)}var Jt=BigInt(0),jt=BigInt(1);function xe(e,t){let r=t.negate();return e?r:t}function De(e,t){let r=Ne(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ur(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function gn(e,t){Ur(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ut(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Lr(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+=jt);let u=t*n,h=u+Math.abs(c)-1,g=c===0,b=c<0,d=t%2!==0;return{nextN:f,offset:h,isZero:g,isNeg:b,isNegF:d,offsetF:u}}function xs(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 ps(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 xn=new WeakMap,Or=new WeakMap;function pn(e){return Or.get(e)||1}function _r(e){if(e!==Jt)throw new Error("invalid wNAF")}var Ve=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>Jt;)r&jt&&(n=n.add(o)),o=o.double(),r>>=jt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=gn(r,this.bits),s=[],i=t,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let u=1;u<o;u++)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=gn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:u,isZero:h,isNeg:g,isNegF:b,offsetF:d}=Lr(n,c,i);n=f,h?s=s.add(xe(b,r[d])):o=o.add(xe(g,r[u]))}return _r(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=gn(t,this.bits);for(let i=0;i<s.windows&&n!==Jt;i++){let{nextN:c,offset:f,isZero:u,isNeg:h}=Lr(n,i,s);if(n=c,!u){let g=r[f];o=o.add(h?g.negate():g)}}return _r(n),o}getPrecomputes(t,r,n){let o=xn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),xn.set(r,o))),o}cached(t,r,n){let o=pn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=pn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ur(r,this.bits),Or.set(t,r),xn.delete(t)}hasCache(t){return pn(t)!==1}};function Hr(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Jt||n>Jt;)r&jt&&(s=s.add(o)),n&jt&&(i=i.add(o)),o=o.double(),r>>=jt,n>>=jt;return{p1:s,p2:i}}function kr(e,t,r,n){xs(r,e),ps(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=Te(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let u=Ut(f),h=new Array(Number(u)+1).fill(i),g=Math.floor((t.BITS-1)/f)*f,b=i;for(let d=g;d>=0;d-=f){h.fill(i);for(let B=0;B<s;B++){let S=n[B],_=Number(S>>BigInt(d)&u);h[_]=h[_].add(r[B])}let w=i;for(let B=h.length-1,S=i;B>0;B--)S=S.add(h[B]),w=w.add(S);if(b=b.add(w),d!==0)for(let B=0;B<f;B++)b=b.double()}return b}function Rr(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hn(t),t}else return Ot(e,{isLE:r})}function Tr(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 u=t[f];if(!(typeof u=="bigint"&&u>Jt))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Rr(t.p,r.Fp,n),s=Rr(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 Nr=(e,t)=>(e+(e>=0?t:-t)/qr)/t;function ys(e,t,r){let[[n,o],[s,i]]=t,c=Nr(i*e,r),f=Nr(-o*e,r),u=e-c*n-f*s,h=-c*o-f*i,g=u<wt,b=h<wt;g&&(u=-u),b&&(h=-h);let d=Ut(Math.ceil(Te(r)/2))+Qt;if(u<wt||u>=d||h<wt||h>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:g,k1:u,k2neg:b,k2:h}}function wn(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function yn(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return de(r.lowS,"lowS"),de(r.prehash,"prehash"),r.format!==void 0&&wn(r.format),r}var mn=class extends Error{constructor(t=""){super(t)}},yt={Err:mn,_tlv:{encode:(e,t)=>{let{Err:r}=yt;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=he(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?he(o.length/2|128):"";return he(e)+s+o+t},decode(e,t){let{Err:r}=yt,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 u=t.subarray(n,n+f);if(u.length!==f)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of u)i=i<<8|h;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}=yt;if(e<wt)throw new t("integer: negative integers are not allowed");let r=he(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}=yt;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 pt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=yt,o=X("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:u,l:h}=n.decode(2,f);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=yt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},wt=BigInt(0),Qt=BigInt(1),qr=BigInt(2),Me=BigInt(3),ws=BigInt(4);function Ht(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=X("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 ms(e,t={}){let r=Tr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ge(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 u=Vr(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function g(L,p,l){let{x:a,y:x}=p.toAffine(),m=n.toBytes(a);if(de(l,"isCompressed"),l){h();let v=!n.isOdd(x);return ot(Cr(v),m)}else return ot(Uint8Array.of(4),m,n.toBytes(x))}function b(L){Rt(L,void 0,"Point");let{publicKey:p,publicKeyUncompressed:l}=u,a=L.length,x=L[0],m=L.subarray(1);if(a===p&&(x===2||x===3)){let v=n.fromBytes(m);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let y=B(v),A;try{A=n.sqrt(y)}catch(O){let D=O instanceof Error?": "+O.message:"";throw new Error("bad point: is not on curve, sqrt error"+D)}h();let E=n.isOdd(A);return(x&1)===1!==E&&(A=n.neg(A)),{x:v,y:A}}else if(a===l&&x===4){let v=n.BYTES,y=n.fromBytes(m.subarray(0,v)),A=n.fromBytes(m.subarray(v,v*2));if(!S(y,A))throw new Error("bad point: is not on curve");return{x:y,y:A}}else throw new Error(`bad point: got length ${a}, expected compressed=${p} or uncompressed=${l}`)}let d=t.toBytes||g,w=t.fromBytes||b;function B(L){let p=n.sqr(L),l=n.mul(p,L);return n.add(n.add(l,n.mul(L,s.a)),s.b)}function S(L,p){let l=n.sqr(p),a=B(L);return n.eql(l,a)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,Me),ws),V=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,V)))throw new Error("bad curve params: a or b");function N(L,p,l=!1){if(!n.isValid(p)||l&&n.is0(p))throw new Error(`bad point coordinate ${L}`);return p}function q(L){if(!(L instanceof R))throw new Error("ProjectivePoint expected")}function C(L){if(!f||!f.basises)throw new Error("no endo");return ys(L,f.basises,o.ORDER)}let P=ln((L,p)=>{let{X:l,Y:a,Z:x}=L;if(n.eql(x,n.ONE))return{x:l,y:a};let m=L.is0();p==null&&(p=m?n.ONE:n.inv(x));let v=n.mul(l,p),y=n.mul(a,p),A=n.mul(x,p);if(m)return{x:n.ZERO,y:n.ZERO};if(!n.eql(A,n.ONE))throw new Error("invZ was invalid");return{x:v,y}}),Y=ln(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x:p,y:l}=L.toAffine();if(!n.isValid(p)||!n.isValid(l))throw new Error("bad point: x or y not field elements");if(!S(p,l))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function z(L,p,l,a,x){return l=new R(n.mul(l.X,L),l.Y,l.Z),p=xe(a,p),l=xe(x,l),p.add(l)}class R{constructor(p,l,a){this.X=N("x",p),this.Y=N("y",l,!0),this.Z=N("z",a),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:l,y:a}=p||{};if(!p||!n.isValid(l)||!n.isValid(a))throw new Error("invalid affine point");if(p instanceof R)throw new Error("projective point not allowed");return n.is0(l)&&n.is0(a)?R.ZERO:new R(l,a,n.ONE)}static fromBytes(p){let l=R.fromAffine(w(Rt(p,void 0,"point")));return l.assertValidity(),l}static fromHex(p){return R.fromBytes(X("pointHex",p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,l=!0){return M.createCache(this,p),l||this.multiply(Me),this}assertValidity(){Y(this)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){q(p);let{X:l,Y:a,Z:x}=this,{X:m,Y:v,Z:y}=p,A=n.eql(n.mul(l,y),n.mul(m,x)),E=n.eql(n.mul(a,y),n.mul(v,x));return A&&E}negate(){return new R(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:l}=s,a=n.mul(l,Me),{X:x,Y:m,Z:v}=this,y=n.ZERO,A=n.ZERO,E=n.ZERO,I=n.mul(x,x),O=n.mul(m,m),D=n.mul(v,v),k=n.mul(x,m);return k=n.add(k,k),E=n.mul(x,v),E=n.add(E,E),y=n.mul(p,E),A=n.mul(a,D),A=n.add(y,A),y=n.sub(O,A),A=n.add(O,A),A=n.mul(y,A),y=n.mul(k,y),E=n.mul(a,E),D=n.mul(p,D),k=n.sub(I,D),k=n.mul(p,k),k=n.add(k,E),E=n.add(I,I),I=n.add(E,I),I=n.add(I,D),I=n.mul(I,k),A=n.add(A,I),D=n.mul(m,v),D=n.add(D,D),I=n.mul(D,k),y=n.sub(y,I),E=n.mul(D,O),E=n.add(E,E),E=n.add(E,E),new R(y,A,E)}add(p){q(p);let{X:l,Y:a,Z:x}=this,{X:m,Y:v,Z:y}=p,A=n.ZERO,E=n.ZERO,I=n.ZERO,O=s.a,D=n.mul(s.b,Me),k=n.mul(l,m),U=n.mul(a,v),Z=n.mul(x,y),G=n.add(l,a),j=n.add(m,v);G=n.mul(G,j),j=n.add(k,U),G=n.sub(G,j),j=n.add(l,x);let $=n.add(m,y);return j=n.mul(j,$),$=n.add(k,Z),j=n.sub(j,$),$=n.add(a,x),A=n.add(v,y),$=n.mul($,A),A=n.add(U,Z),$=n.sub($,A),I=n.mul(O,j),A=n.mul(D,Z),I=n.add(A,I),A=n.sub(U,I),I=n.add(U,I),E=n.mul(A,I),U=n.add(k,k),U=n.add(U,k),Z=n.mul(O,Z),j=n.mul(D,j),U=n.add(U,Z),Z=n.sub(k,Z),Z=n.mul(O,Z),j=n.add(j,Z),k=n.mul(U,j),E=n.add(E,k),k=n.mul($,j),A=n.mul(G,A),A=n.sub(A,k),k=n.mul(G,U),I=n.mul($,I),I=n.add(I,k),new R(A,E,I)}subtract(p){return this.add(p.negate())}is0(){return this.equals(R.ZERO)}multiply(p){let{endo:l}=t;if(!o.isValidNot0(p))throw new Error("invalid scalar: out of range");let a,x,m=v=>M.cached(this,v,y=>De(R,y));if(l){let{k1neg:v,k1:y,k2neg:A,k2:E}=C(p),{p:I,f:O}=m(y),{p:D,f:k}=m(E);x=O.add(k),a=z(l.beta,I,D,v,A)}else{let{p:v,f:y}=m(p);a=v,x=y}return De(R,[a,x])[0]}multiplyUnsafe(p){let{endo:l}=t,a=this;if(!o.isValid(p))throw new Error("invalid scalar: out of range");if(p===wt||a.is0())return R.ZERO;if(p===Qt)return a;if(M.hasCache(this))return this.multiply(p);if(l){let{k1neg:x,k1:m,k2neg:v,k2:y}=C(p),{p1:A,p2:E}=Hr(R,a,m,y);return z(l.beta,A,E,x,v)}else return M.unsafe(a,p)}multiplyAndAddUnsafe(p,l,a){let x=this.multiplyUnsafe(l).add(p.multiplyUnsafe(a));return x.is0()?void 0:x}toAffine(p){return P(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return i===Qt?!0:p?p(R,this):M.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===Qt?this:p?p(R,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(p=!0){return de(p,"isCompressed"),this.assertValidity(),d(R,this,p)}toHex(p=!0){return st(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 De(R,p)}static msm(p,l){return kr(R,o,p,l)}static fromPrivateKey(p){return R.BASE.multiply(Ht(o,p))}}R.BASE=new R(s.Gx,s.Gy,n.ONE),R.ZERO=new R(n.ZERO,n.ONE,n.ZERO),R.Fp=n,R.Fn=o;let K=o.BITS,M=new Ve(R,t.endo?Math.ceil(K/2):K);return R.BASE.precompute(8),R}function Cr(e){return Uint8Array.of(e?2:3)}function Vr(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Es(e,t={}){let{Fn:r}=e,n=t.randomBytes||Mt,o=Object.assign(Vr(e.Fp,r),{seed:bn(r.ORDER)});function s(d){try{return!!Ht(r,d)}catch{return!1}}function i(d,w){let{publicKey:B,publicKeyUncompressed:S}=o;try{let _=d.length;return w===!0&&_!==B||w===!1&&_!==S?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Ce(Rt(d,o.seed,"seed"),r.ORDER)}function f(d,w=!0){return e.BASE.multiply(Ht(r,d)).toBytes(w)}function u(d){let w=c(d);return{secretKey:w,publicKey:f(w)}}function h(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:w,publicKey:B,publicKeyUncompressed:S}=o;if(r.allowedLengths||w===B)return;let _=X("key",d).length;return _===B||_===S}function g(d,w,B=!0){if(h(d)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");let S=Ht(r,d);return e.fromHex(w).multiply(S).toBytes(B)}return Object.freeze({getPublicKey:f,getSharedSecret:g,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Ht(r,d),precompute(d=8,w=e.BASE){return w.precompute(d,!1)}},lengths:o})}function Bs(e,t,r={}){_e(t),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||Mt,o=r.hmac||((l,...a)=>on(t,l,ot(...a))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:f}=i,{keygen:u,getPublicKey:h,getSharedSecret:g,utils:b,lengths:d}=Es(e,r),w={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},B="compact";function S(l){let a=c>>Qt;return l>a}function _(l,a){if(!i.isValidNot0(a))throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);return a}function V(l,a){wn(a);let x=d.signature,m=a==="compact"?x:a==="recovered"?x+1:void 0;return Rt(l,m,`${a} signature`)}class N{constructor(a,x,m){this.r=_("r",a),this.s=_("s",x),m!=null&&(this.recovery=m),Object.freeze(this)}static fromBytes(a,x=B){V(a,x);let m;if(x==="der"){let{r:E,s:I}=yt.toSig(Rt(a));return new N(E,I)}x==="recovered"&&(m=a[0],x="compact",a=a.subarray(1));let v=i.BYTES,y=a.subarray(0,v),A=a.subarray(v,v*2);return new N(i.fromBytes(y),i.fromBytes(A),m)}static fromHex(a,x){return this.fromBytes(Dt(a),x)}addRecoveryBit(a){return new N(this.r,this.s,a)}recoverPublicKey(a){let x=s.ORDER,{r:m,s:v,recovery:y}=this;if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");if(c*qr<x&&y>1)throw new Error("recovery id is ambiguous for h>1 curve");let E=y===2||y===3?m+c:m;if(!s.isValid(E))throw new Error("recovery id 2 or 3 invalid");let I=s.toBytes(E),O=e.fromBytes(ot(Cr((y&1)===0),I)),D=i.inv(E),k=C(X("msgHash",a)),U=i.create(-k*D),Z=i.create(v*D),G=e.BASE.multiplyUnsafe(U).add(O.multiplyUnsafe(Z));if(G.is0())throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return S(this.s)}toBytes(a=B){if(wn(a),a==="der")return Dt(yt.hexFromSig(this));let x=i.toBytes(this.r),m=i.toBytes(this.s);if(a==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ot(Uint8Array.of(this.recovery),x,m)}return ot(x,m)}toHex(a){return st(this.toBytes(a))}assertValidity(){}static fromCompact(a){return N.fromBytes(X("sig",a),"compact")}static fromDER(a){return N.fromBytes(X("sig",a),"der")}normalizeS(){return this.hasHighS()?new N(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return st(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return st(this.toBytes("compact"))}}let q=r.bits2int||function(a){if(a.length>8192)throw new Error("input is too large");let x=pt(a),m=a.length*8-f;return m>0?x>>BigInt(m):x},C=r.bits2int_modN||function(a){return i.create(q(a))},P=Ut(f);function Y(l){return gr("num < 2^"+f,l,wt,P),i.toBytes(l)}function z(l,a){return Rt(l,void 0,"message"),a?Rt(t(l),void 0,"prehashed message"):l}function R(l,a,x){if(["recovered","canonical"].some(U=>U in x))throw new Error("sign() legacy options not supported");let{lowS:m,prehash:v,extraEntropy:y}=yn(x,w);l=z(l,v);let A=C(l),E=Ht(i,a),I=[Y(E),Y(A)];if(y!=null&&y!==!1){let U=y===!0?n(d.secretKey):y;I.push(X("extraEntropy",U))}let O=ot(...I),D=A;function k(U){let Z=q(U);if(!i.isValidNot0(Z))return;let G=i.inv(Z),j=e.BASE.multiply(Z).toAffine(),$=i.create(j.x);if($===wt)return;let J=i.create(G*i.create(D+$*E));if(J===wt)return;let fe=(j.x===$?0:2)|Number(j.y&Qt),ae=J;return m&&S(J)&&(ae=i.neg(J),fe^=1),new N($,ae,fe)}return{seed:O,k2sig:k}}function K(l,a,x={}){l=X("message",l);let{seed:m,k2sig:v}=R(l,a,x);return xr(t.outputLen,i.BYTES,o)(m,v)}function M(l){let a,x=typeof l=="string"||Ct(l),m=!x&&l!==null&&typeof l=="object"&&typeof l.r=="bigint"&&typeof l.s=="bigint";if(!x&&!m)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(m)a=new N(l.r,l.s);else if(x){try{a=N.fromBytes(X("sig",l),"der")}catch(v){if(!(v instanceof yt.Err))throw v}if(!a)try{a=N.fromBytes(X("sig",l),"compact")}catch{return!1}}return a||!1}function L(l,a,x,m={}){let{lowS:v,prehash:y,format:A}=yn(m,w);if(x=X("publicKey",x),a=z(X("message",a),y),"strict"in m)throw new Error("options.strict was renamed to lowS");let E=A===void 0?M(l):N.fromBytes(X("sig",l),A);if(E===!1)return!1;try{let I=e.fromBytes(x);if(v&&E.hasHighS())return!1;let{r:O,s:D}=E,k=C(a),U=i.inv(D),Z=i.create(k*U),G=i.create(O*U),j=e.BASE.multiplyUnsafe(Z).add(I.multiplyUnsafe(G));return j.is0()?!1:i.create(j.x)===O}catch{return!1}}function p(l,a,x={}){let{prehash:m}=yn(x,w);return a=z(a,m),N.fromBytes(l,"recovered").recoverPublicKey(a).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:g,utils:b,lengths:d,Point:e,sign:K,verify:L,recoverPublicKey:p,Signature:N,hash:t})}function vs(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 As(e){let{CURVE:t,curveOpts:r}=vs(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 Ss(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,qe(r.Fn.ORDER,r.Fn.BITS))})}function Dr(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=As(e),s=ms(t,r),i=Bs(s,n,o);return Ss(e,i)}function Mr(e,t){let r=n=>Dr({...e,hash:n});return{...r(t),create:r}}var Ft={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Is={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ls=BigInt(0),Zr=BigInt(1),En=BigInt(2);function _s(e){let t=Ft.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),u=e*e*e%t,h=u*u*e%t,g=ct(h,r,t)*h%t,b=ct(g,r,t)*h%t,d=ct(b,En,t)*u%t,w=ct(d,o,t)*d%t,B=ct(w,s,t)*w%t,S=ct(B,c,t)*B%t,_=ct(S,f,t)*S%t,V=ct(_,c,t)*B%t,N=ct(V,r,t)*h%t,q=ct(N,i,t)*w%t,C=ct(q,n,t)*u%t,P=ct(C,En,t);if(!Ze.eql(Ze.sqr(P),e))throw new Error("Cannot find square root");return P}var Ze=Ot(Ft.p,{sqrt:_s}),$r=Mr({...Ft,Fp:Ze,lowS:!0,endo:Is},Wt),jr={};function je(e,...t){let r=jr[e];if(r===void 0){let n=Wt(Ue(e));r=ot(n,n),jr[e]=r}return Wt(ot(r,...t))}var vn=e=>e.toBytes(!0).slice(1),te=$r.Point,An=e=>e%En===Ls;function Bn(e){let{Fn:t,BASE:r}=te,n=Ht(t,e),o=r.multiply(n);return{scalar:An(o.y)?n:t.neg(n),bytes:vn(o)}}function Pr(e){let t=Ze;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);An(o)||(o=t.neg(o));let s=te.fromAffine({x:e,y:o});return s.assertValidity(),s}var pe=pt;function Gr(...e){return te.Fn.create(pe(je("BIP0340/challenge",...e)))}function Kr(e){return Bn(e).bytes}function Rs(e,t,r=Mt(32)){let{Fn:n}=te,o=X("message",e),{bytes:s,scalar:i}=Bn(t),c=X("auxRand",r,32),f=n.toBytes(i^pe(je("BIP0340/aux",c))),u=je("BIP0340/nonce",f,s,o),{bytes:h,scalar:g}=Bn(u),b=Gr(h,s,o),d=new Uint8Array(64);if(d.set(h,0),d.set(n.toBytes(n.create(g+b*i)),32),!zr(d,o,s))throw new Error("sign: Invalid signature produced");return d}function zr(e,t,r){let{Fn:n,BASE:o}=te,s=X("signature",e,64),i=X("message",t),c=X("publicKey",r,32);try{let f=Pr(pe(c)),u=pe(s.subarray(0,32));if(!be(u,Zr,Ft.p))return!1;let h=pe(s.subarray(32,64));if(!be(h,Zr,Ft.n))return!1;let g=Gr(n.toBytes(u),vn(f),i),b=o.multiplyUnsafe(h).add(f.multiplyUnsafe(n.neg(g))),{x:d,y:w}=b.toAffine();return!(b.is0()||!An(w)||d!==u)}catch{return!1}}var ye=(()=>{let r=(o=Mt(48))=>Ce(o,Ft.n);$r.utils.randomSecretKey;function n(o){let s=r(o);return{secretKey:s,publicKey:Kr(s)}}return{keygen:n,getPublicKey:Kr,sign:Rs,verify:zr,Point:te,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:je,lift_x:Pr,pointToBytes:vn,numberToBytesBE:Xt,bytesToNumberBE:pt,mod:it},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Sn=Wt;function Us(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ke(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function $e(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Q(e,t,r=""){let n=Us(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 In(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 Yr(e,t){Q(e,void 0,"output");let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function mt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Et(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Os(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var Hs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Wr(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Pe(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Ln=(e,t)=>{function r(n,...o){if(Q(n,void 0,"key"),!Hs)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let h=o[0];Q(h,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let s=e.tagLength;s&&o[1]!==void 0&&Q(o[1],void 0,"AAD");let i=t(n,...o),c=(h,g)=>{if(g!==void 0){if(h!==2)throw new Error("cipher output not supported");Q(g,void 0,"output")}},f=!1;return{encrypt(h,g){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,Q(h),c(i.encrypt.length,g),i.encrypt(h,g)},decrypt(h,g){if(Q(h),s&&h.length<s)throw new Error('"ciphertext" expected length bigger than tagLength='+s);return c(i.decrypt.length,g),i.decrypt(h,g)}}}return Object.assign(r,e),r};function _n(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(r&&!ks(t))throw new Error("invalid output, must be aligned");return t}function Xr(e,t,r){Ke(r);let n=new Uint8Array(16),o=Os(n);return o.setBigUint64(0,BigInt(t),r),o.setBigUint64(8,BigInt(e),r),n}function ks(e){return e.byteOffset%4===0}function ee(e){return Uint8Array.from(e)}var Qr=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),Ts=Qr("expand 16-byte k"),Ns=Qr("expand 32-byte k"),qs=mt(Ts),Cs=mt(Ns);function H(e,t){return e<<t|e>>>32-t}function Rn(e){return e.byteOffset%4===0}var Ge=64,Vs=16,Fr=2**32-1,Jr=Uint32Array.of();function Ds(e,t,r,n,o,s,i,c){let f=o.length,u=new Uint8Array(Ge),h=mt(u),g=Rn(o)&&Rn(s),b=g?mt(o):Jr,d=g?mt(s):Jr;for(let w=0;w<f;i++){if(e(t,r,n,h,i,c),i>=Fr)throw new Error("arx: counter overflow");let B=Math.min(Ge,f-w);if(g&&B===Ge){let S=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let _=0,V;_<Vs;_++)V=S+_,d[V]=b[V]^h[_];w+=Ge;continue}for(let S=0,_;S<B;S++)_=w+S,s[_]=o[_]^u[S];w+=B}}function Un(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=Wr({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return $e(o),$e(i),Ke(s),Ke(r),(c,f,u,h,g=0)=>{Q(c,void 0,"key"),Q(f,void 0,"nonce"),Q(u,void 0,"data");let b=u.length;if(h===void 0&&(h=new Uint8Array(b)),Q(h,void 0,"output"),$e(g),g<0||g>=Fr)throw new Error("arx: counter overflow");if(h.length<b)throw new Error(`arx: output (${h.length}) is shorter than data (${b})`);let d=[],w=c.length,B,S;if(w===32)d.push(B=ee(c)),S=Cs;else if(w===16&&r)B=new Uint8Array(32),B.set(c),B.set(c,16),S=qs,d.push(B);else throw Q(c,32,"arx key"),new Error("invalid key size");Rn(f)||d.push(f=ee(f));let _=mt(B);if(n){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(S,_,mt(f.subarray(0,16)),_),f=f.subarray(16)}let V=16-o;if(V!==f.length)throw new Error(`arx: nonce must be ${V} or 16 bytes`);if(V!==12){let q=new Uint8Array(12);q.set(f,s?0:12-f.length),f=q,d.push(f)}let N=mt(f);return Ds(e,S,_,N,u,h,g,i),Et(...d),h}}function F(e,t){return e[t++]&255|(e[t++]&255)<<8}var On=class{constructor(t){T(this,"blockLen",16);T(this,"outputLen",16);T(this,"buffer",new Uint8Array(16));T(this,"r",new Uint16Array(10));T(this,"h",new Uint16Array(10));T(this,"pad",new Uint16Array(8));T(this,"pos",0);T(this,"finished",!1);t=ee(Q(t,32,"key"));let r=F(t,0),n=F(t,2),o=F(t,4),s=F(t,6),i=F(t,8),c=F(t,10),f=F(t,12),u=F(t,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|c<<2)&8191,this.r[7]=(c>>>11|f<<5)&8065,this.r[8]=(f>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let h=0;h<8;h++)this.pad[h]=F(t,16+2*h)}process(t,r,n=!1){let o=n?0:2048,{h:s,r:i}=this,c=i[0],f=i[1],u=i[2],h=i[3],g=i[4],b=i[5],d=i[6],w=i[7],B=i[8],S=i[9],_=F(t,r+0),V=F(t,r+2),N=F(t,r+4),q=F(t,r+6),C=F(t,r+8),P=F(t,r+10),Y=F(t,r+12),z=F(t,r+14),R=s[0]+(_&8191),K=s[1]+((_>>>13|V<<3)&8191),M=s[2]+((V>>>10|N<<6)&8191),L=s[3]+((N>>>7|q<<9)&8191),p=s[4]+((q>>>4|C<<12)&8191),l=s[5]+(C>>>1&8191),a=s[6]+((C>>>14|P<<2)&8191),x=s[7]+((P>>>11|Y<<5)&8191),m=s[8]+((Y>>>8|z<<8)&8191),v=s[9]+(z>>>5|o),y=0,A=y+R*c+K*(5*S)+M*(5*B)+L*(5*w)+p*(5*d);y=A>>>13,A&=8191,A+=l*(5*b)+a*(5*g)+x*(5*h)+m*(5*u)+v*(5*f),y+=A>>>13,A&=8191;let E=y+R*f+K*c+M*(5*S)+L*(5*B)+p*(5*w);y=E>>>13,E&=8191,E+=l*(5*d)+a*(5*b)+x*(5*g)+m*(5*h)+v*(5*u),y+=E>>>13,E&=8191;let I=y+R*u+K*f+M*c+L*(5*S)+p*(5*B);y=I>>>13,I&=8191,I+=l*(5*w)+a*(5*d)+x*(5*b)+m*(5*g)+v*(5*h),y+=I>>>13,I&=8191;let O=y+R*h+K*u+M*f+L*c+p*(5*S);y=O>>>13,O&=8191,O+=l*(5*B)+a*(5*w)+x*(5*d)+m*(5*b)+v*(5*g),y+=O>>>13,O&=8191;let D=y+R*g+K*h+M*u+L*f+p*c;y=D>>>13,D&=8191,D+=l*(5*S)+a*(5*B)+x*(5*w)+m*(5*d)+v*(5*b),y+=D>>>13,D&=8191;let k=y+R*b+K*g+M*h+L*u+p*f;y=k>>>13,k&=8191,k+=l*c+a*(5*S)+x*(5*B)+m*(5*w)+v*(5*d),y+=k>>>13,k&=8191;let U=y+R*d+K*b+M*g+L*h+p*u;y=U>>>13,U&=8191,U+=l*f+a*c+x*(5*S)+m*(5*B)+v*(5*w),y+=U>>>13,U&=8191;let Z=y+R*w+K*d+M*b+L*g+p*h;y=Z>>>13,Z&=8191,Z+=l*u+a*f+x*c+m*(5*S)+v*(5*B),y+=Z>>>13,Z&=8191;let G=y+R*B+K*w+M*d+L*b+p*g;y=G>>>13,G&=8191,G+=l*h+a*u+x*f+m*c+v*(5*S),y+=G>>>13,G&=8191;let j=y+R*S+K*B+M*w+L*d+p*b;y=j>>>13,j&=8191,j+=l*g+a*h+x*u+m*f+v*c,y+=j>>>13,j&=8191,y=(y<<2)+y|0,y=y+A|0,A=y&8191,y=y>>>13,E+=y,s[0]=A,s[1]=E,s[2]=I,s[3]=O,s[4]=D,s[5]=k,s[6]=U,s[7]=Z,s[8]=G,s[9]=j}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),o=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=o,o=t[c]>>>13,t[c]&=8191;t[0]+=o*5,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,n[0]=t[0]+5,o=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+o,o=n[c]>>>13,n[c]&=8191;n[9]-=8192;let s=(o^1)-1;for(let c=0;c<10;c++)n[c]&=s;s=~s;for(let c=0;c<10;c++)t[c]=t[c]&s|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let c=1;c<8;c++)i=(t[c]+r[c]|0)+(i>>>16)|0,t[c]=i&65535;Et(n)}update(t){In(this),Q(t),t=ee(t);let{buffer:r,blockLen:n}=this,o=t.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);if(i===n){for(;n<=o-s;s+=n)this.process(t,s);continue}r.set(t.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Et(this.h,this.r,this.buffer,this.pad)}digestInto(t){In(this),Yr(t,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:o}=this;if(o){for(r[o++]=1;o<16;o++)r[o]=0;this.process(r,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)t[s++]=n[i]>>>0,t[s++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function Ms(e){let t=(n,o)=>e(o).update(n).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var to=Ms(e=>new On(e));function ro(e,t,r,n,o,s=20){let i=e[0],c=e[1],f=e[2],u=e[3],h=t[0],g=t[1],b=t[2],d=t[3],w=t[4],B=t[5],S=t[6],_=t[7],V=o,N=r[0],q=r[1],C=r[2],P=i,Y=c,z=f,R=u,K=h,M=g,L=b,p=d,l=w,a=B,x=S,m=_,v=V,y=N,A=q,E=C;for(let O=0;O<s;O+=2)P=P+K|0,v=H(v^P,16),l=l+v|0,K=H(K^l,12),P=P+K|0,v=H(v^P,8),l=l+v|0,K=H(K^l,7),Y=Y+M|0,y=H(y^Y,16),a=a+y|0,M=H(M^a,12),Y=Y+M|0,y=H(y^Y,8),a=a+y|0,M=H(M^a,7),z=z+L|0,A=H(A^z,16),x=x+A|0,L=H(L^x,12),z=z+L|0,A=H(A^z,8),x=x+A|0,L=H(L^x,7),R=R+p|0,E=H(E^R,16),m=m+E|0,p=H(p^m,12),R=R+p|0,E=H(E^R,8),m=m+E|0,p=H(p^m,7),P=P+M|0,E=H(E^P,16),x=x+E|0,M=H(M^x,12),P=P+M|0,E=H(E^P,8),x=x+E|0,M=H(M^x,7),Y=Y+L|0,v=H(v^Y,16),m=m+v|0,L=H(L^m,12),Y=Y+L|0,v=H(v^Y,8),m=m+v|0,L=H(L^m,7),z=z+p|0,y=H(y^z,16),l=l+y|0,p=H(p^l,12),z=z+p|0,y=H(y^z,8),l=l+y|0,p=H(p^l,7),R=R+K|0,A=H(A^R,16),a=a+A|0,K=H(K^a,12),R=R+K|0,A=H(A^R,8),a=a+A|0,K=H(K^a,7);let I=0;n[I++]=i+P|0,n[I++]=c+Y|0,n[I++]=f+z|0,n[I++]=u+R|0,n[I++]=h+K|0,n[I++]=g+M|0,n[I++]=b+L|0,n[I++]=d+p|0,n[I++]=w+l|0,n[I++]=B+a|0,n[I++]=S+x|0,n[I++]=_+m|0,n[I++]=V+v|0,n[I++]=N+y|0,n[I++]=q+A|0,n[I++]=C+E|0}function Zs(e,t,r,n){let o=e[0],s=e[1],i=e[2],c=e[3],f=t[0],u=t[1],h=t[2],g=t[3],b=t[4],d=t[5],w=t[6],B=t[7],S=r[0],_=r[1],V=r[2],N=r[3];for(let C=0;C<20;C+=2)o=o+f|0,S=H(S^o,16),b=b+S|0,f=H(f^b,12),o=o+f|0,S=H(S^o,8),b=b+S|0,f=H(f^b,7),s=s+u|0,_=H(_^s,16),d=d+_|0,u=H(u^d,12),s=s+u|0,_=H(_^s,8),d=d+_|0,u=H(u^d,7),i=i+h|0,V=H(V^i,16),w=w+V|0,h=H(h^w,12),i=i+h|0,V=H(V^i,8),w=w+V|0,h=H(h^w,7),c=c+g|0,N=H(N^c,16),B=B+N|0,g=H(g^B,12),c=c+g|0,N=H(N^c,8),B=B+N|0,g=H(g^B,7),o=o+u|0,N=H(N^o,16),w=w+N|0,u=H(u^w,12),o=o+u|0,N=H(N^o,8),w=w+N|0,u=H(u^w,7),s=s+h|0,S=H(S^s,16),B=B+S|0,h=H(h^B,12),s=s+h|0,S=H(S^s,8),B=B+S|0,h=H(h^B,7),i=i+g|0,_=H(_^i,16),b=b+_|0,g=H(g^b,12),i=i+g|0,_=H(_^i,8),b=b+_|0,g=H(g^b,7),c=c+f|0,V=H(V^c,16),d=d+V|0,f=H(f^d,12),c=c+f|0,V=H(V^c,8),d=d+V|0,f=H(f^d,7);let q=0;n[q++]=o,n[q++]=s,n[q++]=i,n[q++]=c,n[q++]=S,n[q++]=_,n[q++]=V,n[q++]=N}var Hn=Un(ro,{counterRight:!1,counterLength:4,allowShortKeys:!1}),js=Un(ro,{counterRight:!1,counterLength:8,extendNonceFn:Zs,allowShortKeys:!1});var Ks=new Uint8Array(16),eo=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(Ks.subarray(r))},$s=new Uint8Array(32);function no(e,t,r,n,o){o!==void 0&&Q(o,void 0,"AAD");let s=e(t,r,$s),i=Xr(n.length,o?o.length:0,!0),c=to.create(s);o&&eo(c,o),eo(c,n),c.update(i);let f=c.digest();return Et(s,i),f}var oo=e=>(t,r,n)=>({encrypt(s,i){let c=s.length;i=_n(c+16,i,!1),i.set(s);let f=i.subarray(0,-16);e(t,r,f,f,1);let u=no(e,t,r,f,n);return i.set(u,c),Et(u),i},decrypt(s,i){i=_n(s.length-16,i,!1);let c=s.subarray(0,-16),f=s.subarray(-16),u=no(e,t,r,c,n);if(!Pe(f,u))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),e(t,r,i,i,1),Et(u),i}}),Mc=Ln({blockSize:64,nonceLength:12,tagLength:16},oo(Hn)),Zc=Ln({blockSize:64,nonceLength:24,tagLength:16},oo(js));function we(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ut(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function W(e,t,r=""){let n=we(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 Kt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");ut(e.outputLen),ut(e.blockLen)}function ne(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 io(e,t){W(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ze(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ht(e,t){return e<<32-t|e>>>t}var co=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ps=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $t(e){if(W(e),co)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ps[e[r]];return t}var Bt={_0:48,_9:57,A:65,F:70,a:97,f:102};function so(e){if(e>=Bt._0&&e<=Bt._9)return e-Bt._0;if(e>=Bt.A&&e<=Bt.F)return e-(Bt.A-10);if(e>=Bt.a&&e<=Bt.f)return e-(Bt.a-10)}function At(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(co)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=so(e.charCodeAt(s)),c=so(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 ft(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];W(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}function fo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function me(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var ao=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function uo(e,t,r){return e&t^~e&r}function lo(e,t,r){return e&t^e&r^t&r}var Ye=class{constructor(t,r,n,o){T(this,"blockLen");T(this,"outputLen");T(this,"padOffset");T(this,"isLE");T(this,"buffer");T(this,"view");T(this,"finished",!1);T(this,"length",0);T(this,"pos",0);T(this,"destroyed",!1);this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=ze(this.buffer)}update(t){ne(this),W(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=ze(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){ne(this),io(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let g=i;g<o;g++)r[g]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=ze(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=f/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<u;g++)c.setUint32(4*g,h[g],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()}},St=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Gs=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]),kt=new Uint32Array(64),kn=class extends Ye{constructor(t){super(64,t,8,!1)}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 g=0;g<16;g++,r+=4)kt[g]=t.getUint32(r,!1);for(let g=16;g<64;g++){let b=kt[g-15],d=kt[g-2],w=ht(b,7)^ht(b,18)^b>>>3,B=ht(d,17)^ht(d,19)^d>>>10;kt[g]=B+kt[g-7]+w+kt[g-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:u,H:h}=this;for(let g=0;g<64;g++){let b=ht(c,6)^ht(c,11)^ht(c,25),d=h+b+uo(c,f,u)+Gs[g]+kt[g]|0,B=(ht(n,2)^ht(n,13)^ht(n,22))+lo(n,o,s)|0;h=u,u=f,f=c,c=i+d|0,i=s,s=o,o=n,n=d+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,u=u+this.G|0,h=h+this.H|0,this.set(n,o,s,i,c,f,u,h)}roundClean(){vt(kt)}destroy(){this.set(0,0,0,0,0,0,0,0),vt(this.buffer)}},Tn=class extends kn{constructor(){super(32);T(this,"A",St[0]|0);T(this,"B",St[1]|0);T(this,"C",St[2]|0);T(this,"D",St[3]|0);T(this,"E",St[4]|0);T(this,"F",St[5]|0);T(this,"G",St[6]|0);T(this,"H",St[7]|0)}};var re=fo(()=>new Tn,ao(1));var qn=BigInt(0),Nn=BigInt(1);function Ee(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ho(e){if(typeof e=="bigint"){if(!We(e))throw new Error("positive bigint expected, got "+e)}else ut(e);return e}function Be(e){let t=ho(e).toString(16);return t.length&1?"0"+t:t}function bo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?qn:BigInt("0x"+e)}function oe(e){return bo($t(e))}function Cn(e){return bo($t(zs(W(e)).reverse()))}function Xe(e,t){ut(t),e=ho(e);let r=At(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Vn(e,t){return Xe(e,t).reverse()}function zs(e){return Uint8Array.from(e)}var We=e=>typeof e=="bigint"&&qn<=e;function Ys(e,t,r){return We(e)&&We(t)&&We(r)&&t<=e&&e<r}function go(e,t,r,n){if(!Ys(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Dn(e){let t;for(t=0;e>qn;e>>=Nn,t+=1);return t}var ve=e=>(Nn<<BigInt(e))-Nn;function xo(e,t,r){if(ut(e,"hashLen"),ut(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,f=n(e),u=n(e),h=0,g=()=>{f.fill(1),u.fill(0),h=0},b=(...S)=>r(u,ft(f,...S)),d=(S=o)=>{u=b(s,S),f=b(),S.length!==0&&(u=b(i,S),f=b())},w=()=>{if(h++>=c)throw new Error("drbg: tried max amount of iterations");let S=0,_=[];for(;S<t;){f=b();let V=f.slice();_.push(V),S+=f.length}return ft(..._)};return(S,_)=>{g(),d(S);let V;for(;!(V=_(w()));)d();return g(),V}}function Ae(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,c){let f=e[s];if(c&&f===void 0)return;let u=typeof f;if(u!==i||f===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,f])=>n(c,f,i));o(t,!1),o(r,!0)}function Mn(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 rt=BigInt(0),et=BigInt(1),Pt=BigInt(2),wo=BigInt(3),mo=BigInt(4),Eo=BigInt(5),Ws=BigInt(7),Bo=BigInt(8),Xs=BigInt(9),vo=BigInt(16);function bt(e,t){let r=e%t;return r>=rt?r:t+r}function at(e,t,r){let n=e;for(;t-- >rt;)n*=n,n%=r;return n}function po(e,t){if(e===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let r=bt(e,t),n=t,o=rt,s=et,i=et,c=rt;for(;r!==rt;){let u=n/r,h=n%r,g=o-i*u,b=s-c*u;n=r,r=h,o=i,s=c,i=g,c=b}if(n!==et)throw new Error("invert: does not exist");return bt(o,t)}function jn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ao(e,t){let r=(e.ORDER+et)/mo,n=e.pow(t,r);return jn(e,n,t),n}function Js(e,t){let r=(e.ORDER-Eo)/Bo,n=e.mul(t,Pt),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Pt),o),c=e.mul(s,e.sub(i,e.ONE));return jn(e,c,t),c}function Qs(e){let t=se(e),r=So(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Ws)/vo;return(c,f)=>{let u=c.pow(f,i),h=c.mul(u,n),g=c.mul(u,o),b=c.mul(u,s),d=c.eql(c.sqr(h),f),w=c.eql(c.sqr(g),f);u=c.cmov(u,h,d),h=c.cmov(b,g,w);let B=c.eql(c.sqr(h),f),S=c.cmov(u,h,B);return jn(c,S,f),S}}function So(e){if(e<wo)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%Pt===rt;)t/=Pt,r++;let n=Pt,o=se(e);for(;yo(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ao;let s=o.pow(n,t),i=(t+et)/Pt;return function(f,u){if(f.is0(u))return u;if(yo(f,u)!==1)throw new Error("Cannot find square root");let h=r,g=f.mul(f.ONE,s),b=f.pow(u,t),d=f.pow(u,i);for(;!f.eql(b,f.ONE);){if(f.is0(b))return f.ZERO;let w=1,B=f.sqr(b);for(;!f.eql(B,f.ONE);)if(w++,B=f.sqr(B),w===h)throw new Error("Cannot find square root");let S=et<<BigInt(h-w-1),_=f.pow(g,S);h=w,g=f.sqr(_),b=f.mul(b,g),d=f.mul(d,_)}return d}}function Fs(e){return e%mo===wo?Ao:e%Bo===Eo?Js:e%vo===Xs?Qs(e):So(e)}var ti=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Kn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ti.reduce((n,o)=>(n[o]="function",n),t);return Ae(e,r),e}function ei(e,t,r){if(r<rt)throw new Error("invalid exponent, negatives unsupported");if(r===rt)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>rt;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function Je(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 yo(e,t){let r=(e.ORDER-et)/Pt,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 ni(e,t){t!==void 0&&ut(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Zn=class{constructor(t,r={}){T(this,"ORDER");T(this,"BITS");T(this,"BYTES");T(this,"isLE");T(this,"ZERO",rt);T(this,"ONE",et);T(this,"_lengths");T(this,"_sqrt");T(this,"_mod");if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=ni(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return bt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&et)===et}neg(t){return bt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return bt(t*t,this.ORDER)}add(t,r){return bt(t+r,this.ORDER)}sub(t,r){return bt(t-r,this.ORDER)}mul(t,r){return bt(t*r,this.ORDER)}pow(t,r){return ei(this,t,r)}div(t,r){return bt(t*po(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return po(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Fs(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Vn(t,this.BYTES):Xe(t,this.BYTES)}fromBytes(t,r=!1){W(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Cn(t):oe(t);if(c&&(f=bt(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Je(this,t)}cmov(t,r,n){return n?r:t}};function se(e,t={}){return new Zn(e,t)}function Io(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 $n(e){let t=Io(e);return t+Math.ceil(t/2)}function Pn(e,t,r=!1){W(e);let n=e.length,o=Io(t),s=$n(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Cn(e):oe(e),c=bt(i,t-et)+et;return r?Vn(c,o):Xe(c,o)}var ie=BigInt(0),Gt=BigInt(1);function Se(e,t){let r=t.negate();return e?r:t}function Wn(e,t){let r=Je(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Uo(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Gn(e,t){Uo(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ve(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Lo(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+=Gt);let u=t*n,h=u+Math.abs(c)-1,g=c===0,b=c<0,d=t%2!==0;return{nextN:f,offset:h,isZero:g,isNeg:b,isNegF:d,offsetF:u}}var zn=new WeakMap,Oo=new WeakMap;function Yn(e){return Oo.get(e)||1}function _o(e){if(e!==ie)throw new Error("invalid wNAF")}var Qe=class{constructor(t,r){T(this,"BASE");T(this,"ZERO");T(this,"Fn");T(this,"bits");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>ie;)r&Gt&&(n=n.add(o)),o=o.double(),r>>=Gt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Gn(r,this.bits),s=[],i=t,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let u=1;u<o;u++)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=Gn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:u,isZero:h,isNeg:g,isNegF:b,offsetF:d}=Lo(n,c,i);n=f,h?s=s.add(Se(b,r[d])):o=o.add(Se(g,r[u]))}return _o(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Gn(t,this.bits);for(let i=0;i<s.windows&&n!==ie;i++){let{nextN:c,offset:f,isZero:u,isNeg:h}=Lo(n,i,s);if(n=c,!u){let g=r[f];o=o.add(h?g.negate():g)}}return _o(n),o}getPrecomputes(t,r,n){let o=zn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),zn.set(r,o))),o}cached(t,r,n){let o=Yn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Yn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Uo(r,this.bits),Oo.set(t,r),zn.delete(t)}hasCache(t){return Yn(t)!==1}};function Ho(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ie||n>ie;)r&Gt&&(s=s.add(o)),n&Gt&&(i=i.add(o)),o=o.double(),r>>=Gt,n>>=Gt;return{p1:s,p2:i}}function Ro(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Kn(t),t}else return se(e,{isLE:r})}function ko(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 u=t[f];if(!(typeof u=="bigint"&&u>ie))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Ro(t.p,r.Fp,n),s=Ro(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}}function To(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Fe=class{constructor(t,r){T(this,"oHash");T(this,"iHash");T(this,"blockLen");T(this,"outputLen");T(this,"finished",!1);T(this,"destroyed",!1);if(Kt(t),W(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),vt(o)}update(t){return ne(this),this.iHash.update(t),this}digestInto(t){ne(this),W(t,this.outputLen,"output"),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()}},Tt=(e,t,r)=>new Fe(e,t).update(r).digest();Tt.create=(e,t)=>new Fe(e,t);var No=(e,t)=>(e+(e>=0?t:-t)/qo)/t;function ri(e,t,r){let[[n,o],[s,i]]=t,c=No(i*e,r),f=No(-o*e,r),u=e-c*n-f*s,h=-c*o-f*i,g=u<It,b=h<It;g&&(u=-u),b&&(h=-h);let d=ve(Math.ceil(Dn(r)/2))+ce;if(u<It||u>=d||h<It||h>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:g,k1:u,k2neg:b,k2:h}}function Jn(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Xn(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ee(r.lowS,"lowS"),Ee(r.prehash,"prehash"),r.format!==void 0&&Jn(r.format),r}var Qn=class extends Error{constructor(t=""){super(t)}},Nt={Err:Qn,_tlv:{encode:(e,t)=>{let{Err:r}=Nt;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=Be(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Be(o.length/2|128):"";return Be(e)+s+o+t},decode(e,t){let{Err:r}=Nt,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 u=t.subarray(n,n+f);if(u.length!==f)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of u)i=i<<8|h;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}=Nt;if(e<It)throw new t("integer: negative integers are not allowed");let r=Be(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}=Nt;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 oe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Nt,o=W(e,void 0,"signature"),{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:u,l:h}=n.decode(2,f);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Nt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},It=BigInt(0),ce=BigInt(1),qo=BigInt(2),tn=BigInt(3),oi=BigInt(4);function Co(e,t={}){let r=ko("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Ae(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});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 u=Do(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function g(p,l,a){let{x,y:m}=l.toAffine(),v=n.toBytes(x);if(Ee(a,"isCompressed"),a){h();let y=!n.isOdd(m);return ft(Vo(y),v)}else return ft(Uint8Array.of(4),v,n.toBytes(m))}function b(p){W(p,void 0,"Point");let{publicKey:l,publicKeyUncompressed:a}=u,x=p.length,m=p[0],v=p.subarray(1);if(x===l&&(m===2||m===3)){let y=n.fromBytes(v);if(!n.isValid(y))throw new Error("bad point: is not on curve, wrong x");let A=B(y),E;try{E=n.sqrt(A)}catch(D){let k=D instanceof Error?": "+D.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}h();let I=n.isOdd(E);return(m&1)===1!==I&&(E=n.neg(E)),{x:y,y:E}}else if(x===a&&m===4){let y=n.BYTES,A=n.fromBytes(v.subarray(0,y)),E=n.fromBytes(v.subarray(y,y*2));if(!S(A,E))throw new Error("bad point: is not on curve");return{x:A,y:E}}else throw new Error(`bad point: got length ${x}, expected compressed=${l} or uncompressed=${a}`)}let d=t.toBytes||g,w=t.fromBytes||b;function B(p){let l=n.sqr(p),a=n.mul(l,p);return n.add(n.add(a,n.mul(p,s.a)),s.b)}function S(p,l){let a=n.sqr(l),x=B(p);return n.eql(a,x)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,tn),oi),V=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,V)))throw new Error("bad curve params: a or b");function N(p,l,a=!1){if(!n.isValid(l)||a&&n.is0(l))throw new Error(`bad point coordinate ${p}`);return l}function q(p){if(!(p instanceof R))throw new Error("Weierstrass Point expected")}function C(p){if(!f||!f.basises)throw new Error("no endo");return ri(p,f.basises,o.ORDER)}let P=Mn((p,l)=>{let{X:a,Y:x,Z:m}=p;if(n.eql(m,n.ONE))return{x:a,y:x};let v=p.is0();l==null&&(l=v?n.ONE:n.inv(m));let y=n.mul(a,l),A=n.mul(x,l),E=n.mul(m,l);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x:y,y:A}}),Y=Mn(p=>{if(p.is0()){if(t.allowInfinityPoint&&!n.is0(p.Y))return;throw new Error("bad point: ZERO")}let{x:l,y:a}=p.toAffine();if(!n.isValid(l)||!n.isValid(a))throw new Error("bad point: x or y not field elements");if(!S(l,a))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function z(p,l,a,x,m){return a=new R(n.mul(a.X,p),a.Y,a.Z),l=Se(x,l),a=Se(m,a),l.add(a)}let L=class L{constructor(l,a,x){T(this,"X");T(this,"Y");T(this,"Z");this.X=N("x",l),this.Y=N("y",a,!0),this.Z=N("z",x),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:a,y:x}=l||{};if(!l||!n.isValid(a)||!n.isValid(x))throw new Error("invalid affine point");if(l instanceof L)throw new Error("projective point not allowed");return n.is0(a)&&n.is0(x)?L.ZERO:new L(a,x,n.ONE)}static fromBytes(l){let a=L.fromAffine(w(W(l,void 0,"point")));return a.assertValidity(),a}static fromHex(l){return L.fromBytes(At(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,a=!0){return M.createCache(this,l),a||this.multiply(tn),this}assertValidity(){Y(this)}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){q(l);let{X:a,Y:x,Z:m}=this,{X:v,Y:y,Z:A}=l,E=n.eql(n.mul(a,A),n.mul(v,m)),I=n.eql(n.mul(x,A),n.mul(y,m));return E&&I}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b:a}=s,x=n.mul(a,tn),{X:m,Y:v,Z:y}=this,A=n.ZERO,E=n.ZERO,I=n.ZERO,O=n.mul(m,m),D=n.mul(v,v),k=n.mul(y,y),U=n.mul(m,v);return U=n.add(U,U),I=n.mul(m,y),I=n.add(I,I),A=n.mul(l,I),E=n.mul(x,k),E=n.add(A,E),A=n.sub(D,E),E=n.add(D,E),E=n.mul(A,E),A=n.mul(U,A),I=n.mul(x,I),k=n.mul(l,k),U=n.sub(O,k),U=n.mul(l,U),U=n.add(U,I),I=n.add(O,O),O=n.add(I,O),O=n.add(O,k),O=n.mul(O,U),E=n.add(E,O),k=n.mul(v,y),k=n.add(k,k),O=n.mul(k,U),A=n.sub(A,O),I=n.mul(k,D),I=n.add(I,I),I=n.add(I,I),new L(A,E,I)}add(l){q(l);let{X:a,Y:x,Z:m}=this,{X:v,Y:y,Z:A}=l,E=n.ZERO,I=n.ZERO,O=n.ZERO,D=s.a,k=n.mul(s.b,tn),U=n.mul(a,v),Z=n.mul(x,y),G=n.mul(m,A),j=n.add(a,x),$=n.add(v,y);j=n.mul(j,$),$=n.add(U,Z),j=n.sub(j,$),$=n.add(a,m);let J=n.add(v,A);return $=n.mul($,J),J=n.add(U,G),$=n.sub($,J),J=n.add(x,m),E=n.add(y,A),J=n.mul(J,E),E=n.add(Z,G),J=n.sub(J,E),O=n.mul(D,$),E=n.mul(k,G),O=n.add(E,O),E=n.sub(Z,O),O=n.add(Z,O),I=n.mul(E,O),Z=n.add(U,U),Z=n.add(Z,U),G=n.mul(D,G),$=n.mul(k,$),Z=n.add(Z,G),G=n.sub(U,G),G=n.mul(D,G),$=n.add($,G),U=n.mul(Z,$),I=n.add(I,U),U=n.mul(J,$),E=n.mul(j,E),E=n.sub(E,U),U=n.mul(j,Z),O=n.mul(J,O),O=n.add(O,U),new L(E,I,O)}subtract(l){return this.add(l.negate())}is0(){return this.equals(L.ZERO)}multiply(l){let{endo:a}=t;if(!o.isValidNot0(l))throw new Error("invalid scalar: out of range");let x,m,v=y=>M.cached(this,y,A=>Wn(L,A));if(a){let{k1neg:y,k1:A,k2neg:E,k2:I}=C(l),{p:O,f:D}=v(A),{p:k,f:U}=v(I);m=D.add(U),x=z(a.beta,O,k,y,E)}else{let{p:y,f:A}=v(l);x=y,m=A}return Wn(L,[x,m])[0]}multiplyUnsafe(l){let{endo:a}=t,x=this;if(!o.isValid(l))throw new Error("invalid scalar: out of range");if(l===It||x.is0())return L.ZERO;if(l===ce)return x;if(M.hasCache(this))return this.multiply(l);if(a){let{k1neg:m,k1:v,k2neg:y,k2:A}=C(l),{p1:E,p2:I}=Ho(L,x,v,A);return z(a.beta,E,I,m,y)}else return M.unsafe(x,l)}toAffine(l){return P(this,l)}isTorsionFree(){let{isTorsionFree:l}=t;return i===ce?!0:l?l(L,this):M.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===ce?this:l?l(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(l=!0){return Ee(l,"isCompressed"),this.assertValidity(),d(L,this,l)}toHex(l=!0){return $t(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};T(L,"BASE",new L(s.Gx,s.Gy,n.ONE)),T(L,"ZERO",new L(n.ZERO,n.ONE,n.ZERO)),T(L,"Fp",n),T(L,"Fn",o);let R=L,K=o.BITS,M=new Qe(R,t.endo?Math.ceil(K/2):K);return R.BASE.precompute(8),R}function Vo(e){return Uint8Array.of(e?2:3)}function Do(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function si(e,t={}){let{Fn:r}=e,n=t.randomBytes||me,o=Object.assign(Do(e.Fp,r),{seed:$n(r.ORDER)});function s(d){try{let w=r.fromBytes(d);return r.isValidNot0(w)}catch{return!1}}function i(d,w){let{publicKey:B,publicKeyUncompressed:S}=o;try{let _=d.length;return w===!0&&_!==B||w===!1&&_!==S?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Pn(W(d,o.seed,"seed"),r.ORDER)}function f(d,w=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(w)}function u(d){let{secretKey:w,publicKey:B,publicKeyUncompressed:S}=o;if(!we(d)||"_lengths"in r&&r._lengths||w===B)return;let _=W(d,void 0,"key").length;return _===B||_===S}function h(d,w,B=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(w)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(d);return e.fromBytes(w).multiply(S).toBytes(B)}let g={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},b=To(c,f);return Object.freeze({getPublicKey:f,getSharedSecret:h,keygen:b,Point:e,utils:g,lengths:o})}function Mo(e,t,r={}){Kt(t),Ae(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||me,o=r.hmac||((l,a)=>Tt(t,l,a)),{Fp:s,Fn:i}=e,{ORDER:c,BITS:f}=i,{keygen:u,getPublicKey:h,getSharedSecret:g,utils:b,lengths:d}=si(e,r),w={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},B=c*qo<s.ORDER;function S(l){let a=c>>ce;return l>a}function _(l,a){if(!i.isValidNot0(a))throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);return a}function V(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function N(l,a){Jn(a);let x=d.signature,m=a==="compact"?x:a==="recovered"?x+1:void 0;return W(l,m)}class q{constructor(a,x,m){T(this,"r");T(this,"s");T(this,"recovery");if(this.r=_("r",a),this.s=_("s",x),m!=null){if(V(),![0,1,2,3].includes(m))throw new Error("invalid recovery id");this.recovery=m}Object.freeze(this)}static fromBytes(a,x=w.format){N(a,x);let m;if(x==="der"){let{r:E,s:I}=Nt.toSig(W(a));return new q(E,I)}x==="recovered"&&(m=a[0],x="compact",a=a.subarray(1));let v=d.signature/2,y=a.subarray(0,v),A=a.subarray(v,v*2);return new q(i.fromBytes(y),i.fromBytes(A),m)}static fromHex(a,x){return this.fromBytes(At(a),x)}assertRecovery(){let{recovery:a}=this;if(a==null)throw new Error("invalid recovery id: must be present");return a}addRecoveryBit(a){return new q(this.r,this.s,a)}recoverPublicKey(a){let{r:x,s:m}=this,v=this.assertRecovery(),y=v===2||v===3?x+c:x;if(!s.isValid(y))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let A=s.toBytes(y),E=e.fromBytes(ft(Vo((v&1)===0),A)),I=i.inv(y),O=P(W(a,void 0,"msgHash")),D=i.create(-O*I),k=i.create(m*I),U=e.BASE.multiplyUnsafe(D).add(E.multiplyUnsafe(k));if(U.is0())throw new Error("invalid recovery: point at infinify");return U.assertValidity(),U}hasHighS(){return S(this.s)}toBytes(a=w.format){if(Jn(a),a==="der")return At(Nt.hexFromSig(this));let{r:x,s:m}=this,v=i.toBytes(x),y=i.toBytes(m);return a==="recovered"?(V(),ft(Uint8Array.of(this.assertRecovery()),v,y)):ft(v,y)}toHex(a){return $t(this.toBytes(a))}}let C=r.bits2int||function(a){if(a.length>8192)throw new Error("input is too large");let x=oe(a),m=a.length*8-f;return m>0?x>>BigInt(m):x},P=r.bits2int_modN||function(a){return i.create(C(a))},Y=ve(f);function z(l){return go("num < 2^"+f,l,It,Y),i.toBytes(l)}function R(l,a){return W(l,void 0,"message"),a?W(t(l),void 0,"prehashed message"):l}function K(l,a,x){let{lowS:m,prehash:v,extraEntropy:y}=Xn(x,w);l=R(l,v);let A=P(l),E=i.fromBytes(a);if(!i.isValidNot0(E))throw new Error("invalid private key");let I=[z(E),z(A)];if(y!=null&&y!==!1){let U=y===!0?n(d.secretKey):y;I.push(W(U,void 0,"extraEntropy"))}let O=ft(...I),D=A;function k(U){let Z=C(U);if(!i.isValidNot0(Z))return;let G=i.inv(Z),j=e.BASE.multiply(Z).toAffine(),$=i.create(j.x);if($===It)return;let J=i.create(G*i.create(D+$*E));if(J===It)return;let fe=(j.x===$?0:2)|Number(j.y&ce),ae=J;return m&&S(J)&&(ae=i.neg(J),fe^=1),new q($,ae,B?void 0:fe)}return{seed:O,k2sig:k}}function M(l,a,x={}){let{seed:m,k2sig:v}=K(l,a,x);return xo(t.outputLen,i.BYTES,o)(m,v).toBytes(x.format)}function L(l,a,x,m={}){let{lowS:v,prehash:y,format:A}=Xn(m,w);if(x=W(x,void 0,"publicKey"),a=R(a,y),!we(l)){let E=l instanceof q?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+E)}N(l,A);try{let E=q.fromBytes(l,A),I=e.fromBytes(x);if(v&&E.hasHighS())return!1;let{r:O,s:D}=E,k=P(a),U=i.inv(D),Z=i.create(k*U),G=i.create(O*U),j=e.BASE.multiplyUnsafe(Z).add(I.multiplyUnsafe(G));return j.is0()?!1:i.create(j.x)===O}catch{return!1}}function p(l,a,x={}){let{prehash:m}=Xn(x,w);return a=R(a,m),q.fromBytes(l,"recovered").recoverPublicKey(a).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:g,utils:b,lengths:d,Point:e,sign:M,verify:L,recoverPublicKey:p,Signature:q,hash:t})}var tr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ii={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Zo=BigInt(2);function ci(e){let t=tr.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),u=e*e*e%t,h=u*u*e%t,g=at(h,r,t)*h%t,b=at(g,r,t)*h%t,d=at(b,Zo,t)*u%t,w=at(d,o,t)*d%t,B=at(w,s,t)*w%t,S=at(B,c,t)*B%t,_=at(S,f,t)*S%t,V=at(_,c,t)*B%t,N=at(V,r,t)*h%t,q=at(N,i,t)*w%t,C=at(q,n,t)*u%t,P=at(C,Zo,t);if(!Fn.eql(Fn.sqr(P),e))throw new Error("Cannot find square root");return P}var Fn=se(tr.p,{sqrt:ci}),fi=Co(tr,{Fp:Fn,endo:ii}),jo=Mo(fi,re);function $o(e,t,r){return Kt(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Tt(e,r,t)}var er=Uint8Array.of(0),Ko=Uint8Array.of();function Po(e,t,r,n=32){Kt(e),ut(n,"length");let o=e.outputLen;if(n>255*o)throw new Error("Length must be <= 255*HashLen");let s=Math.ceil(n/o);r===void 0?r=Ko:W(r,void 0,"info");let i=new Uint8Array(s*o),c=Tt.create(e,t),f=c._cloneInto(),u=new Uint8Array(c.outputLen);for(let h=0;h<s;h++)er[0]=h+1,f.update(h===0?Ko:u).update(r).update(er).digestInto(u),i.set(u,o*h),c._cloneInto(f);return c.destroy(),f.destroy(),vt(u,er),i.slice(0,n)}function zo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ai(e){if(!zo(e))throw new Error("Uint8Array expected")}function Yo(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(r=>typeof r=="string"):t.every(r=>Number.isSafeInteger(r)):!1}function Ie(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function or(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function rr(e){if(!Array.isArray(e))throw new Error("array expected")}function en(e,t){if(!Yo(!0,t))throw new Error(`${e}: array of strings expected`)}function ui(e,t){if(!Yo(!1,t))throw new Error(`${e}: array of numbers expected`)}function li(...e){let t=s=>s,r=(s,i)=>c=>s(i(c)),n=e.map(s=>s.encode).reduceRight(r,t),o=e.map(s=>s.decode).reduce(r,t);return{encode:n,decode:o}}function di(e){let t=typeof e=="string"?e.split(""):e,r=t.length;en("alphabet",t);let n=new Map(t.map((o,s)=>[o,s]));return{encode:o=>(rr(o),o.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${e}`);return t[s]})),decode:o=>(rr(o),o.map(s=>{Ie("alphabet.decode",s);let i=n.get(s);if(i===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${e}`);return i}))}}function hi(e=""){return Ie("join",e),{encode:t=>(en("join.decode",t),t.join(e)),decode:t=>(Ie("join.decode",t),t.split(e))}}function bi(e,t="="){return or(e),Ie("padding",t),{encode(r){for(en("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){en("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}var Wo=(e,t)=>t===0?e:Wo(t,e%t),nn=(e,t)=>e+(t-Wo(e,t)),nr=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Go(e,t,r,n){if(rr(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(nn(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${nn(t,r)}`);let o=0,s=0,i=nr[t],c=nr[r]-1,f=[];for(let u of e){if(or(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${t}`);if(o=o<<t|u,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=r;s-=r)f.push((o>>s-r&c)>>>0);let h=nr[s];if(h===void 0)throw new Error("invalid carry");o&=h-1}if(o=o<<r-s&c,!n&&s>=t)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&s>0&&f.push(o>>>0),f}function gi(e,t=!1){if(or(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(nn(8,e)>32||nn(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!zo(r))throw new Error("radix2.encode input should be Uint8Array");return Go(Array.from(r),8,e,!t)},decode:r=>(ui("radix2.decode",r),Uint8Array.from(Go(r,e,8,t)))}}var xi=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",pi=(e,t)=>{Ie("base64",e);let r=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=t?"base64url":"base64";if(e.length>0&&!r.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:n,lastChunkHandling:"strict"})},Xo=xi?{encode(e){return ai(e),e.toBase64()},decode(e){return pi(e,!1)}}:li(gi(6),di("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),bi(6),hi(""));var yi=new TextDecoder("utf-8"),wi=new TextEncoder,mi=1,Ei=65535;function sr(e,t){let r=jo.getSharedSecret(e,At("02"+t)).subarray(1,33);return $o(re,r,wi.encode("nip44-v2"))}function Bi(e,t){let r=Po(re,e,t,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function vi(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;let t=1<<Math.floor(Math.log2(e-1))+1,r=t<=256?32:t/8;return r*(Math.floor((e-1)/r)+1)}function Ai(e){let t=new DataView(e.buffer).getUint16(0),r=e.subarray(2,2+t);if(t<mi||t>Ei||r.length!==t||e.length!==2+vi(t))throw new Error("invalid padding");return yi.decode(r)}function Si(e,t,r){if(r.length!==32)throw new Error("AAD associated data must be 32 bytes");let n=ft(r,t);return Tt(re,e,n)}function Ii(e){if(typeof e!="string")throw new Error("payload must be a valid string");let t=e.length;if(t<132||t>87472)throw new Error("invalid payload length: "+t);if(e[0]==="#")throw new Error("unknown encryption version");let r;try{r=Xo.decode(e)}catch(s){throw new Error("invalid base64: "+s.message)}let n=r.length;if(n<99||n>65603)throw new Error("invalid data length: "+n);let o=r[0];if(o!==2)throw new Error("unknown encryption version "+o);return{nonce:r.subarray(1,33),ciphertext:r.subarray(33,-32),mac:r.subarray(-32)}}function ir(e,t){let{nonce:r,ciphertext:n,mac:o}=Ii(e),{chacha_key:s,chacha_nonce:i,hmac_key:c}=Bi(t,r),f=Si(c,n,r);if(!Pe(f,o))throw new Error("invalid MAC");let u=Hn(s,i,n);return Ai(u)}function Li(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function _i(){let e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function rn(e,t){let r=e.find(n=>n[0]===t);return r?r[1]:void 0}function Lt(e){let t=new Uint8Array(e.length/2);for(let r=0;r<t.length;r++)t[r]=parseInt(e.substr(r*2,2),16);return t}async function Ri(e){if(!e.id||!e.pubkey||!e.sig||!e.tags||e.kind!==30470||!/^[0-9a-f]{128}$/i.test(e.sig)||!/^[0-9a-f]{64}$/i.test(e.pubkey)||!/^[0-9a-f]{64}$/i.test(e.id)||e.tags.length>100||e.content.length>65536||e.tags.some(i=>i.some(c=>c.length>1024)))return!1;let t=e.tags.map(i=>i[0]);if(!t.includes("tier")||!t.includes("age-range")||!t.includes("entity-type"))return!1;let r=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),n=new TextEncoder,o=Sn(n.encode(r));if(st(o)!==e.id.toLowerCase())return!1;try{let i=Lt(e.sig),c=Lt(e.id),f=Lt(e.pubkey);return ye.verify(i,c,f)}catch{return!1}}function Ui(e,t){if(e===t||e==="18+"&&t==="18+")return!0;let r=["0-3","4-7","8-12","13-17","18+"],n=r.indexOf(e),o=r.indexOf(t);return n===-1||o===-1?!1:t==="18+"?e==="18+":e===t}async function Oi(e,t){if(t==null||!/^https:\/\//i.test(t)||!/^[0-9a-f]{64}$/i.test(e))return null;try{let r=await fetch(`${t}/status/${e}`,{signal:AbortSignal.timeout(5e3)});if(!r.ok)return null;let n=await r.json();if(typeof n!="object"||n===null)return null;let o=n;return{confirmed:o.confirmed===!0,method:["A","B","C","D"].includes(o.method)?o.method:null,profession:typeof o.profession=="string"?o.profession:void 0,jurisdiction:typeof o.jurisdiction=="string"?o.jurisdiction:void 0}}catch{return null}}async function Jo(e,t){if(!["0-3","4-7","8-12","13-17","18+"].includes(e))return{verified:!1,ageRange:null,tier:null,entityType:null,credentialId:null,verifierPubkey:null,verifierConfirmed:null,verifierMethod:null,issuedAt:null,expiresAt:null,error:"invalid-age-range"};let n={requiredAgeRange:e,relayUrl:t?.relayUrl||"wss://relay.damus.io",theme:t?.theme||"auto",timeout:t?.timeout||12e4,verifierCheckUrl:t?.verifierCheckUrl!==void 0?t.verifierCheckUrl:"https://verify.signet.forgesworn.dev",acceptUnconfirmed:t?.acceptUnconfirmed||!1,...t};n.timeout=Math.max(5e3,Math.min(n.timeout??12e4,6e5));let o=_i(),s={type:"signet-verify-request",requestId:o,requiredAgeRange:n.requiredAgeRange,relayUrl:n.relayUrl,timestamp:Math.floor(Date.now()/1e3)},i=JSON.stringify(s),c=btoa(i);return new Promise(f=>{let u=document.createElement("style");u.textContent="#signet-verify-dialog::backdrop{background:rgba(0,0,0,0.7)}",document.head.appendChild(u);let h=n.theme==="dark"||n.theme==="auto"&&window.matchMedia("(prefers-color-scheme: dark)").matches,g=h?"#1a1a2e":"#ffffff",b=h?"#e0e0e0":"#1a1a2e",d=h?"#888":"#666",w=document.createElement("dialog");w.id="signet-verify-dialog",w.style.cssText=`border:none;border-radius:16px;padding:32px;max-width:380px;width:90%;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,0.3);background:${g};color:${b};font-family:system-ui,-apple-system,sans-serif;`,w.innerHTML=`
|
|
2
|
+
<h2 style="margin:0 0 8px;font-size:1.3rem;">Verify your age with Signet</h2>
|
|
3
|
+
<p style="margin:0 0 24px;color:${d};font-size:0.9rem;">Scan this QR code with your Signet app to prove you are ${Li(e)}. No personal data is shared.</p>
|
|
4
|
+
<div id="signet-qr" style="display:flex;justify-content:center;margin-bottom:24px;"></div>
|
|
5
|
+
<p style="margin:0 0 16px;color:${d};font-size:0.8rem;">Waiting for verification...</p>
|
|
6
|
+
<button id="signet-cancel" style="background:none;border:1px solid ${d};color:${b};padding:10px 24px;border-radius:8px;cursor:pointer;font-size:0.9rem;">Cancel</button>
|
|
7
|
+
`,document.body.appendChild(w),w.showModal();let B=w.querySelector("#signet-qr");if(B){let _=document.createElement("div");_.style.cssText=`width:200px;height:200px;background:${h?"#2a2a3e":"#f0f0f0"};border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:0.75rem;color:${d};word-break:break-all;padding:12px;`,_.textContent=`signet:verify:${c.slice(0,40)}...`,B.appendChild(_)}let S=new BroadcastChannel("signet-verify-"+o);w.querySelector("#signet-cancel")?.addEventListener("click",()=>{S.close(),w.close(),w.remove(),u.remove(),f({verified:!1,ageRange:null,tier:null,entityType:null,credentialId:null,verifierPubkey:null,verifierConfirmed:null,verifierMethod:null,issuedAt:null,expiresAt:null,error:"cancelled"})}),S.onmessage=async _=>{let V=_.data;if(typeof V!="object"||V===null)return;let N=V;if(N.type!=="signet-verify-response"||N.requestId!==o||!N.credential||typeof N.credential!="object"||!Array.isArray(N.credential.tags))return;let q=N.credential,C=await Ri(q),P=rn(q.tags,"age-range"),Y=rn(q.tags,"tier"),z=rn(q.tags,"entity-type"),R=rn(q.tags,"expires"),K=P?Ui(P,n.requiredAgeRange):!1,M=await Oi(q.pubkey,n.verifierCheckUrl),L=M?.confirmed??null,p=M?.method??null,l=n.acceptUnconfirmed||L===!0;w.close(),w.remove(),u.remove(),S.close();let a=Y?parseInt(Y,10):null,x=R?parseInt(R,10):null,m=Math.floor(Date.now()/1e3),v=x===null||!isNaN(x)&&x>m,y;C?v?K?l||(y=L===!1?"verifier-not-confirmed":"verifier-check-unavailable"):y="age-range-not-met":y="credential-expired":y="invalid-credential",f({verified:C&&v&&K&&l,ageRange:P||null,tier:a!==null&&!isNaN(a)?a:null,entityType:z||null,credentialId:q.id,verifierPubkey:q.pubkey,verifierConfirmed:L,verifierMethod:p,issuedAt:q.created_at,expiresAt:x!==null&&!isNaN(x)?x:null,error:y})},setTimeout(()=>{w.close(),w.remove(),u.remove(),S.close(),f({verified:!1,ageRange:null,tier:null,entityType:null,credentialId:null,verifierPubkey:null,verifierConfirmed:null,verifierMethod:null,issuedAt:null,expiresAt:null,error:"timeout"})},n.timeout)})}function cr(e){let t=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),r=Sn(new TextEncoder().encode(t));return st(r)}async function Hi(e,t){try{let r=sr(t,e.pubkey),n=ir(e.content,r),o=JSON.parse(n);if(typeof o!="object"||o===null)return null;let s=o;if(s.kind!==13||typeof s.pubkey!="string"||!/^[0-9a-f]{64}$/i.test(s.pubkey)||typeof s.created_at!="number"||!Array.isArray(s.tags)||typeof s.content!="string"||typeof s.id!="string"||!/^[0-9a-f]{64}$/i.test(s.id)||typeof s.sig!="string"||!/^[0-9a-f]{128}$/i.test(s.sig)||cr({pubkey:s.pubkey,created_at:s.created_at,kind:13,tags:s.tags,content:s.content})!==s.id.toLowerCase())return null;let c=Lt(s.sig),f=Lt(s.id),u=Lt(s.pubkey);if(!ye.verify(c,f,u))return null;let h=sr(t,s.pubkey),g=ir(s.content,h),b=JSON.parse(g);if(typeof b!="object"||b===null)return null;let d=b;if(typeof d.pubkey!="string"||d.pubkey!==s.pubkey||typeof d.kind!="number"||typeof d.created_at!="number"||!Array.isArray(d.tags)||typeof d.content!="string")return null;let w=typeof d.id=="string"?d.id:cr({pubkey:d.pubkey,created_at:d.created_at,kind:d.kind,tags:d.tags,content:d.content});return{pubkey:d.pubkey,id:w,kind:d.kind,created_at:d.created_at,tags:d.tags,content:d.content}}catch{return null}}async function Qo(e){if(!/^[0-9a-f]{64}$/i.test(e.requestId))throw new Error("invalid-request-id");if(!(e.sessionPrivKey instanceof Uint8Array)||e.sessionPrivKey.length!==32)throw new Error("invalid-session-privkey");if(!/^wss:\/\//i.test(e.relayUrl)&&!/^ws:\/\/(localhost|127\.0\.0\.1)([:\/]|$)/i.test(e.relayUrl))throw new Error("invalid-relay-url");if(typeof e.expectedOrigin!="string"||e.expectedOrigin.length===0)throw new Error("invalid-expected-origin");let t=st(ye.getPublicKey(e.sessionPrivKey)),r=Math.max(5e3,Math.min(e.timeout??12e4,6e5)),n=e.requestId.toLowerCase(),o=e.expectedOrigin;return new Promise((s,i)=>{let c=`sa-${Math.random().toString(36).slice(2,12)}`,f=!1,u;try{u=new WebSocket(e.relayUrl)}catch{i(new Error("relay-error"));return}let h=b=>{if(!f){f=!0,clearTimeout(g);try{u.close()}catch{}b()}},g=setTimeout(()=>{h(()=>i(new Error("timeout")))},r);u.onopen=()=>{let b=Math.floor(Date.now()/1e3)-60;u.send(JSON.stringify(["REQ",c,{kinds:[1059],"#p":[t],since:b}]))},u.onmessage=async b=>{if(f)return;let d;try{d=JSON.parse(typeof b.data=="string"?b.data:"")}catch{return}if(!Array.isArray(d)||d[0]!=="EVENT"||d[1]!==c)return;let w=d[2];if(typeof w!="object"||w===null)return;let B=w;if(B.kind!==1059||typeof B.pubkey!="string"||typeof B.content!="string")return;let S=await Hi({pubkey:B.pubkey,content:B.content},e.sessionPrivKey);if(!S||S.kind!==29999)return;let _=S.tags.find(p=>p[0]==="session");if(!_||_[1]!==n)return;let V=S.tags.find(p=>p[0]==="status");if(V?.[1]==="rejected"){h(()=>i(new Error("denied")));return}if(V?.[1]!=="approved"||Math.abs(Date.now()/1e3-S.created_at)>300)return;let q;try{let p=JSON.parse(S.content);if(typeof p!="object"||p===null)return;q=p}catch{return}if(q.type!=="signet-auth-response"||q.requestId!==n||typeof q.authEvent!="object"||q.authEvent===null)return;let C=q.authEvent;if(typeof C.id!="string"||!/^[0-9a-f]{64}$/i.test(C.id)||typeof C.pubkey!="string"||!/^[0-9a-f]{64}$/i.test(C.pubkey)||typeof C.sig!="string"||!/^[0-9a-f]{128}$/i.test(C.sig)||C.kind!==21236||typeof C.created_at!="number"||!Array.isArray(C.tags)||typeof C.content!="string"||C.pubkey.toLowerCase()!==S.pubkey.toLowerCase()||cr({pubkey:C.pubkey,created_at:C.created_at,kind:21236,tags:C.tags,content:C.content})!==C.id.toLowerCase())return;let Y=!1;try{let p=Lt(C.sig),l=Lt(C.id),a=Lt(C.pubkey);Y=ye.verify(p,l,a)}catch{Y=!1}if(!Y)return;let z=C.tags,R=z.find(p=>Array.isArray(p)&&p[0]==="challenge");if(!R||typeof R[1]!="string"||R[1].toLowerCase()!==n)return;let K=z.find(p=>Array.isArray(p)&&p[0]==="origin");if(!K||K[1]!==o||Math.abs(Date.now()/1e3-C.created_at)>300)return;let L={id:C.id.toLowerCase(),pubkey:C.pubkey.toLowerCase(),kind:21236,created_at:C.created_at,tags:z,content:C.content,sig:C.sig};h(()=>s({pubkey:L.pubkey,authEvent:L,credential:q.credential,createdAt:L.created_at}))},u.onerror=()=>{h(()=>i(new Error("relay-error")))}})}typeof window<"u"&&(window.Signet={verifyAge:Jo,waitForAuthResponse:Qo});return ss(ki);})();
|
|
8
|
+
/*! Bundled license information:
|
|
9
|
+
|
|
10
|
+
@noble/hashes/esm/utils.js:
|
|
11
|
+
@noble/hashes/utils.js:
|
|
12
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
13
|
+
|
|
14
|
+
@noble/curves/esm/utils.js:
|
|
15
|
+
@noble/curves/esm/abstract/modular.js:
|
|
16
|
+
@noble/curves/esm/abstract/curve.js:
|
|
17
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
18
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
19
|
+
@noble/curves/esm/secp256k1.js:
|
|
20
|
+
@noble/curves/utils.js:
|
|
21
|
+
@noble/curves/abstract/modular.js:
|
|
22
|
+
@noble/curves/abstract/curve.js:
|
|
23
|
+
@noble/curves/abstract/weierstrass.js:
|
|
24
|
+
@noble/curves/secp256k1.js:
|
|
25
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
26
|
+
|
|
27
|
+
@noble/ciphers/utils.js:
|
|
28
|
+
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
29
|
+
|
|
30
|
+
@scure/base/index.js:
|
|
31
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
32
|
+
*/
|
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signet Verify SDK — website age verification and cross-device Sign-in-with-Signet.
|
|
3
|
+
*
|
|
4
|
+
* ESM / bundler usage (npm):
|
|
5
|
+
* import { verifyAge, waitForAuthResponse } from 'signet-verify';
|
|
6
|
+
*
|
|
7
|
+
* Script-tag / CDN usage (IIFE bundle exposes `window.Signet`):
|
|
8
|
+
* <script src="https://cdn.signet.forgesworn.dev/signet-verify.iife.js"></script>
|
|
9
|
+
* <script>
|
|
10
|
+
* const result = await Signet.verifyAge('18+');
|
|
11
|
+
* if (result.verified) { // allow access }
|
|
12
|
+
* </script>
|
|
13
|
+
*/
|
|
14
|
+
// Escape HTML special characters to prevent XSS in innerHTML
|
|
15
|
+
function escapeHtml(str) {
|
|
16
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
17
|
+
}
|
|
18
|
+
// Generate a random request ID
|
|
19
|
+
function generateRequestId() {
|
|
20
|
+
const bytes = new Uint8Array(16);
|
|
21
|
+
crypto.getRandomValues(bytes);
|
|
22
|
+
return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
|
|
23
|
+
}
|
|
24
|
+
// Extract a tag value from a Nostr event
|
|
25
|
+
function getTagValue(tags, key) {
|
|
26
|
+
const tag = tags.find(t => t[0] === key);
|
|
27
|
+
return tag ? tag[1] : undefined;
|
|
28
|
+
}
|
|
29
|
+
// BIP-340 Schnorr signature verification via @noble/curves (bundled by esbuild)
|
|
30
|
+
import { schnorr } from '@noble/curves/secp256k1';
|
|
31
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
32
|
+
import { bytesToHex } from '@noble/hashes/utils';
|
|
33
|
+
// NIP-44 v2 decrypt for NIP-17 gift-wrap unwrapping (cross-device auth flow)
|
|
34
|
+
import { decrypt as nip44Decrypt, getConversationKey } from 'nostr-tools/nip44';
|
|
35
|
+
function hexToBytes(hex) {
|
|
36
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
37
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
38
|
+
bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
39
|
+
}
|
|
40
|
+
return bytes;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify a Nostr event's Schnorr signature (BIP-340).
|
|
44
|
+
* Checks: structural validity, event ID hash, and cryptographic signature.
|
|
45
|
+
*/
|
|
46
|
+
async function verifyEventSignature(event) {
|
|
47
|
+
// Structural validation: check field formats
|
|
48
|
+
if (!event.id || !event.pubkey || !event.sig || !event.tags || event.kind !== 30470) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// sig must be exactly 128 hex chars (64-byte Schnorr signature)
|
|
52
|
+
if (!/^[0-9a-f]{128}$/i.test(event.sig))
|
|
53
|
+
return false;
|
|
54
|
+
// pubkey must be exactly 64 hex chars (32-byte x-only public key)
|
|
55
|
+
if (!/^[0-9a-f]{64}$/i.test(event.pubkey))
|
|
56
|
+
return false;
|
|
57
|
+
// id must be exactly 64 hex chars (32-byte SHA-256 hash)
|
|
58
|
+
if (!/^[0-9a-f]{64}$/i.test(event.id))
|
|
59
|
+
return false;
|
|
60
|
+
// Field-size bounds
|
|
61
|
+
if (event.tags.length > 100)
|
|
62
|
+
return false;
|
|
63
|
+
if (event.content.length > 65536)
|
|
64
|
+
return false;
|
|
65
|
+
if (event.tags.some(t => t.some(v => v.length > 1024)))
|
|
66
|
+
return false;
|
|
67
|
+
// Required tags must be present
|
|
68
|
+
const tagKeys = event.tags.map(t => t[0]);
|
|
69
|
+
if (!tagKeys.includes('tier'))
|
|
70
|
+
return false;
|
|
71
|
+
if (!tagKeys.includes('age-range'))
|
|
72
|
+
return false;
|
|
73
|
+
if (!tagKeys.includes('entity-type'))
|
|
74
|
+
return false;
|
|
75
|
+
// Verify event ID matches the SHA-256 hash of the serialized event
|
|
76
|
+
const serialized = JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content]);
|
|
77
|
+
const encoder = new TextEncoder();
|
|
78
|
+
const hashBytes = sha256(encoder.encode(serialized));
|
|
79
|
+
const expectedId = bytesToHex(hashBytes);
|
|
80
|
+
if (expectedId !== event.id.toLowerCase())
|
|
81
|
+
return false;
|
|
82
|
+
// BIP-340 Schnorr signature verification
|
|
83
|
+
try {
|
|
84
|
+
const sigBytes = hexToBytes(event.sig);
|
|
85
|
+
const idBytes = hexToBytes(event.id);
|
|
86
|
+
const pubkeyBytes = hexToBytes(event.pubkey);
|
|
87
|
+
return schnorr.verify(sigBytes, idBytes, pubkeyBytes);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Check if the credential's age range satisfies the required range
|
|
94
|
+
function ageRangeSatisfies(credentialRange, requiredRange) {
|
|
95
|
+
// Simple range matching
|
|
96
|
+
if (credentialRange === requiredRange)
|
|
97
|
+
return true;
|
|
98
|
+
// '18+' satisfies any adult requirement
|
|
99
|
+
if (credentialRange === '18+' && requiredRange === '18+')
|
|
100
|
+
return true;
|
|
101
|
+
// Child ranges: credential must exactly match or be within required
|
|
102
|
+
const ranges = ['0-3', '4-7', '8-12', '13-17', '18+'];
|
|
103
|
+
const credIdx = ranges.indexOf(credentialRange);
|
|
104
|
+
const reqIdx = ranges.indexOf(requiredRange);
|
|
105
|
+
if (credIdx === -1 || reqIdx === -1)
|
|
106
|
+
return false;
|
|
107
|
+
// For '18+' requirement, credential must be '18+'
|
|
108
|
+
if (requiredRange === '18+')
|
|
109
|
+
return credentialRange === '18+';
|
|
110
|
+
// For child requirements, credential range must match
|
|
111
|
+
return credentialRange === requiredRange;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check a verifier's status against the verification bot.
|
|
115
|
+
* Returns { confirmed, method } or null if the check fails/is skipped.
|
|
116
|
+
*/
|
|
117
|
+
async function checkVerifierStatus(verifierPubkey, checkUrl) {
|
|
118
|
+
if (checkUrl === null || checkUrl === undefined)
|
|
119
|
+
return null;
|
|
120
|
+
if (!/^https:\/\//i.test(checkUrl))
|
|
121
|
+
return null;
|
|
122
|
+
if (!/^[0-9a-f]{64}$/i.test(verifierPubkey))
|
|
123
|
+
return null;
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetch(`${checkUrl}/status/${verifierPubkey}`, {
|
|
126
|
+
signal: AbortSignal.timeout(5000), // 5 second timeout — don't block the UX
|
|
127
|
+
});
|
|
128
|
+
if (!response.ok)
|
|
129
|
+
return null;
|
|
130
|
+
const data = await response.json();
|
|
131
|
+
if (typeof data !== 'object' || data === null)
|
|
132
|
+
return null;
|
|
133
|
+
const obj = data;
|
|
134
|
+
return {
|
|
135
|
+
confirmed: obj.confirmed === true,
|
|
136
|
+
method: (['A', 'B', 'C', 'D'].includes(obj.method) ? obj.method : null),
|
|
137
|
+
profession: typeof obj.profession === 'string' ? obj.profession : undefined,
|
|
138
|
+
jurisdiction: typeof obj.jurisdiction === 'string' ? obj.jurisdiction : undefined,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Bot unreachable — return null (unknown), don't block verification
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Main verification function.
|
|
148
|
+
* Shows a modal with QR code, waits for the user's app to respond.
|
|
149
|
+
*/
|
|
150
|
+
export async function verifyAge(requiredAgeRange, options) {
|
|
151
|
+
const VALID_AGE_RANGES = ['0-3', '4-7', '8-12', '13-17', '18+'];
|
|
152
|
+
if (!VALID_AGE_RANGES.includes(requiredAgeRange)) {
|
|
153
|
+
return { verified: false, ageRange: null, tier: null, entityType: null, credentialId: null, verifierPubkey: null, verifierConfirmed: null, verifierMethod: null, issuedAt: null, expiresAt: null, error: 'invalid-age-range' };
|
|
154
|
+
}
|
|
155
|
+
const opts = {
|
|
156
|
+
requiredAgeRange,
|
|
157
|
+
relayUrl: options?.relayUrl || 'wss://relay.damus.io',
|
|
158
|
+
theme: options?.theme || 'auto',
|
|
159
|
+
timeout: options?.timeout || 120000,
|
|
160
|
+
verifierCheckUrl: options?.verifierCheckUrl !== undefined ? options.verifierCheckUrl : 'https://verify.signet.forgesworn.dev',
|
|
161
|
+
acceptUnconfirmed: options?.acceptUnconfirmed || false,
|
|
162
|
+
...options,
|
|
163
|
+
};
|
|
164
|
+
opts.timeout = Math.max(5000, Math.min(opts.timeout ?? 120000, 600000));
|
|
165
|
+
const requestId = generateRequestId();
|
|
166
|
+
const request = {
|
|
167
|
+
type: 'signet-verify-request',
|
|
168
|
+
requestId,
|
|
169
|
+
requiredAgeRange: opts.requiredAgeRange,
|
|
170
|
+
relayUrl: opts.relayUrl,
|
|
171
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
172
|
+
};
|
|
173
|
+
// Encode the request as a URL for QR code
|
|
174
|
+
const requestPayload = JSON.stringify(request);
|
|
175
|
+
const requestBase64 = btoa(requestPayload);
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
// Inject ::backdrop style for the native <dialog> element
|
|
178
|
+
const style = document.createElement('style');
|
|
179
|
+
style.textContent = '#signet-verify-dialog::backdrop{background:rgba(0,0,0,0.7)}';
|
|
180
|
+
document.head.appendChild(style);
|
|
181
|
+
const isDark = opts.theme === 'dark' || (opts.theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
182
|
+
const bg = isDark ? '#1a1a2e' : '#ffffff';
|
|
183
|
+
const fg = isDark ? '#e0e0e0' : '#1a1a2e';
|
|
184
|
+
const muted = isDark ? '#888' : '#666';
|
|
185
|
+
// Use <dialog> for native focus trap and top-layer placement
|
|
186
|
+
const dialog = document.createElement('dialog');
|
|
187
|
+
dialog.id = 'signet-verify-dialog';
|
|
188
|
+
dialog.style.cssText = `border:none;border-radius:16px;padding:32px;max-width:380px;width:90%;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,0.3);background:${bg};color:${fg};font-family:system-ui,-apple-system,sans-serif;`;
|
|
189
|
+
dialog.innerHTML = `
|
|
190
|
+
<h2 style="margin:0 0 8px;font-size:1.3rem;">Verify your age with Signet</h2>
|
|
191
|
+
<p style="margin:0 0 24px;color:${muted};font-size:0.9rem;">Scan this QR code with your Signet app to prove you are ${escapeHtml(requiredAgeRange)}. No personal data is shared.</p>
|
|
192
|
+
<div id="signet-qr" style="display:flex;justify-content:center;margin-bottom:24px;"></div>
|
|
193
|
+
<p style="margin:0 0 16px;color:${muted};font-size:0.8rem;">Waiting for verification...</p>
|
|
194
|
+
<button id="signet-cancel" style="background:none;border:1px solid ${muted};color:${fg};padding:10px 24px;border-radius:8px;cursor:pointer;font-size:0.9rem;">Cancel</button>
|
|
195
|
+
`;
|
|
196
|
+
document.body.appendChild(dialog);
|
|
197
|
+
dialog.showModal();
|
|
198
|
+
// Generate QR code (simple SVG-based, no dependency)
|
|
199
|
+
const qrContainer = dialog.querySelector('#signet-qr');
|
|
200
|
+
if (qrContainer) {
|
|
201
|
+
// For MVP: show the request payload as text that can be copied
|
|
202
|
+
// A proper QR library should be bundled for production
|
|
203
|
+
const qrPlaceholder = document.createElement('div');
|
|
204
|
+
qrPlaceholder.style.cssText = `width:200px;height:200px;background:${isDark ? '#2a2a3e' : '#f0f0f0'};border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:0.75rem;color:${muted};word-break:break-all;padding:12px;`;
|
|
205
|
+
qrPlaceholder.textContent = `signet:verify:${requestBase64.slice(0, 40)}...`;
|
|
206
|
+
qrContainer.appendChild(qrPlaceholder);
|
|
207
|
+
}
|
|
208
|
+
// Listen for response via BroadcastChannel (same-device, request-specific channel)
|
|
209
|
+
const channel = new BroadcastChannel('signet-verify-' + requestId);
|
|
210
|
+
// Cancel handler — scoped to the dialog
|
|
211
|
+
dialog.querySelector('#signet-cancel')?.addEventListener('click', () => {
|
|
212
|
+
channel.close();
|
|
213
|
+
dialog.close();
|
|
214
|
+
dialog.remove();
|
|
215
|
+
style.remove();
|
|
216
|
+
resolve({ verified: false, ageRange: null, tier: null, entityType: null, credentialId: null, verifierPubkey: null, verifierConfirmed: null, verifierMethod: null, issuedAt: null, expiresAt: null, error: 'cancelled' });
|
|
217
|
+
});
|
|
218
|
+
channel.onmessage = async (event) => {
|
|
219
|
+
const data = event.data;
|
|
220
|
+
if (typeof data !== 'object' || data === null)
|
|
221
|
+
return;
|
|
222
|
+
const response = data;
|
|
223
|
+
if (response.type !== 'signet-verify-response' || response.requestId !== requestId)
|
|
224
|
+
return;
|
|
225
|
+
if (!response.credential || typeof response.credential !== 'object' || !Array.isArray(response.credential.tags))
|
|
226
|
+
return;
|
|
227
|
+
const credential = response.credential;
|
|
228
|
+
// Verify the credential
|
|
229
|
+
const valid = await verifyEventSignature(credential);
|
|
230
|
+
const ageRange = getTagValue(credential.tags, 'age-range');
|
|
231
|
+
const tier = getTagValue(credential.tags, 'tier');
|
|
232
|
+
const entityType = getTagValue(credential.tags, 'entity-type');
|
|
233
|
+
const expires = getTagValue(credential.tags, 'expires');
|
|
234
|
+
const satisfied = ageRange ? ageRangeSatisfies(ageRange, opts.requiredAgeRange) : false;
|
|
235
|
+
// Check verifier status against the verification bot
|
|
236
|
+
const verifierStatus = await checkVerifierStatus(credential.pubkey, opts.verifierCheckUrl);
|
|
237
|
+
const verifierConfirmed = verifierStatus?.confirmed ?? null;
|
|
238
|
+
const verifierMethod = verifierStatus?.method ?? null;
|
|
239
|
+
// By default, verified is true only when:
|
|
240
|
+
// 1. Credential signature is valid
|
|
241
|
+
// 2. Age range satisfies requirement
|
|
242
|
+
// 3. Verifier is confirmed (unless acceptUnconfirmed is true)
|
|
243
|
+
const verifierOk = opts.acceptUnconfirmed || verifierConfirmed === true;
|
|
244
|
+
dialog.close();
|
|
245
|
+
dialog.remove();
|
|
246
|
+
style.remove();
|
|
247
|
+
channel.close();
|
|
248
|
+
const tierValue = tier ? parseInt(tier, 10) : null;
|
|
249
|
+
const expiresValue = expires ? parseInt(expires, 10) : null;
|
|
250
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
251
|
+
const notExpired = expiresValue === null || (!isNaN(expiresValue) && expiresValue > nowSec);
|
|
252
|
+
let error;
|
|
253
|
+
if (!valid)
|
|
254
|
+
error = 'invalid-credential';
|
|
255
|
+
else if (!notExpired)
|
|
256
|
+
error = 'credential-expired';
|
|
257
|
+
else if (!satisfied)
|
|
258
|
+
error = 'age-range-not-met';
|
|
259
|
+
else if (!verifierOk)
|
|
260
|
+
error = verifierConfirmed === false ? 'verifier-not-confirmed' : 'verifier-check-unavailable';
|
|
261
|
+
resolve({
|
|
262
|
+
verified: valid && notExpired && satisfied && verifierOk,
|
|
263
|
+
ageRange: ageRange || null,
|
|
264
|
+
tier: (tierValue !== null && !isNaN(tierValue)) ? tierValue : null,
|
|
265
|
+
entityType: entityType || null,
|
|
266
|
+
credentialId: credential.id,
|
|
267
|
+
verifierPubkey: credential.pubkey,
|
|
268
|
+
verifierConfirmed,
|
|
269
|
+
verifierMethod,
|
|
270
|
+
issuedAt: credential.created_at,
|
|
271
|
+
expiresAt: (expiresValue !== null && !isNaN(expiresValue)) ? expiresValue : null,
|
|
272
|
+
error,
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
// Timeout
|
|
276
|
+
setTimeout(() => {
|
|
277
|
+
dialog.close();
|
|
278
|
+
dialog.remove();
|
|
279
|
+
style.remove();
|
|
280
|
+
channel.close();
|
|
281
|
+
resolve({ verified: false, ageRange: null, tier: null, entityType: null, credentialId: null, verifierPubkey: null, verifierConfirmed: null, verifierMethod: null, issuedAt: null, expiresAt: null, error: 'timeout' });
|
|
282
|
+
}, opts.timeout);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
// Compute a NIP-01 event ID: SHA-256 of the canonical serialisation.
|
|
286
|
+
function computeNostrEventId(event) {
|
|
287
|
+
const serialised = JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content]);
|
|
288
|
+
const hash = sha256(new TextEncoder().encode(serialised));
|
|
289
|
+
return bytesToHex(hash);
|
|
290
|
+
}
|
|
291
|
+
// NIP-17 unwrap: kind-1059 wrap → kind-13 seal (verified) → inner rumor event.
|
|
292
|
+
// Returns the rumor or null if any step fails (decrypt error, malformed, identity mismatch).
|
|
293
|
+
async function unwrapGiftWrap(wrap, sessionPrivKey) {
|
|
294
|
+
try {
|
|
295
|
+
// Decrypt wrap → seal
|
|
296
|
+
const wrapConvKey = getConversationKey(sessionPrivKey, wrap.pubkey);
|
|
297
|
+
const sealJson = nip44Decrypt(wrap.content, wrapConvKey);
|
|
298
|
+
const sealParsed = JSON.parse(sealJson);
|
|
299
|
+
if (typeof sealParsed !== 'object' || sealParsed === null)
|
|
300
|
+
return null;
|
|
301
|
+
const seal = sealParsed;
|
|
302
|
+
if (seal.kind !== 13)
|
|
303
|
+
return null;
|
|
304
|
+
if (typeof seal.pubkey !== 'string' || !/^[0-9a-f]{64}$/i.test(seal.pubkey))
|
|
305
|
+
return null;
|
|
306
|
+
if (typeof seal.created_at !== 'number')
|
|
307
|
+
return null;
|
|
308
|
+
if (!Array.isArray(seal.tags))
|
|
309
|
+
return null;
|
|
310
|
+
if (typeof seal.content !== 'string')
|
|
311
|
+
return null;
|
|
312
|
+
if (typeof seal.id !== 'string' || !/^[0-9a-f]{64}$/i.test(seal.id))
|
|
313
|
+
return null;
|
|
314
|
+
if (typeof seal.sig !== 'string' || !/^[0-9a-f]{128}$/i.test(seal.sig))
|
|
315
|
+
return null;
|
|
316
|
+
// Verify seal event ID matches its canonical hash (tamper check)
|
|
317
|
+
const expectedSealId = computeNostrEventId({
|
|
318
|
+
pubkey: seal.pubkey,
|
|
319
|
+
created_at: seal.created_at,
|
|
320
|
+
kind: 13,
|
|
321
|
+
tags: seal.tags,
|
|
322
|
+
content: seal.content,
|
|
323
|
+
});
|
|
324
|
+
if (expectedSealId !== seal.id.toLowerCase())
|
|
325
|
+
return null;
|
|
326
|
+
// Verify seal Schnorr signature — proves it came from the claimed sender.
|
|
327
|
+
// (The rumor itself is unsigned per NIP-59; the seal's signature is the identity anchor.)
|
|
328
|
+
const sealSigBytes = hexToBytes(seal.sig);
|
|
329
|
+
const sealIdBytes = hexToBytes(seal.id);
|
|
330
|
+
const sealPubBytes = hexToBytes(seal.pubkey);
|
|
331
|
+
if (!schnorr.verify(sealSigBytes, sealIdBytes, sealPubBytes))
|
|
332
|
+
return null;
|
|
333
|
+
// Decrypt seal → rumor
|
|
334
|
+
const sealConvKey = getConversationKey(sessionPrivKey, seal.pubkey);
|
|
335
|
+
const rumorJson = nip44Decrypt(seal.content, sealConvKey);
|
|
336
|
+
const rumorParsed = JSON.parse(rumorJson);
|
|
337
|
+
if (typeof rumorParsed !== 'object' || rumorParsed === null)
|
|
338
|
+
return null;
|
|
339
|
+
const rumor = rumorParsed;
|
|
340
|
+
if (typeof rumor.pubkey !== 'string')
|
|
341
|
+
return null;
|
|
342
|
+
// Identity binding: rumor sender must equal seal sender.
|
|
343
|
+
if (rumor.pubkey !== seal.pubkey)
|
|
344
|
+
return null;
|
|
345
|
+
if (typeof rumor.kind !== 'number')
|
|
346
|
+
return null;
|
|
347
|
+
if (typeof rumor.created_at !== 'number')
|
|
348
|
+
return null;
|
|
349
|
+
if (!Array.isArray(rumor.tags))
|
|
350
|
+
return null;
|
|
351
|
+
if (typeof rumor.content !== 'string')
|
|
352
|
+
return null;
|
|
353
|
+
// Rumor may or may not carry an id field; compute if absent.
|
|
354
|
+
const rumorId = typeof rumor.id === 'string'
|
|
355
|
+
? rumor.id
|
|
356
|
+
: computeNostrEventId({
|
|
357
|
+
pubkey: rumor.pubkey,
|
|
358
|
+
created_at: rumor.created_at,
|
|
359
|
+
kind: rumor.kind,
|
|
360
|
+
tags: rumor.tags,
|
|
361
|
+
content: rumor.content,
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
pubkey: rumor.pubkey,
|
|
365
|
+
id: rumorId,
|
|
366
|
+
kind: rumor.kind,
|
|
367
|
+
created_at: rumor.created_at,
|
|
368
|
+
tags: rumor.tags,
|
|
369
|
+
content: rumor.content,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Wait for a cross-device Sign-in-with-Signet response on a Nostr relay.
|
|
378
|
+
*
|
|
379
|
+
* Consumer workflow: generate a session keypair, put the pubkey in the auth URL
|
|
380
|
+
* via the `sessionPubkey` param alongside `relay`, render the QR, then call this
|
|
381
|
+
* function with the matching private key. When the user approves on their phone,
|
|
382
|
+
* the Signet app publishes a NIP-17 gift-wrapped response to the relay and this
|
|
383
|
+
* function resolves with the verified auth result.
|
|
384
|
+
*
|
|
385
|
+
* Rejects with `Error(message)` where message is one of:
|
|
386
|
+
* - `'denied'` — user rejected the request
|
|
387
|
+
* - `'timeout'` — no valid response within the timeout
|
|
388
|
+
* - `'relay-error'` — WebSocket connection failure
|
|
389
|
+
* - `'invalid-request-id'` / `'invalid-session-privkey'` / `'invalid-relay-url'` — bad input
|
|
390
|
+
*/
|
|
391
|
+
export async function waitForAuthResponse(options) {
|
|
392
|
+
if (!/^[0-9a-f]{64}$/i.test(options.requestId)) {
|
|
393
|
+
throw new Error('invalid-request-id');
|
|
394
|
+
}
|
|
395
|
+
if (!(options.sessionPrivKey instanceof Uint8Array) || options.sessionPrivKey.length !== 32) {
|
|
396
|
+
throw new Error('invalid-session-privkey');
|
|
397
|
+
}
|
|
398
|
+
if (!/^wss:\/\//i.test(options.relayUrl) && !/^ws:\/\/(localhost|127\.0\.0\.1)([:\/]|$)/i.test(options.relayUrl)) {
|
|
399
|
+
throw new Error('invalid-relay-url');
|
|
400
|
+
}
|
|
401
|
+
if (typeof options.expectedOrigin !== 'string' || options.expectedOrigin.length === 0) {
|
|
402
|
+
throw new Error('invalid-expected-origin');
|
|
403
|
+
}
|
|
404
|
+
const sessionPubkey = bytesToHex(schnorr.getPublicKey(options.sessionPrivKey));
|
|
405
|
+
const timeout = Math.max(5000, Math.min(options.timeout ?? 120000, 600000));
|
|
406
|
+
const requestIdLower = options.requestId.toLowerCase();
|
|
407
|
+
const expectedOrigin = options.expectedOrigin;
|
|
408
|
+
return new Promise((resolve, reject) => {
|
|
409
|
+
const subId = `sa-${Math.random().toString(36).slice(2, 12)}`;
|
|
410
|
+
let settled = false;
|
|
411
|
+
let ws;
|
|
412
|
+
try {
|
|
413
|
+
ws = new WebSocket(options.relayUrl);
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
reject(new Error('relay-error'));
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const settle = (action) => {
|
|
420
|
+
if (settled)
|
|
421
|
+
return;
|
|
422
|
+
settled = true;
|
|
423
|
+
clearTimeout(timer);
|
|
424
|
+
try {
|
|
425
|
+
ws.close();
|
|
426
|
+
}
|
|
427
|
+
catch { /* ignore */ }
|
|
428
|
+
action();
|
|
429
|
+
};
|
|
430
|
+
const timer = setTimeout(() => {
|
|
431
|
+
settle(() => reject(new Error('timeout')));
|
|
432
|
+
}, timeout);
|
|
433
|
+
ws.onopen = () => {
|
|
434
|
+
// Subscribe slightly in the past so a racing publish isn't missed.
|
|
435
|
+
const since = Math.floor(Date.now() / 1000) - 60;
|
|
436
|
+
ws.send(JSON.stringify(['REQ', subId, { kinds: [1059], '#p': [sessionPubkey], since }]));
|
|
437
|
+
};
|
|
438
|
+
ws.onmessage = async (msgEvent) => {
|
|
439
|
+
if (settled)
|
|
440
|
+
return;
|
|
441
|
+
let msg;
|
|
442
|
+
try {
|
|
443
|
+
msg = JSON.parse(typeof msgEvent.data === 'string' ? msgEvent.data : '');
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (!Array.isArray(msg))
|
|
449
|
+
return;
|
|
450
|
+
if (msg[0] !== 'EVENT' || msg[1] !== subId)
|
|
451
|
+
return;
|
|
452
|
+
const wrap = msg[2];
|
|
453
|
+
if (typeof wrap !== 'object' || wrap === null)
|
|
454
|
+
return;
|
|
455
|
+
const w = wrap;
|
|
456
|
+
if (w.kind !== 1059 || typeof w.pubkey !== 'string' || typeof w.content !== 'string')
|
|
457
|
+
return;
|
|
458
|
+
const rumor = await unwrapGiftWrap({ pubkey: w.pubkey, content: w.content }, options.sessionPrivKey);
|
|
459
|
+
if (!rumor || rumor.kind !== 29999)
|
|
460
|
+
return;
|
|
461
|
+
const sessionTag = rumor.tags.find(t => t[0] === 'session');
|
|
462
|
+
if (!sessionTag || sessionTag[1] !== requestIdLower)
|
|
463
|
+
return;
|
|
464
|
+
const statusTag = rumor.tags.find(t => t[0] === 'status');
|
|
465
|
+
if (statusTag?.[1] === 'rejected') {
|
|
466
|
+
settle(() => reject(new Error('denied')));
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (statusTag?.[1] !== 'approved')
|
|
470
|
+
return;
|
|
471
|
+
// Freshness check — protects against stale replays the relay might serve.
|
|
472
|
+
const ageSec = Math.abs(Date.now() / 1000 - rumor.created_at);
|
|
473
|
+
if (ageSec > 300)
|
|
474
|
+
return;
|
|
475
|
+
let inner;
|
|
476
|
+
try {
|
|
477
|
+
const parsed = JSON.parse(rumor.content);
|
|
478
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
479
|
+
return;
|
|
480
|
+
inner = parsed;
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (inner.type !== 'signet-auth-response')
|
|
486
|
+
return;
|
|
487
|
+
if (inner.requestId !== requestIdLower)
|
|
488
|
+
return;
|
|
489
|
+
// Extract and validate the embedded signed kind-21236 auth event
|
|
490
|
+
if (typeof inner.authEvent !== 'object' || inner.authEvent === null)
|
|
491
|
+
return;
|
|
492
|
+
const ae = inner.authEvent;
|
|
493
|
+
if (typeof ae.id !== 'string' || !/^[0-9a-f]{64}$/i.test(ae.id))
|
|
494
|
+
return;
|
|
495
|
+
if (typeof ae.pubkey !== 'string' || !/^[0-9a-f]{64}$/i.test(ae.pubkey))
|
|
496
|
+
return;
|
|
497
|
+
if (typeof ae.sig !== 'string' || !/^[0-9a-f]{128}$/i.test(ae.sig))
|
|
498
|
+
return;
|
|
499
|
+
if (ae.kind !== 21236)
|
|
500
|
+
return;
|
|
501
|
+
if (typeof ae.created_at !== 'number')
|
|
502
|
+
return;
|
|
503
|
+
if (!Array.isArray(ae.tags))
|
|
504
|
+
return;
|
|
505
|
+
if (typeof ae.content !== 'string')
|
|
506
|
+
return;
|
|
507
|
+
// Identity binding: the signer of the authEvent must be the sender of the rumor
|
|
508
|
+
// (both are the user, wrapped and unwrapped versions of the same identity).
|
|
509
|
+
if (ae.pubkey.toLowerCase() !== rumor.pubkey.toLowerCase())
|
|
510
|
+
return;
|
|
511
|
+
// Verify the authEvent's id matches its canonical SHA-256 hash (tamper detection)
|
|
512
|
+
const expectedAuthEventId = computeNostrEventId({
|
|
513
|
+
pubkey: ae.pubkey,
|
|
514
|
+
created_at: ae.created_at,
|
|
515
|
+
kind: 21236,
|
|
516
|
+
tags: ae.tags,
|
|
517
|
+
content: ae.content,
|
|
518
|
+
});
|
|
519
|
+
if (expectedAuthEventId !== ae.id.toLowerCase())
|
|
520
|
+
return;
|
|
521
|
+
// Verify the authEvent's Schnorr signature over its id with its claimed pubkey
|
|
522
|
+
let sigValid = false;
|
|
523
|
+
try {
|
|
524
|
+
const sigBytes = hexToBytes(ae.sig);
|
|
525
|
+
const idBytes = hexToBytes(ae.id);
|
|
526
|
+
const pubBytes = hexToBytes(ae.pubkey);
|
|
527
|
+
sigValid = schnorr.verify(sigBytes, idBytes, pubBytes);
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
sigValid = false;
|
|
531
|
+
}
|
|
532
|
+
if (!sigValid)
|
|
533
|
+
return;
|
|
534
|
+
// Validate the challenge and origin tags on the authEvent
|
|
535
|
+
const aeTags = ae.tags;
|
|
536
|
+
const challengeTag = aeTags.find(t => Array.isArray(t) && t[0] === 'challenge');
|
|
537
|
+
if (!challengeTag || typeof challengeTag[1] !== 'string' || challengeTag[1].toLowerCase() !== requestIdLower)
|
|
538
|
+
return;
|
|
539
|
+
const originTag = aeTags.find(t => Array.isArray(t) && t[0] === 'origin');
|
|
540
|
+
if (!originTag || originTag[1] !== expectedOrigin)
|
|
541
|
+
return;
|
|
542
|
+
// Freshness check on the auth event itself (the user's signature timestamp)
|
|
543
|
+
const authEventAgeSec = Math.abs(Date.now() / 1000 - ae.created_at);
|
|
544
|
+
if (authEventAgeSec > 300)
|
|
545
|
+
return;
|
|
546
|
+
const verifiedAuthEvent = {
|
|
547
|
+
id: ae.id.toLowerCase(),
|
|
548
|
+
pubkey: ae.pubkey.toLowerCase(),
|
|
549
|
+
kind: 21236,
|
|
550
|
+
created_at: ae.created_at,
|
|
551
|
+
tags: aeTags,
|
|
552
|
+
content: ae.content,
|
|
553
|
+
sig: ae.sig,
|
|
554
|
+
};
|
|
555
|
+
settle(() => resolve({
|
|
556
|
+
pubkey: verifiedAuthEvent.pubkey,
|
|
557
|
+
authEvent: verifiedAuthEvent,
|
|
558
|
+
credential: inner.credential,
|
|
559
|
+
createdAt: verifiedAuthEvent.created_at,
|
|
560
|
+
}));
|
|
561
|
+
};
|
|
562
|
+
ws.onerror = () => {
|
|
563
|
+
settle(() => reject(new Error('relay-error')));
|
|
564
|
+
};
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
// Auto-attach to window for script-tag usage
|
|
568
|
+
if (typeof window !== 'undefined') {
|
|
569
|
+
window.Signet = { verifyAge, waitForAuthResponse };
|
|
570
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "signet-verify",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Signet SDK — website age verification and cross-device Sign-in-with-Signet",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/signet-verify.js",
|
|
7
|
+
"types": "./dist/signet-verify.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/signet-verify.d.ts",
|
|
11
|
+
"import": "./dist/signet-verify.js",
|
|
12
|
+
"default": "./dist/signet-verify.js"
|
|
13
|
+
},
|
|
14
|
+
"./iife": "./dist/signet-verify.iife.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"build": "npm run clean && tsc && npm run build:iife",
|
|
22
|
+
"build:iife": "esbuild src/signet-verify.ts --bundle --format=iife --global-name=Signet --outfile=dist/signet-verify.iife.js --minify --target=es2020",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@noble/curves": "^1.8.1",
|
|
28
|
+
"@noble/hashes": "^1.7.1",
|
|
29
|
+
"nostr-tools": "^2.23.3"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"esbuild": "^0.25.12",
|
|
33
|
+
"signet-protocol": "^1.6.0",
|
|
34
|
+
"typescript": "^5.7.0",
|
|
35
|
+
"vitest": "^3.2.4"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/forgesworn/signet-verify.git"
|
|
41
|
+
}
|
|
42
|
+
}
|