@actioncodes/protocol 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,6 @@ Instead of heavy signature popups or complex flows, it uses short-lived one-time
18
18
  - parseMeta / verifyTransactionMatchesCode (for checking integrity)
19
19
  - verifyTransactionSignedByIntentOwner (optional stronger guarantee).
20
20
  - Errors are typed → Clear ProtocolError.* categories instead of generic fails.
21
- - Performance focus → Benchmarked at ~3.5ms per verification on commodity hardware.
22
21
 
23
22
  ### Core Concepts
24
23
 
@@ -36,6 +35,305 @@ Instead of heavy signature popups or complex flows, it uses short-lived one-time
36
35
  - Always signed by the user's wallet.
37
36
  - Prevents replay / tampering.
38
37
 
38
+ ## Strategy Architecture
39
+
40
+ The Action Codes Protocol supports two main strategies for generating and validating codes:
41
+
42
+ ### 1. Wallet Strategy (Direct)
43
+
44
+ The **Wallet Strategy** is the simplest approach where codes are generated directly from a user's wallet.
45
+
46
+ #### How it works:
47
+ ```typescript
48
+ // 1. Get canonical message for signing
49
+ const canonicalMessage = protocol.getCanonicalMessageParts("user-wallet-address");
50
+
51
+ // 2. Sign the canonical message with user's wallet
52
+ const signature = await userWallet.signMessage(canonicalMessage);
53
+
54
+ // 3. Generate code with the signed canonical message (secret is optional)
55
+ const result = await protocol.generateCode("wallet", canonicalMessage, signature);
56
+ // Optional: provide secret for enhanced security
57
+ // const result = await protocol.generateCode("wallet", canonicalMessage, signature, "optional-secret");
58
+
59
+ // 4. Validate code
60
+ const isValid = await protocol.validateCode("wallet", result.actionCode, {
61
+ chain: "solana",
62
+ pubkey: "user-wallet-address",
63
+ signature: signature
64
+ });
65
+ ```
66
+
67
+ #### Key Features:
68
+ - **Signature-based security** - Codes require a valid signature over the canonical message (prevents public key + timestamp attacks)
69
+ - **Direct wallet binding** - Codes are cryptographically tied to the user's public key
70
+ - **Optional secrets** - Users can provide a secret for enhanced security (uses HMAC), or omit it (uses SHA256)
71
+ - **Immediate validation** - No delegation certificates needed
72
+ - **Perfect for** - Direct user interactions, simple authentication flows
73
+
74
+ #### Security Model:
75
+ - **Signature verification** - All codes require a valid signature over the canonical message
76
+ - **Public key + timestamp attack prevention** - Signatures prevent attackers from generating codes with just public key + timestamp
77
+ - Codes are bound to the specific public key
78
+ - Optional secret provides additional entropy (HMAC vs SHA256)
79
+ - Time-based expiration prevents replay attacks
80
+ - Canonical message signing ensures integrity
81
+
82
+ ### 2. Delegation Strategy (Advanced)
83
+
84
+ The **Delegation Strategy** allows users to pre-authorize actions through delegation certificates, enabling more complex workflows like relayer services.
85
+
86
+ #### How it works:
87
+
88
+ ##### Step 1: Create Delegation Certificate
89
+ ```typescript
90
+ // User creates a delegation certificate template
91
+ const template = await protocol.createDelegationCertificateTemplate(
92
+ userPublicKey,
93
+ 3600000, // 1 hour expiration
94
+ "solana"
95
+ );
96
+
97
+ // User signs the certificate
98
+ const message = DelegationStrategy.serializeCertificate(template);
99
+ const signature = await userWallet.signMessage(message);
100
+
101
+ const certificate: DelegationCertificate = {
102
+ ...template,
103
+ signature: signature
104
+ };
105
+ ```
106
+
107
+ ##### Step 2: Generate Delegated Codes
108
+ ```typescript
109
+ // Generate codes using the delegation certificate
110
+ const result = await protocol.generateCode("delegation", certificate);
111
+ const actionCode = result.actionCode;
112
+ ```
113
+
114
+ ##### Step 3: Validate Delegated Codes
115
+ ```typescript
116
+ // Validate the delegated code with the certificate
117
+ const isValid = await protocol.validateCode(actionCode, "delegation", certificate);
118
+ ```
119
+
120
+ #### Key Features:
121
+ - **Pre-authorization** - Users can authorize actions for a limited time
122
+ - **Relayer support** - Third parties can validate codes without generating them
123
+ - **Certificate-based** - Codes are bound to specific delegation certificates
124
+ - **Time-limited** - Certificates have expiration times
125
+ - **Perfect for** - Relayer services, automated systems, complex workflows
126
+
127
+ #### Security Model:
128
+ - **Code-Certificate Binding** - Codes are cryptographically bound to their specific certificate
129
+ - **Signature Verification** - Certificate signatures are verified using chain adapters
130
+ - **Delegation ID** - Each certificate has a unique ID derived from its content + signature
131
+ - **Cross-Certificate Protection** - Codes from one certificate cannot be used with another
132
+ - **Relayer Security** - Relayers can validate codes but cannot generate them without the user's signature
133
+
134
+ #### Important Security Guarantees:
135
+
136
+ 1. **Stolen Delegation IDs are Useless**
137
+ - Delegation IDs are public identifiers (like transaction hashes)
138
+ - They cannot be used to generate or validate codes
139
+ - They're safe to share publicly
140
+
141
+ 2. **Stolen Signatures Cannot Create Valid Codes**
142
+ - Even if an attacker steals a signature, they cannot create valid codes
143
+ - Codes are bound to the ENTIRE certificate (not just the signature)
144
+ - Different certificate data = different code = validation failure
145
+
146
+ 3. **Relayer Code Generation Prevention**
147
+ - Relayers cannot generate codes even with public certificate data
148
+ - Certificate hashes include the signature (private user asset)
149
+ - Only the original user can generate valid codes
150
+
151
+ 4. **Code-Certificate Binding**
152
+ - Codes are cryptographically linked to their specific certificate
153
+ - Cross-certificate attacks are impossible
154
+ - Each certificate produces unique codes
155
+
156
+ #### Delegation Certificate Structure:
157
+ ```typescript
158
+ interface DelegationCertificate {
159
+ version: "1.0";
160
+ delegator: string; // User's public key
161
+ issuedAt: number; // Timestamp when issued
162
+ expiresAt: number; // Expiration timestamp
163
+ nonce: string; // Unique nonce for this certificate
164
+ chain: string; // Target blockchain
165
+ signature: string; // User's signature of the certificate
166
+ }
167
+ ```
168
+
169
+ #### Delegated Action Code Structure:
170
+ ```typescript
171
+ interface DelegatedActionCode {
172
+ code: string; // The actual action code
173
+ pubkey: string; // User's public key
174
+ timestamp: number; // Generation timestamp
175
+ expiresAt: number; // Code expiration
176
+ delegationId: string; // Hash of the certificate (used internally as secret)
177
+ delegatedBy: string; // Who delegated (same as pubkey)
178
+ // Note: secret field is inherited from ActionCode but not used in delegation
179
+ }
180
+ ```
181
+
182
+ ## Use Cases & Examples
183
+
184
+ ### Wallet Strategy Use Cases
185
+
186
+ #### 1. Simple Authentication
187
+ ```typescript
188
+ // User logs into a dApp
189
+ const canonicalMessage = protocol.getCanonicalMessageParts(userWallet.publicKey);
190
+ const signature = await userWallet.signMessage(canonicalMessage);
191
+ const result = await protocol.generateCode("wallet", canonicalMessage, signature);
192
+
193
+ // dApp validates the code
194
+ const isValid = await protocol.validateCode('wallet', result.actionCode, {
195
+ chain: "solana",
196
+ pubkey: userWallet.publicKey,
197
+ signature: signature
198
+ });
199
+ ```
200
+
201
+ #### 2. Transaction Authorization
202
+ ```typescript
203
+ // User authorizes a specific transaction
204
+ const canonicalMessage = protocol.getCanonicalMessageParts(userWallet.publicKey);
205
+ const signature = await userWallet.signMessage(canonicalMessage);
206
+ const result = await protocol.generateCode("wallet", canonicalMessage, signature);
207
+ // Optional: add secret for enhanced security
208
+ // const result = await protocol.generateCode("wallet", canonicalMessage, signature, `tx-${transactionHash}`);
209
+
210
+ // Relayer validates before executing
211
+ const isValid = await protocol.validateCode('wallet', result.actionCode, {
212
+ chain: "solana",
213
+ pubkey: userWallet.publicKey,
214
+ signature: signature
215
+ });
216
+ ```
217
+
218
+ ### Delegation Strategy Use Cases
219
+
220
+ #### 1. Relayer Services
221
+ ```typescript
222
+ // User pre-authorizes a relayer for 1 hour
223
+ const certificate = await createDelegationCertificate(userWallet, 3600000);
224
+
225
+ // Relayer can validate codes but not generate them
226
+ const relayer = new RelayerService();
227
+ relayer.registerCertificate(certificate);
228
+
229
+ // User generates codes that relayer can validate
230
+ const actionCode = await protocol.generateCode("delegation", certificate);
231
+ const isValid = relayer.validateCode(actionCode, certificate);
232
+ ```
233
+
234
+ #### 2. Automated Trading Bots
235
+ ```typescript
236
+ // User authorizes trading bot for specific operations
237
+ const tradingCertificate = await createDelegationCertificate(userWallet, 86400000); // 24 hours
238
+
239
+ // Bot can execute trades using delegated codes
240
+ const tradeCode = await protocol.generateCode("delegation", tradingCertificate);
241
+ // Bot executes trade with this code
242
+ ```
243
+
244
+ #### 3. Multi-Signature Workflows
245
+ ```typescript
246
+ // Multiple users can delegate to a shared certificate
247
+ const sharedCertificate = await createSharedDelegationCertificate([
248
+ user1Wallet,
249
+ user2Wallet,
250
+ user3Wallet
251
+ ]);
252
+
253
+ // Any authorized user can generate codes
254
+ const actionCode = await protocol.generateCode("delegation", sharedCertificate);
255
+ ```
256
+
257
+ ## Security Considerations
258
+
259
+ ### What Makes Action Codes Secure?
260
+
261
+ 1. **Cryptographic Binding**
262
+ - Codes are mathematically tied to specific public keys
263
+ - Impossible to forge without the private key
264
+
265
+ 2. **Time-Limited Validity**
266
+ - Codes expire automatically
267
+ - Prevents replay attacks
268
+
269
+ 3. **One-Time Use**
270
+ - Each code is unique and time-bound
271
+ - Cannot be reused
272
+
273
+ 4. **Delegation Security**
274
+ - Delegation certificates are cryptographically signed
275
+ - Codes are bound to specific certificates
276
+ - Cross-certificate attacks are impossible
277
+
278
+ ### Best Practices
279
+
280
+ 1. **Secret Management**
281
+ - Use cryptographically secure random secrets
282
+ - Don't reuse secrets across different contexts
283
+ - Consider using deterministic secrets based on context
284
+
285
+ 2. **Certificate Expiration**
286
+ - Set appropriate expiration times for delegation certificates
287
+ - Shorter expiration = higher security
288
+ - Longer expiration = better UX
289
+
290
+ 3. **Relayer Security**
291
+ - Only trust relayers with full certificates
292
+ - Never share private keys with relayers
293
+ - Monitor relayer behavior
294
+
295
+ 4. **Code Validation**
296
+ - Always validate codes server-side
297
+ - Check expiration times
298
+ - Verify the binding to the correct public key
299
+
300
+ ## Performance
301
+
302
+ - **Code Generation**: ~1ms per code
303
+ - **Code Validation**: ~3ms per validation
304
+ - **Memory Usage**: Minimal (no state storage required)
305
+ - **Network**: No network calls required for validation
306
+
307
+ ## Getting Started
308
+
309
+ ```bash
310
+ # Install
311
+ npm install @actioncodes/protocol
312
+
313
+ # Basic usage
314
+ import { ActionCodesProtocol } from '@actioncodes/protocol';
315
+
316
+ const protocol = new ActionCodesProtocol();
317
+
318
+ // 1. Get canonical message for signing
319
+ const canonicalMessage = protocol.getCanonicalMessageParts("your-public-key");
320
+
321
+ // 2. Sign the canonical message with your wallet
322
+ const signature = await yourWallet.signMessage(canonicalMessage);
323
+
324
+ // 3. Generate a code with the signed canonical message
325
+ const result = await protocol.generateCode("wallet", canonicalMessage, signature);
326
+ // Optional: add secret for enhanced security
327
+ // const result = await protocol.generateCode("wallet", canonicalMessage, signature, "optional-secret");
328
+
329
+ // 4. Validate a code
330
+ const isValid = await protocol.validateCode("wallet", result.actionCode, {
331
+ chain: "solana",
332
+ pubkey: "your-public-key",
333
+ signature: signature
334
+ });
335
+ ```
336
+
39
337
  #### Vision
