@actioncodes/protocol 1.2.2 → 2.0.0
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 +1 -1
- package/README.md +32 -45
- package/dist/ActionCodesProtocol.d.ts +35 -0
- package/dist/ActionCodesProtocol.d.ts.map +1 -0
- package/dist/adapters/BaseChainAdapter.d.ts +22 -0
- package/dist/adapters/BaseChainAdapter.d.ts.map +1 -0
- package/dist/adapters/SolanaAdapter.d.ts +44 -0
- package/dist/adapters/SolanaAdapter.d.ts.map +1 -0
- package/dist/constants.d.ts +6 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/errors.d.ts +63 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +25 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -36
- package/dist/index.js.map +25 -0
- package/dist/strategy/DelegationStrategy.d.ts +43 -0
- package/dist/strategy/DelegationStrategy.d.ts.map +1 -0
- package/dist/strategy/WalletStrategy.d.ts +8 -0
- package/dist/strategy/WalletStrategy.d.ts.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/canonical.d.ts +5 -0
- package/dist/utils/canonical.d.ts.map +1 -0
- package/dist/utils/crypto.d.ts +13 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/protocolMeta.d.ts +16 -0
- package/dist/utils/protocolMeta.d.ts.map +1 -0
- package/docs/ActionCodesProtocol/README.md +11 -0
- package/docs/ActionCodesProtocol/classes/ActionCodesProtocol.md +147 -0
- package/docs/README.md +10 -50
- package/docs/adapters/BaseChainAdapter/README.md +20 -0
- package/docs/adapters/BaseChainAdapter/classes/BaseChainAdapter.md +56 -0
- package/docs/adapters/BaseChainAdapter/interfaces/BaseContext.md +17 -0
- package/docs/adapters/BaseChainAdapter/interfaces/ChainAdapter.md +33 -0
- package/docs/adapters/BaseChainAdapter/type-aliases/ChainContext.md +23 -0
- package/docs/adapters/NodeCryptoAdapter/README.md +15 -0
- package/docs/adapters/NodeCryptoAdapter/classes/NodeCryptoAdapter.md +254 -0
- package/docs/adapters/NodeCryptoAdapter/type-aliases/NodeCryptoContext.md +27 -0
- package/docs/adapters/SolanaAdapter/README.md +16 -0
- package/docs/adapters/SolanaAdapter/classes/SolanaAdapter.md +190 -0
- package/docs/adapters/SolanaAdapter/type-aliases/SolanaContext.md +27 -0
- package/docs/adapters/SolanaAdapter/type-aliases/SolanaTransaction.md +13 -0
- package/docs/constants/README.md +8 -13
- package/docs/constants/variables/CODE_CHARSET_DIGITS.md +11 -0
- package/docs/constants/variables/CODE_DEFAULT_LENGTH.md +11 -0
- package/docs/constants/variables/CODE_MAX_LENGTH.md +11 -0
- package/docs/constants/variables/CODE_MIN_LENGTH.md +11 -0
- package/docs/constants/variables/PROTOCOL_META_MAX_BYTES.md +11 -0
- package/docs/constants/variables/PROTOCOL_NORMALIZATION.md +11 -0
- package/docs/constants/variables/SUPPORTED_CHAINS.md +3 -3
- package/docs/errors/README.md +22 -0
- package/docs/errors/classes/ExpiredCodeError.md +695 -0
- package/docs/errors/classes/InvalidCodeFormatError.md +691 -0
- package/docs/errors/classes/InvalidPubkeyFormatError.md +691 -0
- package/docs/errors/classes/InvalidSignatureError.md +687 -0
- package/docs/errors/classes/MetaMismatchError.md +695 -0
- package/docs/errors/classes/MissingMetaError.md +681 -0
- package/docs/errors/classes/ProtocolError.md +637 -0
- package/docs/errors/classes/TransactionNotSignedByIntendedOwnerError.md +691 -0
- package/docs/errors/enumerations/ProtocolErrorCode.md +121 -0
- package/docs/index/README.md +83 -41
- package/docs/modules.md +12 -9
- package/docs/strategy/WalletStrategy/README.md +11 -0
- package/docs/strategy/WalletStrategy/classes/WalletStrategy.md +67 -0
- package/docs/types/README.md +14 -0
- package/docs/types/interfaces/ActionCode.md +65 -0
- package/docs/types/interfaces/CanonicalMessageParts.md +33 -0
- package/docs/types/interfaces/CodeGenerationConfig.md +33 -0
- package/docs/types/interfaces/CodeGenerationResult.md +25 -0
- package/docs/utils/canonical/README.md +16 -0
- package/docs/utils/canonical/functions/serializeCanonical.md +21 -0
- package/docs/utils/canonical/variables/CANONICAL_MESSAGE_PREFIX.md +11 -0
- package/docs/utils/canonical/variables/CANONICAL_MESSAGE_VERSION.md +11 -0
- package/docs/utils/crypto/README.md +18 -0
- package/docs/utils/crypto/functions/base32EncodeCrockford.md +21 -0
- package/docs/utils/crypto/functions/codeHash.md +21 -0
- package/docs/utils/crypto/functions/digestToDigits.md +25 -0
- package/docs/utils/crypto/functions/generateRandomSecret.md +15 -0
- package/docs/utils/crypto/functions/hkdfSha256.md +35 -0
- package/docs/utils/crypto/functions/hmacSha256.md +25 -0
- package/docs/utils/crypto/functions/sha256.md +21 -0
- package/docs/utils/crypto/functions/truncateBits.md +25 -0
- package/docs/utils/protocolMeta/README.md +21 -0
- package/docs/utils/protocolMeta/functions/buildProtocolMeta.md +21 -0
- package/docs/utils/protocolMeta/functions/parseProtocolMeta.md +21 -0
- package/docs/utils/protocolMeta/functions/validateProtocolMetaFormat.md +21 -0
- package/docs/utils/protocolMeta/interfaces/ProtocolMetaFields.md +41 -0
- package/docs/utils/protocolMeta/variables/SCHEME.md +11 -0
- package/package.json +42 -47
- package/dist/actioncode.d.ts +0 -120
- package/dist/actioncode.d.ts.map +0 -1
- package/dist/actioncode.js +0 -186
- package/dist/adapters/base.d.ts +0 -93
- package/dist/adapters/base.d.ts.map +0 -1
- package/dist/adapters/base.js +0 -65
- package/dist/adapters/solana/index.d.ts +0 -2
- package/dist/adapters/solana/index.d.ts.map +0 -1
- package/dist/adapters/solana/index.js +0 -30
- package/dist/adapters/solana/solana.d.ts +0 -113
- package/dist/adapters/solana/solana.d.ts.map +0 -1
- package/dist/adapters/solana/solana.js +0 -537
- package/dist/codegen.d.ts +0 -76
- package/dist/codegen.d.ts.map +0 -1
- package/dist/codegen.js +0 -211
- package/dist/constants.js +0 -24
- package/dist/meta.d.ts +0 -54
- package/dist/meta.d.ts.map +0 -1
- package/dist/meta.js +0 -104
- package/dist/protocol.d.ts +0 -179
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js +0 -390
- package/docs/_media/LICENSE +0 -201
- package/docs/_media/README.md +0 -28
- package/docs/actioncode/README.md +0 -21
- package/docs/actioncode/classes/ActionCode.md +0 -430
- package/docs/actioncode/interfaces/ActionCodeFields.md +0 -89
- package/docs/actioncode/interfaces/ActionCodeMetadata.md +0 -25
- package/docs/actioncode/interfaces/ActionCodeTransaction.md +0 -57
- package/docs/actioncode/type-aliases/ActionCodeStatus.md +0 -11
- package/docs/adapters/base/README.md +0 -11
- package/docs/adapters/base/classes/BaseChainAdapter.md +0 -396
- package/docs/adapters/solana/README.md +0 -19
- package/docs/adapters/solana/solana/README.md +0 -15
- package/docs/adapters/solana/solana/classes/SolanaAdapter.md +0 -506
- package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +0 -13
- package/docs/codegen/README.md +0 -11
- package/docs/codegen/classes/CodeGenerator.md +0 -341
- package/docs/constants/type-aliases/SupportedChain.md +0 -11
- package/docs/constants/variables/CODE_LENGTH.md +0 -11
- package/docs/constants/variables/CODE_TTL.md +0 -11
- package/docs/constants/variables/MAX_PREFIX_LENGTH.md +0 -11
- package/docs/constants/variables/MIN_PREFIX_LENGTH.md +0 -11
- package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +0 -11
- package/docs/constants/variables/PROTOCOL_PREFIX.md +0 -11
- package/docs/constants/variables/PROTOCOL_VERSION.md +0 -11
- package/docs/meta/README.md +0 -15
- package/docs/meta/classes/ProtocolMetaParser.md +0 -177
- package/docs/meta/interfaces/ProtocolMetaV1.md +0 -59
- package/docs/protocol/README.md +0 -51
- package/docs/protocol/classes/ActionCodesProtocol.md +0 -676
- package/docs/protocol/interfaces/ProtocolConfig.md +0 -71
package/LICENSE
CHANGED
@@ -198,4 +198,4 @@
|
|
198
198
|
distributed under the License is distributed on an "AS IS" BASIS,
|
199
199
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
200
|
See the License for the specific language governing permissions and
|
201
|
-
limitations under the License.
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
@@ -1,55 +1,42 @@
|
|
1
|
-
|
1
|
+
## Action Codes Protocol
|
2
2
|
|
3
|
-
|
3
|
+
The Action Codes Protocol is a lightweight way to prove intent and authorize actions across blockchains, apps, and wallets.
|
4
|
+
Instead of heavy signature popups or complex flows, it uses short-lived one-time codes derived from canonical cryptographic messages.
|
4
5
|
|
5
|
-
|
6
|
+
### This enables:
|
7
|
+
- Secure intent binding – the code is cryptographically tied to a wallet/public key.
|
8
|
+
- Fast verification – relayers/servers can validate in microseconds.
|
9
|
+
- Cross-chain support – adapters handle chain-specific quirks (currently we are supporting Solana)
|
10
|
+
- Simple dev UX – just generate → sign → verify.
|
6
11
|
|
7
|
-
|
12
|
+
### What's new in v2 (compared to [v1](https://github.com/otaprotocol/actioncodes))
|
13
|
+
- Now we use Bun as core library. We are down to ~3ms per code signature verification on commodity hardware.
|
14
|
+
- Canonical Messages only → No ambiguity. Codes are always derived from a canonical serialization (serializeCanonical).
|
15
|
+
- No AIPs (Action Codes Improvement Proposals) → Overkill for lightweight protocol.
|
16
|
+
- Chain Adapters simplified → They don't enforce business rules; they just provide utilities:
|
17
|
+
- createProtocolMetaIx (for attaching metadata)
|
18
|
+
- parseMeta / verifyTransactionMatchesCode (for checking integrity)
|
19
|
+
- verifyTransactionSignedByIntentOwner (optional stronger guarantee).
|
20
|
+
- Errors are typed → Clear ProtocolError.* categories instead of generic fails.
|
21
|
+
- Performance focus → Benchmarked at ~3.5ms per verification on commodity hardware.
|
8
22
|
|
9
|
-
|
23
|
+
### Core Concepts
|
10
24
|
|
11
|
-
|
25
|
+
1. Action Codes
|
26
|
+
- A short-lived, one-time code bound to a wallet/public key.
|
27
|
+
- Generated using HMAC/HKDF and canonical serialization.
|
12
28
|
|
13
|
-
|
14
|
-
|
29
|
+
2. Protocol Meta
|
30
|
+
- The "payload" carried with transactions to tie them to action codes.
|
31
|
+
- Versioned, deterministic, size-limited.
|
32
|
+
- Perfect for attaching to transactions or off-chain messages for tracing.
|
15
33
|
|
16
|
-
|
17
|
-
|
34
|
+
3. Canonical Message
|
35
|
+
- A deterministic JSON serialization of (pubkey, code, timestamp, optional secret)
|
36
|
+
- Always signed by the user's wallet.
|
37
|
+
- Prevents replay / tampering.
|
18
38
|
|
19
|
-
|
20
|
-
Each transaction carries an encoded `meta` string for verifiable context across chains.
|
39
|
+
#### Vision
|
21
40
|
|
22
|
-
|
23
|
-
Works on Solana today; built for future EVM, Cosmos, and more.
|
41
|
+
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.
|
24
42
|
|
25
|
-
- 🌐 **Prefix Namespace System**
|
26
|
-
Enables ecosystem-wide namespacing (e.g. `JUP`, `ME`) for branded intents and UIs.
|
27
|
-
|
28
|
-
---
|
29
|
-
|
30
|
-
## 📦 Repository Structure
|
31
|
-
|
32
|
-
```
|
33
|
-
/src - SDK modules (codegen, meta, validator, blockchain adapters)
|
34
|
-
/specs - Formal specifications (AIPs)
|
35
|
-
README.md - You are here
|
36
|
-
LICENSE - Apache 2.0
|
37
|
-
```
|
38
|
-
|
39
|
-
---
|
40
|
-
|
41
|
-
## 📄 Specifications
|
42
|
-
|
43
|
-
[Protocol Specifications](./specs/README.md)
|
44
|
-
|
45
|
-
- [`AIP-0`](./specs/aip-0.md): Action Codes Protocol Architecture
|
46
|
-
- [`AIP-1`](./specs/aip-1.md): Protocol Meta Format
|
47
|
-
- [`AIP-2`](./specs/aip-2.md): Authority Signature Validation
|
48
|
-
- [`AIP-3`](./specs/aip-3.md): Intent Resolution & Routing
|
49
|
-
- [`AIP-4`](./specs/aip-4.md): Prefix System
|
50
|
-
|
51
|
-
---
|
52
|
-
|
53
|
-
## 📜 License
|
54
|
-
|
55
|
-
This protocol is open source under the [Apache 2.0 License](./LICENSE).
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { ActionCode, CodeGenerationConfig, DelegationCertificate, DelegatedActionCode } from "./types";
|
2
|
+
import type { ChainAdapter, ChainWalletStrategyContext } from "./adapters/BaseChainAdapter";
|
3
|
+
import { WalletStrategy } from "./strategy/WalletStrategy";
|
4
|
+
import { DelegationStrategy } from "./strategy/DelegationStrategy";
|
5
|
+
import { SolanaAdapter } from "./adapters/SolanaAdapter";
|
6
|
+
export declare class ActionCodesProtocol {
|
7
|
+
private readonly config;
|
8
|
+
private adapters;
|
9
|
+
private _walletStrategy;
|
10
|
+
private _delegationStrategy;
|
11
|
+
constructor(config: CodeGenerationConfig);
|
12
|
+
getConfig(): CodeGenerationConfig;
|
13
|
+
/** Register a chain adapter */
|
14
|
+
registerAdapter(chain: string, adapter: ChainAdapter): void;
|
15
|
+
/** Get a registered adapter */
|
16
|
+
getAdapter(chain: string): ChainAdapter | undefined;
|
17
|
+
/** Typed access to specific adapters */
|
18
|
+
get adapter(): {
|
19
|
+
solana: SolanaAdapter;
|
20
|
+
};
|
21
|
+
/** Access to strategies */
|
22
|
+
get walletStrategy(): WalletStrategy;
|
23
|
+
get delegationStrategy(): DelegationStrategy;
|
24
|
+
createDelegationCertificateTemplate(userPublicKey: string, durationMs?: number, chain?: string): Omit<DelegationCertificate, "signature">;
|
25
|
+
generateCode(strategy: "wallet", pubkey: string, providedSecret?: string): {
|
26
|
+
actionCode: ActionCode;
|
27
|
+
canonicalMessage: Uint8Array;
|
28
|
+
};
|
29
|
+
generateCode(strategy: "delegation", certificate: DelegationCertificate): {
|
30
|
+
actionCode: DelegatedActionCode;
|
31
|
+
};
|
32
|
+
validateCode(strategy: "wallet", actionCode: ActionCode, context?: Omit<ChainWalletStrategyContext<unknown>, "canonicalMessageParts">): void;
|
33
|
+
validateCode(strategy: "delegation", actionCode: DelegatedActionCode, certificate: DelegationCertificate): void;
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=ActionCodesProtocol.d.ts.map
|
@@ -0,0 +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,aAAa,EAAsB,MAAM,0BAA0B,CAAC;AAG7E,qBAAa,mBAAmB;IAKlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,mBAAmB,CAAqB;gBAEnB,MAAM,EAAE,oBAAoB;IASlD,SAAS,IAAI,oBAAoB;IAIxC,+BAA+B;IAC/B,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAI3D,+BAA+B;IAC/B,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAInD,wCAAwC;IACxC,IAAI,OAAO;gBAEoC,aAAa;MAE3D;IAED,2BAA2B;IAC3B,IAAI,cAAc,mBAEjB;IAED,IAAI,kBAAkB,uBAErB;IAGD,mCAAmC,CACjC,aAAa,EAAE,MAAM,EACrB,UAAU,GAAE,MAAgB,EAC5B,KAAK,GAAE,MAAiB,GACvB,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC;IAS3C,YAAY,CACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,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;IAsBD,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;CAiDR"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { CanonicalMessageParts, DelegationCertificate } from "../types";
|
2
|
+
export interface BaseWalletStrategyContext {
|
3
|
+
chain: string;
|
4
|
+
canonicalMessageParts: CanonicalMessageParts;
|
5
|
+
}
|
6
|
+
export interface BaseDelegationContext {
|
7
|
+
chain: string;
|
8
|
+
pubkey: string;
|
9
|
+
signature: string;
|
10
|
+
certificate: DelegationCertificate;
|
11
|
+
}
|
12
|
+
export type ChainWalletStrategyContext<T> = BaseWalletStrategyContext & T;
|
13
|
+
export type ChainDelegationStrategyContext<T> = BaseDelegationContext & T;
|
14
|
+
export interface ChainAdapter<TCtx = unknown, DCtx = unknown> {
|
15
|
+
verifyWithWallet(context: ChainWalletStrategyContext<TCtx>): boolean;
|
16
|
+
verifyWithDelegation(context: ChainDelegationStrategyContext<DCtx>): boolean;
|
17
|
+
}
|
18
|
+
export declare abstract class BaseChainAdapter<TCtx, DCtx> implements ChainAdapter<TCtx, DCtx> {
|
19
|
+
abstract verifyWithWallet(context: ChainWalletStrategyContext<TCtx>): boolean;
|
20
|
+
abstract verifyWithDelegation(context: ChainDelegationStrategyContext<DCtx>): boolean;
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=BaseChainAdapter.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"BaseChainAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/BaseChainAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAG7E,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IAEd,qBAAqB,EAAE,qBAAqB,CAAC;CAC9C;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,qBAAqB,CAAC;CACpC;AAED,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI,yBAAyB,GAAG,CAAC,CAAC;AAC1E,MAAM,MAAM,8BAA8B,CAAC,CAAC,IAAI,qBAAqB,GAAG,CAAC,CAAC;AAC1E,MAAM,WAAW,YAAY,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO;IAC1D,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACrE,oBAAoB,CAAC,OAAO,EAAE,8BAA8B,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;CAC9E;AAED,8BAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAE,YAAW,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC;IACpF,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,CAAC,IAAI,CAAC,GAAG,OAAO;IAC7E,QAAQ,CAAC,oBAAoB,CAAC,OAAO,EAAE,8BAA8B,CAAC,IAAI,CAAC,GAAG,OAAO;CACtF"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { PublicKey, Transaction, VersionedTransaction, TransactionInstruction } from "@solana/web3.js";
|
2
|
+
import { BaseChainAdapter, type ChainWalletStrategyContext, type ChainDelegationStrategyContext } from "./BaseChainAdapter";
|
3
|
+
import { type ProtocolMetaFields } from "../utils/protocolMeta";
|
4
|
+
import type { ActionCode } from "../types";
|
5
|
+
export type SolanaContext = {
|
6
|
+
pubkey: string | PublicKey;
|
7
|
+
signature: string;
|
8
|
+
};
|
9
|
+
/** Union of supported Solana txn types */
|
10
|
+
export type SolanaTransaction = Transaction | VersionedTransaction;
|
11
|
+
export declare class SolanaAdapter extends BaseChainAdapter<SolanaContext, SolanaContext> {
|
12
|
+
/** Normalize pubkey input to PublicKey */
|
13
|
+
private normalizePubkey;
|
14
|
+
/** Verify the signature over canonical message (protocol-level) */
|
15
|
+
verifyWithWallet(context: ChainWalletStrategyContext<SolanaContext>): boolean;
|
16
|
+
/** Verify delegation certificate signature */
|
17
|
+
verifyWithDelegation(context: ChainDelegationStrategyContext<SolanaContext>): boolean;
|
18
|
+
/** Create a Solana memo instruction carrying protocol meta (for SDK/clients) */
|
19
|
+
static createProtocolMetaIx(meta: ProtocolMetaFields): TransactionInstruction;
|
20
|
+
/** Extract protocol metadata string (memo) from a transaction, or null */
|
21
|
+
getProtocolMeta(tx: SolanaTransaction): string | null;
|
22
|
+
/** Get parsed ProtocolMeta object, or null if none or invalid */
|
23
|
+
parseMeta(tx: SolanaTransaction): ProtocolMetaFields | null;
|
24
|
+
/** List memo instructions from the transaction (legacy & versioned) */
|
25
|
+
private getMemoInstructions;
|
26
|
+
/**
|
27
|
+
* Validate that a transaction's memo meta aligns with the bound `actionCode`.
|
28
|
+
* Throws ProtocolError if validation fails.
|
29
|
+
*/
|
30
|
+
verifyTransactionMatchesCode(actionCode: ActionCode, tx: SolanaTransaction): void;
|
31
|
+
/**
|
32
|
+
* Verify that the transaction is signed by the "intendedFor" pubkey
|
33
|
+
* as declared in the protocol meta of the transaction.
|
34
|
+
* Throws ProtocolError if validation fails.
|
35
|
+
*/
|
36
|
+
verifyTransactionSignedByIntentOwner(tx: SolanaTransaction): void;
|
37
|
+
/**
|
38
|
+
* Attach protocol meta into a legacy or versioned transaction.
|
39
|
+
*
|
40
|
+
* ⚠️ Note: this mutates the given transaction.
|
41
|
+
*/
|
42
|
+
static attachProtocolMeta<T extends SolanaTransaction>(tx: T, meta: ProtocolMetaFields): T;
|
43
|
+
}
|
44
|
+
//# sourceMappingURL=SolanaAdapter.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SolanaAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/SolanaAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,KAAK,0BAA0B,EAAE,KAAK,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAC5H,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAK3C,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,oBAAoB,CAAC;AAEnE,qBAAa,aAAc,SAAQ,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC;IAC/E,0CAA0C;IAC1C,OAAO,CAAC,eAAe;IAOvB,mEAAmE;IACnE,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,CAAC,aAAa,CAAC,GAAG,OAAO;IA0B7E,8CAA8C;IAC9C,oBAAoB,CAAC,OAAO,EAAE,8BAA8B,CAAC,aAAa,CAAC,GAAG,OAAO;IAiDrF,gFAAgF;IAChF,MAAM,CAAC,oBAAoB,CACzB,IAAI,EAAE,kBAAkB,GACvB,sBAAsB;IAKzB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI;IAerD,iEAAiE;IACjE,SAAS,CAAC,EAAE,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,IAAI;IAM3D,uEAAuE;IACvE,OAAO,CAAC,mBAAmB;IAmC3B;;;OAGG;IACH,4BAA4B,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,iBAAiB,GACpB,IAAI;IAiCP;;;;OAIG;IACH,oCAAoC,CAAC,EAAE,EAAE,iBAAiB,GAAG,IAAI;IAoEjE;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,CAAC,SAAS,iBAAiB,EACnD,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,kBAAkB,GACvB,CAAC;CA+CL"}
|
package/dist/constants.d.ts
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
export declare const
|
2
|
-
export declare const
|
3
|
-
export declare const
|
4
|
-
export declare const
|
5
|
-
export declare const
|
6
|
-
export declare const
|
7
|
-
export declare const MAX_PREFIX_LENGTH = 12;
|
1
|
+
export declare const PROTOCOL_NORMALIZATION = "NFC";
|
2
|
+
export declare const PROTOCOL_META_MAX_BYTES = 256;
|
3
|
+
export declare const CODE_MIN_LENGTH = 6;
|
4
|
+
export declare const CODE_MAX_LENGTH = 24;
|
5
|
+
export declare const CODE_DEFAULT_LENGTH = 8;
|
6
|
+
export declare const CODE_CHARSET_DIGITS = "0123456789";
|
8
7
|
export declare const SUPPORTED_CHAINS: readonly ["solana"];
|
9
|
-
export type SupportedChain = (typeof SUPPORTED_CHAINS)[number];
|
10
8
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAGrC,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB,qBAAsB,CAAC"}
|
package/dist/errors.d.ts
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
export declare enum ProtocolErrorCode {
|
2
|
+
EXPIRED_CODE = "EXPIRED_CODE",
|
3
|
+
INVALID_CODE_FORMAT = "INVALID_CODE_FORMAT",
|
4
|
+
INVALID_SIGNATURE = "INVALID_SIGNATURE",
|
5
|
+
MISSING_META = "MISSING_META",
|
6
|
+
INVALID_META_FORMAT = "INVALID_META_FORMAT",
|
7
|
+
META_MISMATCH = "META_MISMATCH",
|
8
|
+
META_TOO_LARGE = "META_TOO_LARGE",
|
9
|
+
TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER = "TRANSACTION_NOT_SIGNED_BY_INTENDED_OWNER",
|
10
|
+
INVALID_TRANSACTION_FORMAT = "INVALID_TRANSACTION_FORMAT",
|
11
|
+
INVALID_PUBKEY_FORMAT = "INVALID_PUBKEY_FORMAT",
|
12
|
+
INVALID_INPUT = "INVALID_INPUT",
|
13
|
+
MISSING_REQUIRED_FIELD = "MISSING_REQUIRED_FIELD",
|
14
|
+
CRYPTO_ERROR = "CRYPTO_ERROR",
|
15
|
+
INVALID_DIGEST = "INVALID_DIGEST",
|
16
|
+
INVALID_ADAPTER = "INVALID_ADAPTER"
|
17
|
+
}
|
18
|
+
export declare class ProtocolError extends Error {
|
19
|
+
readonly code: ProtocolErrorCode;
|
20
|
+
readonly details?: Record<string, unknown> | undefined;
|
21
|
+
constructor(code: ProtocolErrorCode, message: string, details?: Record<string, unknown> | undefined);
|
22
|
+
static expiredCode(code: string, expiresAt: number, currentTime: number): ExpiredCodeError;
|
23
|
+
static invalidCodeFormat(code: string, reason: string): InvalidCodeFormatError;
|
24
|
+
static invalidSignature(reason: string): InvalidSignatureError;
|
25
|
+
static missingMeta(): MissingMetaError;
|
26
|
+
static invalidMetaFormat(reason: string): ProtocolError;
|
27
|
+
static metaMismatch(expected: string, actual: string, field: string): MetaMismatchError;
|
28
|
+
static metaTooLarge(maxBytes: number, actualBytes: number): ProtocolError;
|
29
|
+
static transactionNotSignedByIntendedOwner(intended: string, actualSigners: string[]): TransactionNotSignedByIntendedOwnerError;
|
30
|
+
static invalidTransactionFormat(reason: string): ProtocolError;
|
31
|
+
static invalidPubkeyFormat(pubkey: string, reason: string): InvalidPubkeyFormatError;
|
32
|
+
static invalidInput(field: string, value: unknown, reason: string): ProtocolError;
|
33
|
+
static missingRequiredField(field: string): ProtocolError;
|
34
|
+
static cryptoError(operation: string, reason: string): ProtocolError;
|
35
|
+
static invalidDigest(reason: string): ProtocolError;
|
36
|
+
static invalidAdapter(adapter: string): InvalidAdapterError;
|
37
|
+
static create(code: ProtocolErrorCode, message: string, details?: Record<string, unknown>): ProtocolError;
|
38
|
+
}
|
39
|
+
export declare class ExpiredCodeError extends ProtocolError {
|
40
|
+
constructor(code: string, expiresAt: number, currentTime: number);
|
41
|
+
}
|
42
|
+
export declare class MissingMetaError extends ProtocolError {
|
43
|
+
constructor();
|
44
|
+
}
|
45
|
+
export declare class MetaMismatchError extends ProtocolError {
|
46
|
+
constructor(expected: string, actual: string, field: string);
|
47
|
+
}
|
48
|
+
export declare class TransactionNotSignedByIntendedOwnerError extends ProtocolError {
|
49
|
+
constructor(intended: string, actualSigners: string[]);
|
50
|
+
}
|
51
|
+
export declare class InvalidPubkeyFormatError extends ProtocolError {
|
52
|
+
constructor(pubkey: string, reason: string);
|
53
|
+
}
|
54
|
+
export declare class InvalidSignatureError extends ProtocolError {
|
55
|
+
constructor(reason: string);
|
56
|
+
}
|
57
|
+
export declare class InvalidCodeFormatError extends ProtocolError {
|
58
|
+
constructor(code: string, reason: string);
|
59
|
+
}
|
60
|
+
export declare class InvalidAdapterError extends ProtocolError {
|
61
|
+
constructor(adapter: string);
|
62
|
+
}
|
63
|
+
//# sourceMappingURL=errors.d.ts.map
|
@@ -0,0 +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;IAC3C,aAAa,kBAAkB;IAC/B,cAAc,mBAAmB;IAGjC,wCAAwC,6CAA6C;IACrF,0BAA0B,+BAA+B;IACzD,qBAAqB,0BAA0B;IAG/C,aAAa,kBAAkB;IAC/B,sBAAsB,2BAA2B;IAGjD,YAAY,iBAAiB;IAC7B,cAAc,mBAAmB;IAGjC,eAAe,oBAAoB;CACpC;AAED,qBAAa,aAAc,SAAQ,KAAK;aAEpB,IAAI,EAAE,iBAAiB;aAEvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,iBAAiB,EACvC,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAOnD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB;IAI1F,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,sBAAsB;IAI9E,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAK9D,MAAM,CAAC,WAAW,IAAI,gBAAgB;IAItC,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IAQvD,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB;IAIvF,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa;IASzE,MAAM,CAAC,mCAAmC,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,wCAAwC;IAI/H,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IAQ9D,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,wBAAwB;IAKpF,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa;IAQjF,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa;IASzD,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa;IAQpE,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IASnD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB;IAK3D,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;CAG1G;AAGD,qBAAa,gBAAiB,SAAQ,aAAa;gBACrC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAQjE;AAED,qBAAa,gBAAiB,SAAQ,aAAa;;CAQlD;AAED,qBAAa,iBAAkB,SAAQ,aAAa;gBACtC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAQ5D;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
ADDED
@@ -0,0 +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],f[O]),q8=I|0,D8=H(q,Z,28)^e(q,Z,34)^e(q,Z,39),Z8=_(q,Z,28)^t(q,Z,34)^t(q,Z,39),W8=q&X^q&Y^X&Y,R0=Z&J^Z&N^J&N;r=F|0,o=M|0,F=G|0,M=W|0,G=z|0,W=R|0,{h:z,l:R}=E(U|0,K|0,x|0,q8|0),U=Y|0,K=N|0,Y=X|0,N=J|0,X=q|0,J=Z|0;let y8=l8(q8,Z8,R0);q=c8(y8,x,D8,W8),Z=y8|0}({h:q,l:Z}=E(this.Ah|0,this.Al|0,q|0,Z|0)),{h:X,l:J}=E(this.Bh|0,this.Bl|0,X|0,J|0),{h:Y,l:N}=E(this.Ch|0,this.Cl|0,Y|0,N|0),{h:U,l:K}=E(this.Dh|0,this.Dl|0,U|0,K|0),{h:z,l:R}=E(this.Eh|0,this.El|0,z|0,R|0),{h:G,l:W}=E(this.Fh|0,this.Fl|0,G|0,W|0),{h:F,l:M}=E(this.Gh|0,this.Gl|0,F|0,M|0),{h:r,l:o}=E(this.Hh|0,this.Hl|0,r|0,o|0),this.set(q,Z,X,J,Y,N,U,K,z,R,G,W,F,M,r,o)}roundClean(){T(f,p)}destroy(){T(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class V0 extends Q8{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(64)}}class E0 extends Q8{Ah=P[0]|0;Al=P[1]|0;Bh=P[2]|0;Bl=P[3]|0;Ch=P[4]|0;Cl=P[5]|0;Dh=P[6]|0;Dl=P[7]|0;Eh=P[8]|0;El=P[9]|0;Fh=P[10]|0;Fl=P[11]|0;Gh=P[12]|0;Gl=P[13]|0;Hh=P[14]|0;Hl=P[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 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")}}}
|
2
|
+
|
3
|
+
//# debugId=378EC37CD0386CC964756E2164756E21
|