40
338
 
41
339
  Action Codes Protocol aim to be the OTP protocol for blockchains but allowing more than authentication: a simple, universal interaction layer usable across apps, chains, and eventually banks/CBDCs.
@@ -20,9 +20,11 @@ export declare class ActionCodesProtocol {
20
20
  };
21
21
  /** Access to strategies */
22
22
  get walletStrategy(): WalletStrategy;
23
+ /** Get canonical message parts for signing (before code generation) */
24
+ getCanonicalMessageParts(pubkey: string, providedSecret?: string): Uint8Array;
23
25
  get delegationStrategy(): DelegationStrategy;
24
26
  createDelegationCertificateTemplate(userPublicKey: string, durationMs?: number, chain?: string): Omit<DelegationCertificate, "signature">;
25
- generateCode(strategy: "wallet", pubkey: string, providedSecret?: string): {
27
+ generateCode(strategy: "wallet", canonicalMessage: Uint8Array, signature: string, providedSecret?: string): {
26
28
  actionCode: ActionCode;
27
29
  canonicalMessage: Uint8Array;
28
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ActionCodesProtocol.d.ts","sourceRoot":"","sources":["../src/ActionCodesProtocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,a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AE,MAAM,GACtB;QACD,UAAU,EAAE,UAAU,CAAC;QACvB,gBAAgB,EAAE,UAAU,CAAC;KAC9B;IACD,YAAY,CACV,QAAQ,EAAE,YAAY,EACtB,WAAW,EAAE,qBAAqB,GACjC;QACD,UAAU,EAAE,mBAAmB,CAAC;KACjC;IAyBD,YAAY,CACV,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC,GAC3E,IAAI;IACP,YAAY,CACV,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,mBAAmB,EAC/B,WAAW,EAAE,qBAAqB,GACjC,IAAI;CA0DR"}
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare enum ProtocolErrorCode {
2
2
  EXPIRED_CODE = "EXPIRED_CODE",
3
+ INVALID_CODE = "INVALID_CODE",
3
4
  INVALID_CODE_FORMAT = "INVALID_CODE_FORMAT",
4
5
  INVALID_SIGNATURE = "INVALID_SIGNATURE",
5
6
  MISSING_META = "MISSING_META",
@@ -20,6 +21,7 @@ export declare class ProtocolError extends Error {
20
21
  readonly details?: Record<string, unknown> | undefined;
21
22
  constructor(code: ProtocolErrorCode, message: string, details?: Record<string, unknown> | undefined);
22
23
  static expiredCode(code: string, expiresAt: number, currentTime: number): ExpiredCodeError;
24
+ static invalidCode(expected: string, actual: string): ProtocolError;
23
25
  static invalidCodeFormat(code: string, reason: string): InvalidCodeFormatError;
24
26
  static invalidSignature(reason: string): InvalidSignatureError;
25
27
  static missingMeta(): MissingMetaError;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAE3B,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;IAC3C,iBAAiB,sBAAsB;IAGvC,YAAY,iBAAiB;IAC7B,mBAAmB,wBAAwB;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5D;AAED,qBAAa,wCAAyC,SAAQ,aAAa;gBAC7D,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE;CAUtD;AAED,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ3C;AAED,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,MAAM,EAAE,MAAM;CAM3B;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQzC;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,EAAE,MAAM;CAI5B"}
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- var G0=Object.create;var{getPrototypeOf:O0,defineProperty:s,getOwnPropertyNames:g8,getOwnPropertyDescriptor:F0}=Object,f8=Object.prototype.hasOwnProperty;var p8=(Q,$,q)=>{q=Q!=null?G0(O0(Q)):{};let Z=$||!Q||!Q.__esModule?s(q,"default",{value:Q,enumerable:!0}):q;for(let X of g8(Q))if(!f8.call(Z,X))s(Z,X,{get:()=>Q[X],enumerable:!0});return Z},m8=new WeakMap,P0=(Q)=>{var $=m8.get(Q),q;if($)return $;if($=s({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")g8(Q).map((Z)=>!f8.call($,Z)&&s($,Z,{get:()=>Q[Z],enumerable:!(q=F0(Q,Z))||q.enumerable}));return m8.set(Q,$),$};var v0=(Q,$)=>{for(var q in $)s(Q,q,{get:$[q],enumerable:!0,configurable:!0,set:(Z)=>$[q]=()=>Z})};var A0={};v0(A0,{truncateBits:()=>j8,sha256:()=>A,serializeCanonical:()=>l,hmacSha256:()=>U8,hkdfSha256:()=>C0,generateRandomSecret:()=>m0,generateNonce:()=>E8,digestToDigits:()=>K8,codeHash:()=>V8,base32EncodeCrockford:()=>y0,WalletStrategy:()=>n,SolanaAdapter:()=>$8,SUPPORTED_CHAINS:()=>H0,PROTOCOL_NORMALIZATION:()=>R8,PROTOCOL_META_MAX_BYTES:()=>c,DelegationStrategy:()=>V,CODE_MIN_LENGTH:()=>G8,CODE_MAX_LENGTH:()=>O8,CODE_DEFAULT_LENGTH:()=>p0,CODE_CHARSET_DIGITS:()=>S0,CANONICAL_MESSAGE_VERSION:()=>g0,CANONICAL_MESSAGE_PREFIX:()=>f0,BaseChainAdapter:()=>i,ActionCodesProtocol:()=>K0});module.exports=P0(A0);class i{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function D0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function X8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let q=$&&`"${$}" `;throw Error(`${q}expected integer >= 0, got ${Q}`)}}function m(Q,$,q=""){let Z=D0(Q),X=Q?.length,J=$!==void 0;if(!Z||J&&X!==$){let Y=q&&`"${q}" `,N=J?` of length ${$}`:"",U=Z?`length=${X}`:`type=${typeof Q}`;throw Error(Y+"expected Uint8Array"+N+", got "+U)}return Q}function a(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");X8(Q.outputLen),X8(Q.blockLen)}function u(Q,$=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if($&&Q.finished)throw Error("Hash#digest() has already been called")}function S8(Q,$){m(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function T(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function J8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function k(Q,$){return Q<<32-$|Q>>>$}function H8(Q,$={}){let q=(X,J)=>Q(J).update(X).digest(),Z=Q(void 0);return q.outputLen=Z.outputLen,q.blockLen=Z.blockLen,q.create=(X)=>Q(X),Object.assign(q,$),Object.freeze(q)}var _8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function A8(Q,$,q){return Q&$^~Q&q}function u8(Q,$,q){return Q&$^Q&q^$&q}class Y8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,q,Z){this.blockLen=Q,this.outputLen=$,this.padOffset=q,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=J8(this.buffer)}update(Q){u(this),m(Q);let{view:$,buffer:q,blockLen:Z}=this,X=Q.length;for(let J=0;J<X;){let Y=Math.min(Z-this.pos,X-J);if(Y===Z){let N=J8(Q);for(;Z<=X-J;J+=Z)this.process(N,J);continue}if(q.set(Q.subarray(J,J+Y),this.pos),this.pos+=Y,J+=Y,this.pos===Z)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){u(this),S8(Q,this),this.finished=!0;let{buffer:$,view:q,blockLen:Z,isLE:X}=this,{pos:J}=this;if($[J++]=128,T(this.buffer.subarray(J)),this.padOffset>Z-J)this.process(q,0),J=0;for(let z=J;z<Z;z++)$[z]=0;q.setBigUint64(Z-8,BigInt(this.length*8),X),this.process(q,0);let Y=J8(Q),N=this.outputLen;if(N%4)throw Error("_sha2: outputLen must be aligned to 32bit");let U=N/4,K=this.get();if(U>K.length)throw Error("_sha2: outputLen bigger than state");for(let z=0;z<U;z++)Y.setUint32(4*z,K[z],X)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let q=Q.slice(0,$);return this.destroy(),q}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:q,length:Z,finished:X,destroyed:J,pos:Y}=this;if(Q.destroyed=J,Q.finished=X,Q.length=Z,Q.pos=Y,Z%$)Q.buffer.set(q);return Q}clone(){return this._cloneInto()}}var b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),B=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),P=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),v=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var z8=BigInt(4294967295),d8=BigInt(32);function W0(Q,$=!1){if($)return{h:Number(Q&z8),l:Number(Q>>d8&z8)};return{h:Number(Q>>d8&z8)|0,l:Number(Q&z8)|0}}function h8(Q,$=!1){let q=Q.length,Z=new Uint32Array(q),X=new Uint32Array(q);for(let J=0;J<q;J++){let{h:Y,l:N}=W0(Q[J],$);[Z[J],X[J]]=[Y,N]}return[Z,X]}var w8=(Q,$,q)=>Q>>>q,L8=(Q,$,q)=>Q<<32-q|$>>>q,H=(Q,$,q)=>Q>>>q|$<<32-q,_=(Q,$,q)=>Q<<32-q|$>>>q,e=(Q,$,q)=>Q<<64-q|$>>>q-32,t=(Q,$,q)=>Q>>>q-32|$<<64-q;function E(Q,$,q,Z){let X=($>>>0)+(Z>>>0);return{h:Q+q+(X/4294967296|0)|0,l:X|0}}var l8=(Q,$,q)=>(Q>>>0)+($>>>0)+(q>>>0),c8=(Q,$,q,Z)=>$+q+Z+(Q/4294967296|0)|0,n8=(Q,$,q,Z)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0),r8=(Q,$,q,Z,X)=>$+q+Z+X+(Q/4294967296|0)|0,o8=(Q,$,q,Z,X)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0)+(X>>>0),s8=(Q,$,q,Z,X,J)=>$+q+Z+X+J+(Q/4294967296|0)|0;var L0=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]),g=new Uint32Array(64);class M8 extends Y8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:q,D:Z,E:X,F:J,G:Y,H:N}=this;return[Q,$,q,Z,X,J,Y,N]}set(Q,$,q,Z,X,J,Y,N){this.A=Q|0,this.B=$|0,this.C=q|0,this.D=Z|0,this.E=X|0,this.F=J|0,this.G=Y|0,this.H=N|0}process(Q,$){for(let z=0;z<16;z++,$+=4)g[z]=Q.getUint32($,!1);for(let z=16;z<64;z++){let R=g[z-15],G=g[z-2],W=k(R,7)^k(R,18)^R>>>3,F=k(G,17)^k(G,19)^G>>>10;g[z]=F+g[z-7]+W+g[z-16]|0}let{A:q,B:Z,C:X,D:J,E:Y,F:N,G:U,H:K}=this;for(let z=0;z<64;z++){let R=k(Y,6)^k(Y,11)^k(Y,25),G=K+R+A8(Y,N,U)+L0[z]+g[z]|0,F=(k(q,2)^k(q,13)^k(q,22))+u8(q,Z,X)|0;K=U,U=N,N=Y,Y=J+G|0,J=X,X=Z,Z=q,q=G+F|0}q=q+this.A|0,Z=Z+this.B|0,X=X+this.C|0,J=J+this.D|0,Y=Y+this.E|0,N=N+this.F|0,U=U+this.G|0,K=K+this.H|0,this.set(q,Z,X,J,Y,N,U,K)}roundClean(){T(g)}destroy(){this.set(0,0,0,0,0,0,0,0),T(this.buffer)}}class i8 extends M8{A=b[0]|0;B=b[1]|0;C=b[2]|0;D=b[3]|0;E=b[4]|0;F=b[5]|0;G=b[6]|0;H=b[7]|0;constructor(){super(32)}}class M0 extends M8{A=B[0]|0;B=B[1]|0;C=B[2]|0;D=B[3]|0;E=B[4]|0;F=B[5]|0;G=B[6]|0;H=B[7]|0;constructor(){super(28)}}var a8=(()=>h8(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((Q)=>BigInt(Q))))(),T0=(()=>a8[0])(),k0=(()=>a8[1])(),f=new Uint32Array(80),p=new Uint32Array(80);class Q8 extends Y8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:q,Bl:Z,Ch:X,Cl:J,Dh:Y,Dl:N,Eh:U,El:K,Fh:z,Fl:R,Gh:G,Gl:W,Hh:F,Hl:M}=this;return[Q,$,q,Z,X,J,Y,N,U,K,z,R,G,W,F,M]}set(Q,$,q,Z,X,J,Y,N,U,K,z,R,G,W,F,M){this.Ah=Q|0,this.Al=$|0,this.Bh=q|0,this.Bl=Z|0,this.Ch=X|0,this.Cl=J|0,this.Dh=Y|0,this.Dl=N|0,this.Eh=U|0,this.El=K|0,this.Fh=z|0,this.Fl=R|0,this.Gh=G|0,this.Gl=W|0,this.Hh=F|0,this.Hl=M|0}process(Q,$){for(let O=0;O<16;O++,$+=4)f[O]=Q.getUint32($),p[O]=Q.getUint32($+=4);for(let O=16;O<80;O++){let C=f[O-15]|0,y=p[O-15]|0,P8=H(C,y,1)^H(C,y,8)^w8(C,y,7),v8=_(C,y,1)^_(C,y,8)^L8(C,y,7),I=f[O-2]|0,x=p[O-2]|0,q8=H(I,x,19)^e(I,x,61)^w8(I,x,6),D8=_(I,x,19)^t(I,x,61)^L8(I,x,6),Z8=n8(v8,D8,p[O-7],p[O-16]),W8=r8(Z8,P8,q8,f[O-7],f[O-16]);f[O]=W8|0,p[O]=Z8|0}let{Ah:q,Al:Z,Bh:X,Bl:J,Ch:Y,Cl:N,Dh:U,Dl:K,Eh:z,El:R,Fh:G,Fl:W,Gh:F,Gl:M,Hh:r,Hl:o}=this;for(let O=0;O<80;O++){let C=H(z,R,14)^H(z,R,18)^e(z,R,41),y=_(z,R,14)^_(z,R,18)^t(z,R,41),P8=z&G^~z&F,v8=R&W^~R&M,I=o8(o,y,v8,k0[O],p[O]),x=s8(I,r,C,P8,T0[O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|0;constructor(){super(48)}}var w=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),L=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class I0 extends Q8{Ah=w[0]|0;Al=w[1]|0;Bh=w[2]|0;Bl=w[3]|0;Ch=w[4]|0;Cl=w[5]|0;Dh=w[6]|0;Dl=w[7]|0;Eh=w[8]|0;El=w[9]|0;Fh=w[10]|0;Fl=w[11]|0;Gh=w[12]|0;Gl=w[13]|0;Hh=w[14]|0;Hl=w[15]|0;constructor(){super(28)}}class x0 extends Q8{Ah=L[0]|0;Al=L[1]|0;Bh=L[2]|0;Bl=L[3]|0;Ch=L[4]|0;Cl=L[5]|0;Dh=L[6]|0;Dl=L[7]|0;Eh=L[8]|0;El=L[9]|0;Fh=L[10]|0;Fl=L[11]|0;Gh=L[12]|0;Gl=L[13]|0;Hh=L[14]|0;Hl=L[15]|0;constructor(){super(32)}}var N8=H8(()=>new i8,_8(1));class T8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if(a(Q),m($,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let q=this.blockLen,Z=new Uint8Array(q);Z.set($.length>q?Q.create().update($).digest():$);for(let X=0;X<Z.length;X++)Z[X]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let X=0;X<Z.length;X++)Z[X]^=106;this.oHash.update(Z),T(Z)}update(Q){return u(this),this.iHash.update(Q),this}digestInto(Q){u(this),m(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:$,iHash:q,finished:Z,destroyed:X,blockLen:J,outputLen:Y}=this;return Q=Q,Q.finished=Z,Q.destroyed=X,Q.blockLen=J,Q.outputLen=Y,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=q._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var d=(Q,$,q)=>new T8(Q,$).update(q).digest();d.create=(Q,$)=>new T8(Q,$);function b0(Q,$,q){if(a(Q),q===void 0)q=new Uint8Array(Q.outputLen);return d(Q,q,$)}var k8=Uint8Array.of(0),e8=Uint8Array.of();function B0(Q,$,q,Z=32){a(Q),X8(Z,"length");let X=Q.outputLen;if(Z>255*X)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/X);if(q===void 0)q=e8;else m(q,void 0,"info");let Y=new Uint8Array(J*X),N=d.create(Q,$),U=N._cloneInto(),K=new Uint8Array(N.outputLen);for(let z=0;z<J;z++)k8[0]=z+1,U.update(z===0?e8:K).update(q).update(k8).digestInto(K),Y.set(K,X*z),N._cloneInto(U);return N.destroy(),U.destroy(),T(K,k8),Y.slice(0,Z)}var t8=(Q,$,q,Z,X)=>B0(Q,b0(Q,$,q),Z,X);function h(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function A(Q){return N8(h(Q))}function U8(Q,$){return d(N8,h(Q),h($))}function C0(Q,$,{salt:q,info:Z}={}){let X=q?h(q):new Uint8Array(32),J=h(Q),Y=Z?h(Z):new Uint8Array(0);return t8(N8,J,X,Y,$)}var Q0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function y0(Q){let $=0,q=0,Z="";for(let X=0;X<Q.length;X++){q=q<<8|Q[X],$+=8;while($>=5)Z+=Q0[q>>>$-5&31],$-=5}if($>0)Z+=Q0[q<<5-$&31];return Z}function j8(Q,$){let q=Math.ceil($/8),Z=new Uint8Array(q),X=Math.min(q,Q.length);Z.set(Q.subarray(0,X));let J=q*8-$;if(J>0){let Y=255<<J;Z[q-1]=Z[q-1]&Y}return Z}function K8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let q="",Z=Q[Q.length-1]&15;for(let X=0;q.length<$;X++){let J=(Z+X*4)%Math.max(1,Q.length-4),U=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");q+=U}return q.slice(0,$)}function V8(Q){let $=A(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}function m0(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}function E8(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}var g0=1,f0="actioncodes";function l(Q){let $=JSON.stringify({id:"actioncodes",ver:1,pubkey:Q.pubkey,windowStart:Q.windowStart,...Q.secret&&{secret:Q.secret}});return new TextEncoder().encode($)}var R8="NFC",c=256,G8=6,O8=24,p0=8,S0="0123456789",H0=["solana"];class j extends Error{code;details;constructor(Q,$,q){super($);this.code=Q;this.details=q;this.name="ProtocolError"}static expiredCode(Q,$,q){return new $0(Q,$,q)}static invalidCodeFormat(Q,$){return new z0(Q,$)}static invalidSignature(Q){return new Y0(Q)}static missingMeta(){return new q0}static invalidMetaFormat(Q){return new j("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,q){return new Z0(Q,$,q)}static metaTooLarge(Q,$){return new j("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new X0(Q,$)}static invalidTransactionFormat(Q){return new j("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new J0(Q,$)}static invalidInput(Q,$,q){return new j("INVALID_INPUT",`Invalid ${Q}: ${q}`,{field:Q,value:$,reason:q})}static missingRequiredField(Q){return new j("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new j("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new j("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new N0(Q)}static create(Q,$,q){return new j(Q,$,q)}}class $0 extends j{constructor(Q,$,q){super("EXPIRED_CODE",`Action code '${Q}' expired at ${$}, current time: ${q}`,{code:Q,expiresAt:$,currentTime:q});this.name="ExpiredCodeError"}}class q0 extends j{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class Z0 extends j{constructor(Q,$,q){super("META_MISMATCH",`Meta ${q} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:q});this.name="MetaMismatchError"}}class X0 extends j{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${$.join(", ")}]`,{intended:Q,actualSigners:$});this.name="TransactionNotSignedByIntendedOwnerError"}}class J0 extends j{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class Y0 extends j{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class z0 extends j{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class N0 extends j{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}class n{config;constructor(Q){this.config=Q}generateCode(Q,$){let q=_0(Date.now(),this.config.ttlMs),Z=$,X=l({pubkey:Q,windowStart:q,secret:Z}),J=Z?U8(Z,X):A(X),Y=Math.max(G8,Math.min(O8,this.config.codeLength)),N=j8(J,8*Math.ceil(Y/2));return{actionCode:{code:K8(N,Y),pubkey:Q,timestamp:q,expiresAt:q+this.config.ttlMs,...Z&&{secret:Z}},canonicalMessage:X}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw j.expiredCode(Q.code,Q.expiresAt,$);let q=l({pubkey:Q.pubkey,windowStart:Q.timestamp,secret:Q.secret}),Z=Q.secret?U8(Q.secret,q):A(q),X=Math.max(G8,Math.min(O8,this.config.codeLength)),J=j8(Z,8*Math.ceil(X/2));if(K8(J,X)!==Q.code)throw j.invalidCodeFormat(Q.code,"Code does not match expected value")}}function _0(Q,$){return Math.floor(Q/$)*$}class V{walletStrategy;constructor(Q){this.walletStrategy=new n(Q)}static createDelegationCertificateTemplate(Q,$=3600000,q="solana"){let Z=Date.now();return{version:"1.0",delegator:Q,issuedAt:Z,expiresAt:Z+$,nonce:E8(),chain:q}}generateDelegatedCode(Q){if(!this.validateCertificate(Q))throw Error("Invalid delegation certificate");let $=V.hashCertificate(Q);return{actionCode:{...this.walletStrategy.generateCode(Q.delegator,$).actionCode,delegationId:V.hashCertificate(Q),delegatedBy:Q.delegator}}}validateDelegatedCode(Q,$){if(this.walletStrategy.validateCode(Q),!this.validateCertificate($))throw Error("Delegation certificate expired or invalid");if(Q.delegationId!==V.hashCertificate($))throw Error("Action code does not match delegation certificate");if(Q.delegatedBy!==$.delegator)throw Error("Action code delegator does not match certificate")}validateCertificate(Q){if(Date.now()>Q.expiresAt)return!1;if(Date.now()<Q.issuedAt)return!1;if(!Q.version||!Q.delegator||!Q.issuedAt||!Q.expiresAt||!Q.nonce||!Q.chain||!Q.signature)return!1;if(Q.version!=="1.0")return!1;return!0}static serializeCertificate(Q){let $=JSON.stringify({version:Q.version,delegator:Q.delegator,issuedAt:Q.issuedAt,expiresAt:Q.expiresAt,nonce:Q.nonce,chain:Q.chain});return new TextEncoder().encode($)}static hashCertificate(Q){let $=this.serializeCertificate(Q),q=A($);return Array.from(q).map((Z)=>Z.toString(16).padStart(2,"0")).join("")}static validateCertificateStructure(Q){if(!Q.version||!Q.delegator||!Q.issuedAt||!Q.expiresAt||!Q.nonce||!Q.chain||!Q.signature)return!1;if(Q.version!=="1.0")return!1;if(Date.now()>Q.expiresAt)return!1;if(Date.now()<Q.issuedAt)return!1;return!0}getWalletStrategy(){return this.walletStrategy}}var B8=p8(require("tweetnacl")),C8=p8(require("bs58")),D=require("@solana/web3.js"),S=require("@solana/spl-memo");var I8="actioncodes:";function x8(Q){let $=U0(Q);if($.int!=null)F8($.int);let q=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let X=JSON.stringify($.p);F8(X),q.push(`p=${encodeURIComponent(X)}`)}let Z=I8+q.join("&");return j0(Z),Z}function b8(Q){if(!Q.startsWith(I8))throw Error("protocol meta must start with actioncodes:");let q=Q.slice(I8.length).split("&").filter(Boolean),Z=new Map;for(let G of q){let[W,F]=G.split("=",2);if(!W)continue;let M=F!=null?decodeURIComponent(F):"";Z.set(W,M)}let X=Z.get("ver"),J=Z.get("id"),Y=Z.get("int"),N=Z.get("p");if(X==null||J==null||Y==null)throw Error("protocol meta missing required fields ver or id or int");let U=Number(X);if(!Number.isInteger(U)||U<=0)throw Error("protocol meta ver must be positive integer");let K;if(N!=null&&N!=="")try{if(K=JSON.parse(N),typeof K!=="object"||K===null||Array.isArray(K))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let z=U0({ver:U,id:J,int:Y,p:K});if(z.int!=null)F8(z.int);if(z.p!=null)F8(JSON.stringify(z.p));if([...Z.keys()].filter((G)=>G!=="ver"&&G!=="id"&&G!=="int"&&G!=="p").length>0)throw Error("protocol meta contains unsupported keys");return j0(x8(z)),z}function U0(Q){let $=Q.id.normalize(R8).trim(),q={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)q.int=Q.int.normalize(R8).trim();if(Q.p!=null)q.p=Q.p;return q}function j0(Q){if(new TextEncoder().encode(Q).length>c)throw Error(`protocol meta exceeds ${c} bytes`)}function F8(Q){if(new TextEncoder().encode(Q).length>c)throw Error(`protocol meta params exceed ${c} bytes`)}class $8 extends i{normalizePubkey(Q){if(typeof Q==="string")return new D.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!=="solana")return!1;if(!Q.pubkey||!Q.signature||!Q.canonicalMessageParts)return!1;try{let $=l(Q.canonicalMessageParts),q=this.normalizePubkey(Q.pubkey),Z=C8.default.decode(Q.signature),X=q.toBytes();if(Z.length!==64||X.length!==32)return!1;return B8.default.sign.detached.verify($,Z,X)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!=="solana")return!1;if(!Q.pubkey||!Q.signature||!Q.certificate)return!1;let $=Q.certificate;if(!V.validateCertificateStructure($))return!1;if($.delegator!==Q.pubkey)return!1;if($.chain!==Q.chain)return!1;try{let q={version:$.version,delegator:$.delegator,issuedAt:$.issuedAt,expiresAt:$.expiresAt,nonce:$.nonce,chain:$.chain},Z=V.serializeCertificate(q),X=this.normalizePubkey(Q.pubkey),J=C8.default.decode(Q.signature),Y=X.toBytes();if(J.length!==64||Y.length!==32)return!1;return B8.default.sign.detached.verify(Z,J,Y)}catch{return!1}}static createProtocolMetaIx(Q){let $=x8(Q);return S.createMemoInstruction($)}getProtocolMeta(Q){for(let $ of this.getMemoInstructions(Q)){let q=$.data;try{let Z=new TextDecoder().decode(q);if(b8(Z))return Z}catch{}}return null}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return b8($)}getMemoInstructions(Q){if(Q instanceof D.Transaction)return Q.instructions.filter(($)=>$.programId.equals(S.MEMO_PROGRAM_ID));else{let q=Q.message;if(q instanceof D.MessageV0){let Z=[];for(let X of q.compiledInstructions){let J=q.staticAccountKeys[X.programIdIndex];if(J&&J.equals(S.MEMO_PROGRAM_ID)){let Y=X.accountKeyIndexes.map((N)=>({pubkey:q.staticAccountKeys[N],isSigner:!1,isWritable:!1}));Z.push(new D.TransactionInstruction({keys:Y,programId:J,data:X.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,$){let q=Date.now();if(q>Q.expiresAt)throw j.expiredCode(Q.code,Q.expiresAt,q);let Z=this.parseMeta($);if(!Z)throw j.missingMeta();if(Z.ver!==2)throw j.metaMismatch("2",String(Z.ver),"ver");let X=V8(Q.code);if(Z.id!==X)throw j.metaMismatch(X,Z.id,"id");if(Z.int!==Q.pubkey)throw j.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw j.missingMeta();let q=$.int;if(!q)throw j.invalidMetaFormat("Missing 'int' (intendedFor) field");let Z;try{Z=new D.PublicKey(q)}catch{throw j.invalidPubkeyFormat(q,"Invalid public key format")}let X=[];if(Q instanceof D.Transaction){if(!Q.signatures.some((Y)=>{if(!Y.signature)return!1;return X.push(Y.publicKey.toString()),Y.publicKey.equals(Z)}))throw j.transactionNotSignedByIntendedOwner(q,X);return}if(Q instanceof D.VersionedTransaction){let J=Q.message;if(J instanceof D.MessageV0){let Y=J.header.numRequiredSignatures;for(let N=0;N<Y;N++){let U=J.staticAccountKeys[N];if(U){if(X.push(U.toString()),U.equals(Z))return}}throw j.transactionNotSignedByIntendedOwner(q,X)}}throw j.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,$){let q=$8.createProtocolMetaIx($);if(Q instanceof D.Transaction)return Q.add(q),Q;if(Q instanceof D.VersionedTransaction){let Z=Q.message,X=[...Z.staticAccountKeys];if(!X.some((K)=>K.equals(S.MEMO_PROGRAM_ID)))X.push(S.MEMO_PROGRAM_ID);let Y={programIdIndex:X.findIndex((K)=>K.equals(S.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:q.data},N=new D.MessageV0({header:Z.header,staticAccountKeys:X,recentBlockhash:Z.recentBlockhash,compiledInstructions:[...Z.compiledInstructions,Y],addressTableLookups:Z.addressTableLookups}),U=new D.VersionedTransaction(N);return U.signatures=Q.signatures,U}throw Error("Unsupported transaction type")}}class K0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new $8,this._walletStrategy=new n(Q),this._delegationStrategy=new V(Q)}getConfig(){return this.config}registerAdapter(Q,$){this.adapters[Q]=$}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}get delegationStrategy(){return this._delegationStrategy}createDelegationCertificateTemplate(Q,$=3600000,q="solana"){return V.createDelegationCertificateTemplate(Q,$,q)}generateCode(Q,$,q){if(Q==="wallet")return this.walletStrategy.generateCode($,q);else return this.delegationStrategy.generateDelegatedCode($)}validateCode(Q,$,q){if(Q==="wallet"){if(this.walletStrategy.validateCode($),!q)return;let Z=q,X=this.getAdapter(Z.chain);if(!X)throw j.invalidAdapter(Z.chain);if(!X.verifyWithWallet({...Z,canonicalMessageParts:{pubkey:$.pubkey,windowStart:$.timestamp}}))throw Error("Signature verification failed")}else{let Z=q,X=this.getAdapter(Z.chain);if(!X)throw j.invalidAdapter(Z.chain);if(!X.verifyWithDelegation({chain:Z.chain,pubkey:Z.delegator,signature:Z.signature,certificate:Z}))throw Error("Signature verification failed")}}}
1
+ var G0=Object.create;var{getPrototypeOf:O0,defineProperty:i,getOwnPropertyNames:p8,getOwnPropertyDescriptor:F0}=Object,f8=Object.prototype.hasOwnProperty;var H8=(Q,$,q)=>{q=Q!=null?G0(O0(Q)):{};let Z=$||!Q||!Q.__esModule?i(q,"default",{value:Q,enumerable:!0}):q;for(let X of p8(Q))if(!f8.call(Z,X))i(Z,X,{get:()=>Q[X],enumerable:!0});return Z},m8=new WeakMap,P0=(Q)=>{var $=m8.get(Q),q;if($)return $;if($=i({},"__esModule",{value:!0}),Q&&typeof Q==="object"||typeof Q==="function")p8(Q).map((Z)=>!f8.call($,Z)&&i($,Z,{get:()=>Q[Z],enumerable:!(q=F0(Q,Z))||q.enumerable}));return m8.set(Q,$),$};var v0=(Q,$)=>{for(var q in $)i(Q,q,{get:$[q],enumerable:!0,configurable:!0,set:(Z)=>$[q]=()=>Z})};var _0={};v0(_0,{truncateBits:()=>j8,sha256:()=>u,serializeCanonical:()=>C,hmacSha256:()=>n,hkdfSha256:()=>C0,generateRandomSecret:()=>m0,generateNonce:()=>I8,digestToDigits:()=>K8,codeHash:()=>V8,base32EncodeCrockford:()=>y0,WalletStrategy:()=>r,SolanaAdapter:()=>q8,SUPPORTED_CHAINS:()=>g0,PROTOCOL_NORMALIZATION:()=>R8,PROTOCOL_META_MAX_BYTES:()=>c,DelegationStrategy:()=>V,CODE_MIN_LENGTH:()=>G8,CODE_MAX_LENGTH:()=>O8,CODE_DEFAULT_LENGTH:()=>H0,CODE_CHARSET_DIGITS:()=>S0,CANONICAL_MESSAGE_VERSION:()=>p0,CANONICAL_MESSAGE_PREFIX:()=>f0,BaseChainAdapter:()=>a,ActionCodesProtocol:()=>K0});module.exports=P0(_0);class a{}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function D0(Q){return Q instanceof Uint8Array||ArrayBuffer.isView(Q)&&Q.constructor.name==="Uint8Array"}function J8(Q,$=""){if(!Number.isSafeInteger(Q)||Q<0){let q=$&&`"${$}" `;throw Error(`${q}expected integer >= 0, got ${Q}`)}}function p(Q,$,q=""){let Z=D0(Q),X=Q?.length,J=$!==void 0;if(!Z||J&&X!==$){let Y=q&&`"${q}" `,z=J?` of length ${$}`:"",U=Z?`length=${X}`:`type=${typeof Q}`;throw Error(Y+"expected Uint8Array"+z+", got "+U)}return Q}function e(Q){if(typeof Q!=="function"||typeof Q.create!=="function")throw Error("Hash must wrapped by utils.createHasher");J8(Q.outputLen),J8(Q.blockLen)}function d(Q,$=!0){if(Q.destroyed)throw Error("Hash instance has been destroyed");if($&&Q.finished)throw Error("Hash#digest() has already been called")}function S8(Q,$){p(Q,void 0,"digestInto() output");let q=$.outputLen;if(Q.length<q)throw Error('"digestInto() output" expected to be of length >='+q)}function T(...Q){for(let $=0;$<Q.length;$++)Q[$].fill(0)}function Y8(Q){return new DataView(Q.buffer,Q.byteOffset,Q.byteLength)}function k(Q,$){return Q<<32-$|Q>>>$}function g8(Q,$={}){let q=(X,J)=>Q(J).update(X).digest(),Z=Q(void 0);return q.outputLen=Z.outputLen,q.blockLen=Z.blockLen,q.create=(X)=>Q(X),Object.assign(q,$),Object.freeze(q)}var _8=(Q)=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,Q])});function A8(Q,$,q){return Q&$^~Q&q}function u8(Q,$,q){return Q&$^Q&q^$&q}class N8{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(Q,$,q,Z){this.blockLen=Q,this.outputLen=$,this.padOffset=q,this.isLE=Z,this.buffer=new Uint8Array(Q),this.view=Y8(this.buffer)}update(Q){d(this),p(Q);let{view:$,buffer:q,blockLen:Z}=this,X=Q.length;for(let J=0;J<X;){let Y=Math.min(Z-this.pos,X-J);if(Y===Z){let z=Y8(Q);for(;Z<=X-J;J+=Z)this.process(z,J);continue}if(q.set(Q.subarray(J,J+Y),this.pos),this.pos+=Y,J+=Y,this.pos===Z)this.process($,0),this.pos=0}return this.length+=Q.length,this.roundClean(),this}digestInto(Q){d(this),S8(Q,this),this.finished=!0;let{buffer:$,view:q,blockLen:Z,isLE:X}=this,{pos:J}=this;if($[J++]=128,T(this.buffer.subarray(J)),this.padOffset>Z-J)this.process(q,0),J=0;for(let N=J;N<Z;N++)$[N]=0;q.setBigUint64(Z-8,BigInt(this.length*8),X),this.process(q,0);let Y=Y8(Q),z=this.outputLen;if(z%4)throw Error("_sha2: outputLen must be aligned to 32bit");let U=z/4,K=this.get();if(U>K.length)throw Error("_sha2: outputLen bigger than state");for(let N=0;N<U;N++)Y.setUint32(4*N,K[N],X)}digest(){let{buffer:Q,outputLen:$}=this;this.digestInto(Q);let q=Q.slice(0,$);return this.destroy(),q}_cloneInto(Q){Q||=new this.constructor,Q.set(...this.get());let{blockLen:$,buffer:q,length:Z,finished:X,destroyed:J,pos:Y}=this;if(Q.destroyed=J,Q.finished=X,Q.length=Z,Q.pos=Y,Z%$)Q.buffer.set(q);return Q}clone(){return this._cloneInto()}}var b=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),B=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),v=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),D=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var z8=BigInt(4294967295),d8=BigInt(32);function W0(Q,$=!1){if($)return{h:Number(Q&z8),l:Number(Q>>d8&z8)};return{h:Number(Q>>d8&z8)|0,l:Number(Q&z8)|0}}function h8(Q,$=!1){let q=Q.length,Z=new Uint32Array(q),X=new Uint32Array(q);for(let J=0;J<q;J++){let{h:Y,l:z}=W0(Q[J],$);[Z[J],X[J]]=[Y,z]}return[Z,X]}var w8=(Q,$,q)=>Q>>>q,L8=(Q,$,q)=>Q<<32-q|$>>>q,_=(Q,$,q)=>Q>>>q|$<<32-q,A=(Q,$,q)=>Q<<32-q|$>>>q,t=(Q,$,q)=>Q<<64-q|$>>>q-32,Q8=(Q,$,q)=>Q>>>q-32|$<<64-q;function I(Q,$,q,Z){let X=($>>>0)+(Z>>>0);return{h:Q+q+(X/4294967296|0)|0,l:X|0}}var l8=(Q,$,q)=>(Q>>>0)+($>>>0)+(q>>>0),n8=(Q,$,q,Z)=>$+q+Z+(Q/4294967296|0)|0,c8=(Q,$,q,Z)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0),r8=(Q,$,q,Z,X)=>$+q+Z+X+(Q/4294967296|0)|0,o8=(Q,$,q,Z,X)=>(Q>>>0)+($>>>0)+(q>>>0)+(Z>>>0)+(X>>>0),s8=(Q,$,q,Z,X,J)=>$+q+Z+X+J+(Q/4294967296|0)|0;var L0=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]),f=new Uint32Array(64);class M8 extends N8{constructor(Q){super(64,Q,8,!1)}get(){let{A:Q,B:$,C:q,D:Z,E:X,F:J,G:Y,H:z}=this;return[Q,$,q,Z,X,J,Y,z]}set(Q,$,q,Z,X,J,Y,z){this.A=Q|0,this.B=$|0,this.C=q|0,this.D=Z|0,this.E=X|0,this.F=J|0,this.G=Y|0,this.H=z|0}process(Q,$){for(let N=0;N<16;N++,$+=4)f[N]=Q.getUint32($,!1);for(let N=16;N<64;N++){let R=f[N-15],G=f[N-2],F=k(R,7)^k(R,18)^R>>>3,P=k(G,17)^k(G,19)^G>>>10;f[N]=P+f[N-7]+F+f[N-16]|0}let{A:q,B:Z,C:X,D:J,E:Y,F:z,G:U,H:K}=this;for(let N=0;N<64;N++){let R=k(Y,6)^k(Y,11)^k(Y,25),G=K+R+A8(Y,z,U)+L0[N]+f[N]|0,P=(k(q,2)^k(q,13)^k(q,22))+u8(q,Z,X)|0;K=U,U=z,z=Y,Y=J+G|0,J=X,X=Z,Z=q,q=G+P|0}q=q+this.A|0,Z=Z+this.B|0,X=X+this.C|0,J=J+this.D|0,Y=Y+this.E|0,z=z+this.F|0,U=U+this.G|0,K=K+this.H|0,this.set(q,Z,X,J,Y,z,U,K)}roundClean(){T(f)}destroy(){this.set(0,0,0,0,0,0,0,0),T(this.buffer)}}class i8 extends M8{A=b[0]|0;B=b[1]|0;C=b[2]|0;D=b[3]|0;E=b[4]|0;F=b[5]|0;G=b[6]|0;H=b[7]|0;constructor(){super(32)}}class M0 extends M8{A=B[0]|0;B=B[1]|0;C=B[2]|0;D=B[3]|0;E=B[4]|0;F=B[5]|0;G=B[6]|0;H=B[7]|0;constructor(){super(28)}}var a8=(()=>h8(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((Q)=>BigInt(Q))))(),T0=(()=>a8[0])(),k0=(()=>a8[1])(),H=new Uint32Array(80),S=new Uint32Array(80);class $8 extends N8{constructor(Q){super(128,Q,16,!1)}get(){let{Ah:Q,Al:$,Bh:q,Bl:Z,Ch:X,Cl:J,Dh:Y,Dl:z,Eh:U,El:K,Fh:N,Fl:R,Gh:G,Gl:F,Hh:P,Hl:M}=this;return[Q,$,q,Z,X,J,Y,z,U,K,N,R,G,F,P,M]}set(Q,$,q,Z,X,J,Y,z,U,K,N,R,G,F,P,M){this.Ah=Q|0,this.Al=$|0,this.Bh=q|0,this.Bl=Z|0,this.Ch=X|0,this.Cl=J|0,this.Dh=Y|0,this.Dl=z|0,this.Eh=U|0,this.El=K|0,this.Fh=N|0,this.Fl=R|0,this.Gh=G|0,this.Gl=F|0,this.Hh=P|0,this.Hl=M|0}process(Q,$){for(let O=0;O<16;O++,$+=4)H[O]=Q.getUint32($),S[O]=Q.getUint32($+=4);for(let O=16;O<80;O++){let y=H[O-15]|0,m=S[O-15]|0,P8=_(y,m,1)^_(y,m,8)^w8(y,m,7),v8=A(y,m,1)^A(y,m,8)^L8(y,m,7),E=H[O-2]|0,x=S[O-2]|0,Z8=_(E,x,19)^t(E,x,61)^w8(E,x,6),D8=A(E,x,19)^Q8(E,x,61)^L8(E,x,6),X8=c8(v8,D8,S[O-7],S[O-16]),W8=r8(X8,P8,Z8,H[O-7],H[O-16]);H[O]=W8|0,S[O]=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Fl=D[11]|0;Gh=D[12]|0;Gl=D[13]|0;Hh=D[14]|0;Hl=D[15]|0;constructor(){super(64)}}class I0 extends $8{Ah=v[0]|0;Al=v[1]|0;Bh=v[2]|0;Bl=v[3]|0;Ch=v[4]|0;Cl=v[5]|0;Dh=v[6]|0;Dl=v[7]|0;Eh=v[8]|0;El=v[9]|0;Fh=v[10]|0;Fl=v[11]|0;Gh=v[12]|0;Gl=v[13]|0;Hh=v[14]|0;Hl=v[15]|0;constructor(){super(48)}}var w=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),L=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class E0 extends $8{Ah=w[0]|0;Al=w[1]|0;Bh=w[2]|0;Bl=w[3]|0;Ch=w[4]|0;Cl=w[5]|0;Dh=w[6]|0;Dl=w[7]|0;Eh=w[8]|0;El=w[9]|0;Fh=w[10]|0;Fl=w[11]|0;Gh=w[12]|0;Gl=w[13]|0;Hh=w[14]|0;Hl=w[15]|0;constructor(){super(28)}}class x0 extends $8{Ah=L[0]|0;Al=L[1]|0;Bh=L[2]|0;Bl=L[3]|0;Ch=L[4]|0;Cl=L[5]|0;Dh=L[6]|0;Dl=L[7]|0;Eh=L[8]|0;El=L[9]|0;Fh=L[10]|0;Fl=L[11]|0;Gh=L[12]|0;Gl=L[13]|0;Hh=L[14]|0;Hl=L[15]|0;constructor(){super(32)}}var U8=g8(()=>new i8,_8(1));class T8{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(Q,$){if(e(Q),p($,void 0,"key"),this.iHash=Q.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let q=this.blockLen,Z=new Uint8Array(q);Z.set($.length>q?Q.create().update($).digest():$);for(let X=0;X<Z.length;X++)Z[X]^=54;this.iHash.update(Z),this.oHash=Q.create();for(let X=0;X<Z.length;X++)Z[X]^=106;this.oHash.update(Z),T(Z)}update(Q){return d(this),this.iHash.update(Q),this}digestInto(Q){d(this),p(Q,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(Q),this.oHash.update(Q),this.oHash.digestInto(Q),this.destroy()}digest(){let Q=new Uint8Array(this.oHash.outputLen);return this.digestInto(Q),Q}_cloneInto(Q){Q||=Object.create(Object.getPrototypeOf(this),{});let{oHash:$,iHash:q,finished:Z,destroyed:X,blockLen:J,outputLen:Y}=this;return Q=Q,Q.finished=Z,Q.destroyed=X,Q.blockLen=J,Q.outputLen=Y,Q.oHash=$._cloneInto(Q.oHash),Q.iHash=q._cloneInto(Q.iHash),Q}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var h=(Q,$,q)=>new T8(Q,$).update(q).digest();h.create=(Q,$)=>new T8(Q,$);function b0(Q,$,q){if(e(Q),q===void 0)q=new Uint8Array(Q.outputLen);return h(Q,q,$)}var k8=Uint8Array.of(0),e8=Uint8Array.of();function B0(Q,$,q,Z=32){e(Q),J8(Z,"length");let X=Q.outputLen;if(Z>255*X)throw Error("Length must be <= 255*HashLen");let J=Math.ceil(Z/X);if(q===void 0)q=e8;else p(q,void 0,"info");let Y=new Uint8Array(J*X),z=h.create(Q,$),U=z._cloneInto(),K=new Uint8Array(z.outputLen);for(let N=0;N<J;N++)k8[0]=N+1,U.update(N===0?e8:K).update(q).update(k8).digestInto(K),Y.set(K,X*N),z._cloneInto(U);return z.destroy(),U.destroy(),T(K,k8),Y.slice(0,Z)}var t8=(Q,$,q,Z,X)=>B0(Q,b0(Q,$,q),Z,X);function l(Q){if(typeof Q==="string")return new TextEncoder().encode(Q);return Q}function u(Q){return U8(l(Q))}function n(Q,$){return h(U8,l(Q),l($))}function C0(Q,$,{salt:q,info:Z}={}){let X=q?l(q):new Uint8Array(32),J=l(Q),Y=Z?l(Z):new Uint8Array(0);return t8(U8,J,X,Y,$)}var Q0="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function y0(Q){let $=0,q=0,Z="";for(let X=0;X<Q.length;X++){q=q<<8|Q[X],$+=8;while($>=5)Z+=Q0[q>>>$-5&31],$-=5}if($>0)Z+=Q0[q<<5-$&31];return Z}function j8(Q,$){let q=Math.ceil($/8),Z=new Uint8Array(q),X=Math.min(q,Q.length);Z.set(Q.subarray(0,X));let J=q*8-$;if(J>0){let Y=255<<J;Z[q-1]=Z[q-1]&Y}return Z}function K8(Q,$){if(Q.length===0)throw Error("digestToDigits: empty digest");let q="",Z=Q[Q.length-1]&15;for(let X=0;q.length<$;X++){let J=(Z+X*4)%Math.max(1,Q.length-4),U=(((Q[J]&127)<<24|Q[J+1]<<16|Q[J+2]<<8|Q[J+3])%1e9).toString().padStart(9,"0");q+=U}return q.slice(0,$)}function V8(Q){let $=u(Q);return Array.from($).map((q)=>q.toString(16).padStart(2,"0")).join("")}function m0(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}function I8(){let Q=new Uint8Array(32);return crypto.getRandomValues(Q),btoa(String.fromCharCode(...Q))}var p0=1,f0="actioncodes";function C(Q){let $=JSON.stringify({id:"actioncodes",ver:1,pubkey:Q.pubkey,windowStart:Q.windowStart,...Q.secret&&{secret:Q.secret}});return new TextEncoder().encode($)}var R8="NFC",c=256,G8=6,O8=24,H0=8,S0="0123456789",g0=["solana"];class j extends Error{code;details;constructor(Q,$,q){super($);this.code=Q;this.details=q;this.name="ProtocolError"}static expiredCode(Q,$,q){return new $0(Q,$,q)}static invalidCode(Q,$){return new j("INVALID_CODE",`Invalid code: expected '${Q}', got '${$}'`,{expected:Q,actual:$})}static invalidCodeFormat(Q,$){return new N0(Q,$)}static invalidSignature(Q){return new Y0(Q)}static missingMeta(){return new q0}static invalidMetaFormat(Q){return new j("INVALID_META_FORMAT",`Invalid protocol meta format: ${Q}`,{reason:Q})}static metaMismatch(Q,$,q){return new Z0(Q,$,q)}static metaTooLarge(Q,$){return new j("META_TOO_LARGE",`Protocol meta too large: ${$} bytes (max: ${Q})`,{maxBytes:Q,actualBytes:$})}static transactionNotSignedByIntendedOwner(Q,$){return new X0(Q,$)}static invalidTransactionFormat(Q){return new j("INVALID_TRANSACTION_FORMAT",`Invalid transaction format: ${Q}`,{reason:Q})}static invalidPubkeyFormat(Q,$){return new J0(Q,$)}static invalidInput(Q,$,q){return new j("INVALID_INPUT",`Invalid ${Q}: ${q}`,{field:Q,value:$,reason:q})}static missingRequiredField(Q){return new j("MISSING_REQUIRED_FIELD",`Missing required field: ${Q}`,{field:Q})}static cryptoError(Q,$){return new j("CRYPTO_ERROR",`Crypto error in ${Q}: ${$}`,{operation:Q,reason:$})}static invalidDigest(Q){return new j("INVALID_DIGEST",`Invalid digest: ${Q}`,{reason:Q})}static invalidAdapter(Q){return new z0(Q)}static create(Q,$,q){return new j(Q,$,q)}}class $0 extends j{constructor(Q,$,q){super("EXPIRED_CODE",`Action code '${Q}' expired at ${$}, current time: ${q}`,{code:Q,expiresAt:$,currentTime:q});this.name="ExpiredCodeError"}}class q0 extends j{constructor(){super("MISSING_META","Transaction does not contain valid protocol meta");this.name="MissingMetaError"}}class Z0 extends j{constructor(Q,$,q){super("META_MISMATCH",`Meta ${q} mismatch: expected '${Q}', got '${$}'`,{expected:Q,actual:$,field:q});this.name="MetaMismatchError"}}class X0 extends j{constructor(Q,$){super("TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",`Transaction not signed by intended owner '${Q}'. Actual signers: [${$.join(", ")}]`,{intended:Q,actualSigners:$});this.name="TransactionNotSignedByIntendedOwnerError"}}class J0 extends j{constructor(Q,$){super("INVALID_PUBKEY_FORMAT",`Invalid public key format '${Q}': ${$}`,{pubkey:Q,reason:$});this.name="InvalidPubkeyFormatError"}}class Y0 extends j{constructor(Q){super("INVALID_SIGNATURE",`Invalid signature: ${Q}`,{reason:Q});this.name="InvalidSignatureError"}}class N0 extends j{constructor(Q,$){super("INVALID_CODE_FORMAT",`Invalid code format '${Q}': ${$}`,{code:Q,reason:$});this.name="InvalidCodeFormatError"}}class z0 extends j{constructor(Q){super("INVALID_ADAPTER",`Invalid adapter: ${Q}`,{adapter:Q});this.name="InvalidAdapterError"}}class r{config;constructor(Q){this.config=Q}generateCode(Q,$,q){let Z=Q,X=JSON.parse(new TextDecoder().decode(Z)),J=X.pubkey,Y=X.windowStart,z=q,U;if($){let F=new TextEncoder().encode($);U=n(F,Z)}else if(z)U=n(z,Z);else U=u(Z);let K=Math.max(G8,Math.min(O8,this.config.codeLength)),N=j8(U,8*Math.ceil(K/2));return{actionCode:{code:K8(N,K),pubkey:J,timestamp:Y,expiresAt:Y+this.config.ttlMs,...$&&{signature:$},...z&&{secret:z}},canonicalMessage:Z}}validateCode(Q){let $=Date.now();if($>Q.expiresAt+(this.config.clockSkewMs??0))throw j.expiredCode(Q.code,Q.expiresAt,$);let q=C({pubkey:Q.pubkey,windowStart:Q.timestamp,secret:Q.secret}),Z;if(Q.signature){let z=new TextEncoder().encode(Q.signature);Z=n(z,q)}else if(Q.secret)Z=n(Q.secret,q);else Z=u(q);let X=Math.max(G8,Math.min(O8,this.config.codeLength)),J=j8(Z,8*Math.ceil(X/2)),Y=K8(J,X);if(Y!==Q.code)throw j.invalidCode(Y,Q.code)}}class V{walletStrategy;config;constructor(Q){this.config=Q,this.walletStrategy=new r(Q)}static createDelegationCertificateTemplate(Q,$=3600000,q="solana"){let Z=Date.now();return{version:"1.0",delegator:Q,issuedAt:Z,expiresAt:Z+$,nonce:I8(),chain:q}}generateDelegatedCode(Q){if(!this.validateCertificate(Q))throw Error("Invalid delegation certificate");let $=V.hashCertificate(Q),q=Math.floor(Date.now()/this.config.ttlMs)*this.config.ttlMs,Z=C({pubkey:Q.delegator,windowStart:q,secret:$});return{actionCode:{...this.walletStrategy.generateCode(Z,"",$).actionCode,delegationId:V.hashCertificate(Q),delegatedBy:Q.delegator}}}validateDelegatedCode(Q,$){if(this.walletStrategy.validateCode(Q),!this.validateCertificate($))throw Error("Delegation certificate expired or invalid");if(Q.delegationId!==V.hashCertificate($))throw Error("Action code does not match delegation certificate");if(Q.delegatedBy!==$.delegator)throw Error("Action code delegator does not match certificate")}validateCertificate(Q){if(Date.now()>Q.expiresAt)return!1;if(Date.now()<Q.issuedAt)return!1;if(!Q.version||!Q.delegator||!Q.issuedAt||!Q.expiresAt||!Q.nonce||!Q.chain||!Q.signature)return!1;if(Q.version!=="1.0")return!1;return!0}static serializeCertificate(Q){let $=JSON.stringify({version:Q.version,delegator:Q.delegator,issuedAt:Q.issuedAt,expiresAt:Q.expiresAt,nonce:Q.nonce,chain:Q.chain});return new TextEncoder().encode($)}static hashCertificate(Q){let $=this.serializeCertificate(Q),q=new TextEncoder().encode(Q.signature),Z=new Uint8Array($.length+q.length);Z.set($,0),Z.set(q,$.length);let X=u(Z);return Array.from(X).map((J)=>J.toString(16).padStart(2,"0")).join("")}static validateCertificateStructure(Q){if(!Q.version||!Q.delegator||!Q.issuedAt||!Q.expiresAt||!Q.nonce||!Q.chain||!Q.signature)return!1;if(Q.version!=="1.0")return!1;if(Date.now()>Q.expiresAt)return!1;if(Date.now()<Q.issuedAt)return!1;return!0}getWalletStrategy(){return this.walletStrategy}}var B8=H8(require("tweetnacl")),C8=H8(require("bs58")),W=require("@solana/web3.js"),g=require("@solana/spl-memo");var E8="actioncodes:";function x8(Q){let $=U0(Q);if($.int!=null)F8($.int);let q=[`ver=${$.ver}`,`id=${encodeURIComponent($.id)}`,`int=${encodeURIComponent($.int)}`];if($.p!=null&&Object.keys($.p).length>0){let X=JSON.stringify($.p);F8(X),q.push(`p=${encodeURIComponent(X)}`)}let Z=E8+q.join("&");return j0(Z),Z}function b8(Q){if(!Q.startsWith(E8))throw Error("protocol meta must start with actioncodes:");let q=Q.slice(E8.length).split("&").filter(Boolean),Z=new Map;for(let G of q){let[F,P]=G.split("=",2);if(!F)continue;let M=P!=null?decodeURIComponent(P):"";Z.set(F,M)}let X=Z.get("ver"),J=Z.get("id"),Y=Z.get("int"),z=Z.get("p");if(X==null||J==null||Y==null)throw Error("protocol meta missing required fields ver or id or int");let U=Number(X);if(!Number.isInteger(U)||U<=0)throw Error("protocol meta ver must be positive integer");let K;if(z!=null&&z!=="")try{if(K=JSON.parse(z),typeof K!=="object"||K===null||Array.isArray(K))throw Error("protocol meta p must be a JSON object")}catch{throw Error("protocol meta p must be valid JSON")}let N=U0({ver:U,id:J,int:Y,p:K});if(N.int!=null)F8(N.int);if(N.p!=null)F8(JSON.stringify(N.p));if([...Z.keys()].filter((G)=>G!=="ver"&&G!=="id"&&G!=="int"&&G!=="p").length>0)throw Error("protocol meta contains unsupported keys");return j0(x8(N)),N}function U0(Q){let $=Q.id.normalize(R8).trim(),q={ver:Q.ver,id:$,int:Q.int};if(Q.int!=null)q.int=Q.int.normalize(R8).trim();if(Q.p!=null)q.p=Q.p;return q}function j0(Q){if(new TextEncoder().encode(Q).length>c)throw Error(`protocol meta exceeds ${c} bytes`)}function F8(Q){if(new TextEncoder().encode(Q).length>c)throw Error(`protocol meta params exceed ${c} bytes`)}class q8 extends a{normalizePubkey(Q){if(typeof Q==="string")return new W.PublicKey(Q);return Q}verifyWithWallet(Q){if(Q.chain!=="solana")return!1;if(!Q.pubkey||!Q.signature||!Q.canonicalMessageParts)return!1;try{let $=C(Q.canonicalMessageParts),q=this.normalizePubkey(Q.pubkey),Z=C8.default.decode(Q.signature),X=q.toBytes();if(Z.length!==64||X.length!==32)return!1;return B8.default.sign.detached.verify($,Z,X)}catch{return!1}}verifyWithDelegation(Q){if(Q.chain!=="solana")return!1;if(!Q.pubkey||!Q.signature||!Q.certificate)return!1;let $=Q.certificate;if(!V.validateCertificateStructure($))return!1;if($.delegator!==Q.pubkey)return!1;if($.chain!==Q.chain)return!1;try{let q={version:$.version,delegator:$.delegator,issuedAt:$.issuedAt,expiresAt:$.expiresAt,nonce:$.nonce,chain:$.chain},Z=V.serializeCertificate(q),X=this.normalizePubkey(Q.pubkey),J=C8.default.decode(Q.signature),Y=X.toBytes();if(J.length!==64||Y.length!==32)return!1;return B8.default.sign.detached.verify(Z,J,Y)}catch{return!1}}static createProtocolMetaIx(Q){let $=x8(Q);return g.createMemoInstruction($)}getProtocolMeta(Q){for(let $ of this.getMemoInstructions(Q)){let q=$.data;try{let Z=new TextDecoder().decode(q);if(b8(Z))return Z}catch{}}return null}parseMeta(Q){let $=this.getProtocolMeta(Q);if(!$)return null;return b8($)}getMemoInstructions(Q){if(Q instanceof W.Transaction)return Q.instructions.filter(($)=>$.programId.equals(g.MEMO_PROGRAM_ID));else{let q=Q.message;if(q instanceof W.MessageV0){let Z=[];for(let X of q.compiledInstructions){let J=q.staticAccountKeys[X.programIdIndex];if(J&&J.equals(g.MEMO_PROGRAM_ID)){let Y=X.accountKeyIndexes.map((z)=>({pubkey:q.staticAccountKeys[z],isSigner:!1,isWritable:!1}));Z.push(new W.TransactionInstruction({keys:Y,programId:J,data:X.data}))}}return Z}return[]}}verifyTransactionMatchesCode(Q,$){let q=Date.now();if(q>Q.expiresAt)throw j.expiredCode(Q.code,Q.expiresAt,q);let Z=this.parseMeta($);if(!Z)throw j.missingMeta();if(Z.ver!==2)throw j.metaMismatch("2",String(Z.ver),"ver");let X=V8(Q.code);if(Z.id!==X)throw j.metaMismatch(X,Z.id,"id");if(Z.int!==Q.pubkey)throw j.metaMismatch(Q.pubkey,Z.int,"int")}verifyTransactionSignedByIntentOwner(Q){let $=this.parseMeta(Q);if(!$)throw j.missingMeta();let q=$.int;if(!q)throw j.invalidMetaFormat("Missing 'int' (intendedFor) field");let Z;try{Z=new W.PublicKey(q)}catch{throw j.invalidPubkeyFormat(q,"Invalid public key format")}let X=[];if(Q instanceof W.Transaction){if(!Q.signatures.some((Y)=>{if(!Y.signature)return!1;return X.push(Y.publicKey.toString()),Y.publicKey.equals(Z)}))throw j.transactionNotSignedByIntendedOwner(q,X);return}if(Q instanceof W.VersionedTransaction){let J=Q.message;if(J instanceof W.MessageV0){let Y=J.header.numRequiredSignatures;for(let z=0;z<Y;z++){let U=J.staticAccountKeys[z];if(U){if(X.push(U.toString()),U.equals(Z))return}}throw j.transactionNotSignedByIntendedOwner(q,X)}}throw j.invalidTransactionFormat("Unsupported transaction format")}static attachProtocolMeta(Q,$){let q=q8.createProtocolMetaIx($);if(Q instanceof W.Transaction)return Q.add(q),Q;if(Q instanceof W.VersionedTransaction){let Z=Q.message,X=[...Z.staticAccountKeys];if(!X.some((K)=>K.equals(g.MEMO_PROGRAM_ID)))X.push(g.MEMO_PROGRAM_ID);let Y={programIdIndex:X.findIndex((K)=>K.equals(g.MEMO_PROGRAM_ID)),accountKeyIndexes:[],data:q.data},z=new W.MessageV0({header:Z.header,staticAccountKeys:X,recentBlockhash:Z.recentBlockhash,compiledInstructions:[...Z.compiledInstructions,Y],addressTableLookups:Z.addressTableLookups}),U=new W.VersionedTransaction(z);return U.signatures=Q.signatures,U}throw Error("Unsupported transaction type")}}class K0{config;adapters={};_walletStrategy;_delegationStrategy;constructor(Q){this.config=Q;this.adapters.solana=new q8,this._walletStrategy=new r(Q),this._delegationStrategy=new V(Q)}getConfig(){return this.config}registerAdapter(Q,$){this.adapters[Q]=$}getAdapter(Q){return this.adapters[Q]}get adapter(){return{solana:this.adapters.solana}}get walletStrategy(){return this._walletStrategy}getCanonicalMessageParts(Q,$){let q=Math.floor(Date.now()/this.config.ttlMs)*this.config.ttlMs;return C({pubkey:Q,windowStart:q,secret:$})}get delegationStrategy(){return this._delegationStrategy}createDelegationCertificateTemplate(Q,$=3600000,q="solana"){return V.createDelegationCertificateTemplate(Q,$,q)}generateCode(Q,$,q,Z){if(Q==="wallet"){if(!q)throw j.invalidSignature("Missing signature over canonical message");return this.walletStrategy.generateCode($,q,Z)}else return this.delegationStrategy.generateDelegatedCode($)}validateCode(Q,$,q){if(Q==="wallet"){if(this.walletStrategy.validateCode($),!q)return;let Z=q,X=this.getAdapter(Z.chain);if(!X)throw j.invalidAdapter(Z.chain);if(!X.verifyWithWallet({...Z,canonicalMessageParts:{pubkey:$.pubkey,windowStart:$.timestamp}}))throw Error("Signature verification failed")}else{let Z=q;this.delegationStrategy.validateDelegatedCode($,Z);let X=this.getAdapter(Z.chain);if(!X)throw j.invalidAdapter(Z.chain);if(!X.verifyWithDelegation({chain:Z.chain,pubkey:Z.delegator,signature:Z.signature,certificate:Z}))throw Error("Signature verification failed")}}}
2
2
 
3
- //# debugId=378EC37CD0386CC964756E2164756E21
3
+ //# debugId=2B3E0B14432E14F764756E2164756E21