@prism-ing/wallet 0.1.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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +596 -0
- package/SPEC.md +192 -0
- package/dist/backends/squads-recovery-backend.d.ts +59 -0
- package/dist/backends/squads-recovery-backend.d.ts.map +1 -0
- package/dist/backends/squads-recovery-backend.js +81 -0
- package/dist/backends/squads-recovery-backend.js.map +1 -0
- package/dist/backends/squads-types.d.ts +74 -0
- package/dist/backends/squads-types.d.ts.map +1 -0
- package/dist/backends/squads-types.js +22 -0
- package/dist/backends/squads-types.js.map +1 -0
- package/dist/backends/zerodev-policy-mapper.d.ts +41 -0
- package/dist/backends/zerodev-policy-mapper.d.ts.map +1 -0
- package/dist/backends/zerodev-policy-mapper.js +127 -0
- package/dist/backends/zerodev-policy-mapper.js.map +1 -0
- package/dist/backends/zerodev-session-backend.d.ts +43 -0
- package/dist/backends/zerodev-session-backend.d.ts.map +1 -0
- package/dist/backends/zerodev-session-backend.js +63 -0
- package/dist/backends/zerodev-session-backend.js.map +1 -0
- package/dist/backends/zerodev-types.d.ts +104 -0
- package/dist/backends/zerodev-types.d.ts.map +1 -0
- package/dist/backends/zerodev-types.js +13 -0
- package/dist/backends/zerodev-types.js.map +1 -0
- package/dist/create-wallet.d.ts +89 -0
- package/dist/create-wallet.d.ts.map +1 -0
- package/dist/create-wallet.js +235 -0
- package/dist/create-wallet.js.map +1 -0
- package/dist/cross-chain.d.ts +64 -0
- package/dist/cross-chain.d.ts.map +1 -0
- package/dist/cross-chain.js +200 -0
- package/dist/cross-chain.js.map +1 -0
- package/dist/errors.d.ts +115 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +97 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/base58.d.ts +8 -0
- package/dist/internal/base58.d.ts.map +1 -0
- package/dist/internal/base58.js +34 -0
- package/dist/internal/base58.js.map +1 -0
- package/dist/internal/eip712.d.ts +41 -0
- package/dist/internal/eip712.d.ts.map +1 -0
- package/dist/internal/eip712.js +182 -0
- package/dist/internal/eip712.js.map +1 -0
- package/dist/internal/file-spend-persistence.d.ts +9 -0
- package/dist/internal/file-spend-persistence.d.ts.map +1 -0
- package/dist/internal/file-spend-persistence.js +58 -0
- package/dist/internal/file-spend-persistence.js.map +1 -0
- package/dist/internal/onebalance-client.d.ts +59 -0
- package/dist/internal/onebalance-client.d.ts.map +1 -0
- package/dist/internal/onebalance-client.js +2 -0
- package/dist/internal/onebalance-client.js.map +1 -0
- package/dist/internal/onebalance-http-client.d.ts +25 -0
- package/dist/internal/onebalance-http-client.d.ts.map +1 -0
- package/dist/internal/onebalance-http-client.js +161 -0
- package/dist/internal/onebalance-http-client.js.map +1 -0
- package/dist/internal/onebalance-types.d.ts +201 -0
- package/dist/internal/onebalance-types.d.ts.map +1 -0
- package/dist/internal/onebalance-types.js +39 -0
- package/dist/internal/onebalance-types.js.map +1 -0
- package/dist/internal/platform.d.ts +14 -0
- package/dist/internal/platform.d.ts.map +1 -0
- package/dist/internal/platform.js +22 -0
- package/dist/internal/platform.js.map +1 -0
- package/dist/internal/quote-verifier.d.ts +71 -0
- package/dist/internal/quote-verifier.d.ts.map +1 -0
- package/dist/internal/quote-verifier.js +172 -0
- package/dist/internal/quote-verifier.js.map +1 -0
- package/dist/internal/recovery-manager.d.ts +29 -0
- package/dist/internal/recovery-manager.d.ts.map +1 -0
- package/dist/internal/recovery-manager.js +161 -0
- package/dist/internal/recovery-manager.js.map +1 -0
- package/dist/result.d.ts +132 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +114 -0
- package/dist/result.js.map +1 -0
- package/dist/schemas.d.ts +184 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +76 -0
- package/dist/schemas.js.map +1 -0
- package/dist/session-keys.d.ts +53 -0
- package/dist/session-keys.d.ts.map +1 -0
- package/dist/session-keys.js +345 -0
- package/dist/session-keys.js.map +1 -0
- package/dist/signers/node-signing-backend.d.ts +11 -0
- package/dist/signers/node-signing-backend.d.ts.map +1 -0
- package/dist/signers/node-signing-backend.js +120 -0
- package/dist/signers/node-signing-backend.js.map +1 -0
- package/dist/signers/ows-adapter.d.ts +70 -0
- package/dist/signers/ows-adapter.d.ts.map +1 -0
- package/dist/signers/ows-adapter.js +53 -0
- package/dist/signers/ows-adapter.js.map +1 -0
- package/dist/signers/ows-signing-backend.d.ts +25 -0
- package/dist/signers/ows-signing-backend.d.ts.map +1 -0
- package/dist/signers/ows-signing-backend.js +192 -0
- package/dist/signers/ows-signing-backend.js.map +1 -0
- package/dist/signers/secure-enclave-backend.d.ts +19 -0
- package/dist/signers/secure-enclave-backend.d.ts.map +1 -0
- package/dist/signers/secure-enclave-backend.js +201 -0
- package/dist/signers/secure-enclave-backend.js.map +1 -0
- package/dist/signers/secure-enclave-types.d.ts +98 -0
- package/dist/signers/secure-enclave-types.d.ts.map +1 -0
- package/dist/signers/secure-enclave-types.js +12 -0
- package/dist/signers/secure-enclave-types.js.map +1 -0
- package/dist/types.d.ts +371 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OneBalance API types matching the v3 REST API.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These types mirror the OneBalance OpenAPI spec (v1.6.2).
|
|
6
|
+
* All amounts are strings in smallest unit (wei, lamports).
|
|
7
|
+
* Chain identifiers use CAIP-2 format (e.g. "eip155:8453").
|
|
8
|
+
* Asset identifiers use either aggregated ("ob:usdc") or CAIP-19 format.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
/** Discriminated union of OneBalance account configurations. */
|
|
13
|
+
export type MultiAccount = RoleBasedAccount | KernelV31Account | SolanaAccount;
|
|
14
|
+
export interface RoleBasedAccount {
|
|
15
|
+
readonly type: 'role-based';
|
|
16
|
+
readonly sessionAddress: string;
|
|
17
|
+
readonly adminAddress: string;
|
|
18
|
+
readonly accountAddress: string;
|
|
19
|
+
}
|
|
20
|
+
export interface KernelV31Account {
|
|
21
|
+
readonly type: 'kernel-v3.1-ecdsa';
|
|
22
|
+
readonly signerAddress: string;
|
|
23
|
+
readonly accountAddress: string;
|
|
24
|
+
readonly deploymentType?: 'ERC4337';
|
|
25
|
+
}
|
|
26
|
+
export interface SolanaAccount {
|
|
27
|
+
readonly type: 'solana';
|
|
28
|
+
readonly accountAddress: string;
|
|
29
|
+
}
|
|
30
|
+
export type PredictAddressRequest = {
|
|
31
|
+
readonly type: 'kernel-v3.1-ecdsa';
|
|
32
|
+
readonly signerAddress: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly sessionAddress: string;
|
|
35
|
+
readonly adminAddress: string;
|
|
36
|
+
};
|
|
37
|
+
export interface PredictAddressResponse {
|
|
38
|
+
readonly predictedAddress: string;
|
|
39
|
+
}
|
|
40
|
+
/** Asset identifier — aggregated ("ob:usdc") or specific (CAIP-19). */
|
|
41
|
+
export interface AssetReference {
|
|
42
|
+
readonly assetId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface QuoteRequest {
|
|
45
|
+
readonly from: {
|
|
46
|
+
readonly accounts: readonly MultiAccount[];
|
|
47
|
+
readonly asset: AssetReference;
|
|
48
|
+
readonly amount: string;
|
|
49
|
+
};
|
|
50
|
+
readonly to: {
|
|
51
|
+
readonly asset: AssetReference;
|
|
52
|
+
readonly account?: string;
|
|
53
|
+
};
|
|
54
|
+
readonly slippageTolerance?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface QuoteResponse {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly accounts: readonly MultiAccount[];
|
|
59
|
+
readonly originChainsOperations: readonly ChainOperation[];
|
|
60
|
+
readonly originToken: OriginToken;
|
|
61
|
+
readonly destinationToken: DestinationToken;
|
|
62
|
+
readonly expirationTimestamp: string;
|
|
63
|
+
readonly tamperProofSignature: string;
|
|
64
|
+
readonly slippage?: QuoteSlippage;
|
|
65
|
+
readonly fees?: QuoteFees;
|
|
66
|
+
}
|
|
67
|
+
export interface OriginToken {
|
|
68
|
+
readonly aggregatedAssetId: string;
|
|
69
|
+
readonly amount: string;
|
|
70
|
+
readonly assetType: readonly string[];
|
|
71
|
+
readonly fiatValue: readonly AssetFiatValue[];
|
|
72
|
+
}
|
|
73
|
+
export interface AssetFiatValue {
|
|
74
|
+
readonly assetType: string;
|
|
75
|
+
readonly fiatValue: string;
|
|
76
|
+
}
|
|
77
|
+
export interface DestinationToken {
|
|
78
|
+
readonly aggregatedAssetId: string;
|
|
79
|
+
readonly amount: string;
|
|
80
|
+
readonly assetType: string;
|
|
81
|
+
readonly fiatValue: string;
|
|
82
|
+
readonly minimumAmount?: string;
|
|
83
|
+
readonly minimumFiatValue?: string;
|
|
84
|
+
readonly symbol?: string;
|
|
85
|
+
readonly name?: string;
|
|
86
|
+
readonly decimals?: number;
|
|
87
|
+
readonly recipientAccount?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface QuoteSlippage {
|
|
90
|
+
readonly origin: {
|
|
91
|
+
readonly percent: string;
|
|
92
|
+
readonly usd: string;
|
|
93
|
+
readonly value: string;
|
|
94
|
+
};
|
|
95
|
+
readonly destination: {
|
|
96
|
+
readonly percent: string;
|
|
97
|
+
readonly usd: string;
|
|
98
|
+
readonly value: string;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export interface QuoteFees {
|
|
102
|
+
readonly assets: Readonly<Record<string, string>>;
|
|
103
|
+
readonly cumulativeUSD: string;
|
|
104
|
+
}
|
|
105
|
+
/** Discriminated union: EVM operation or Solana operation. */
|
|
106
|
+
export type ChainOperation = EvmChainOperation | SolanaChainOperation;
|
|
107
|
+
export interface EvmChainOperation {
|
|
108
|
+
readonly userOp: SerializedUserOperation;
|
|
109
|
+
readonly typedDataToSign: TypedDataToSign;
|
|
110
|
+
readonly assetType: string;
|
|
111
|
+
readonly amount: string;
|
|
112
|
+
}
|
|
113
|
+
export interface SolanaChainOperation {
|
|
114
|
+
readonly type: 'solana';
|
|
115
|
+
readonly instructions: readonly SolanaInstruction[];
|
|
116
|
+
readonly recentBlockHash: string;
|
|
117
|
+
readonly feePayer: string;
|
|
118
|
+
readonly assetType: string;
|
|
119
|
+
readonly amount: string;
|
|
120
|
+
readonly dataToSign: string;
|
|
121
|
+
signature?: string;
|
|
122
|
+
readonly addressLookupTableAddresses?: readonly string[];
|
|
123
|
+
}
|
|
124
|
+
/** ERC-4337 UserOperation (all fields serialized as strings). */
|
|
125
|
+
export interface SerializedUserOperation {
|
|
126
|
+
readonly sender: string;
|
|
127
|
+
readonly nonce: string;
|
|
128
|
+
readonly factory?: string;
|
|
129
|
+
readonly factoryData?: string;
|
|
130
|
+
readonly callData: string;
|
|
131
|
+
readonly callGasLimit: string;
|
|
132
|
+
readonly verificationGasLimit: string;
|
|
133
|
+
readonly preVerificationGas: string;
|
|
134
|
+
readonly maxFeePerGas: string;
|
|
135
|
+
readonly maxPriorityFeePerGas: string;
|
|
136
|
+
readonly paymaster: string;
|
|
137
|
+
readonly paymasterVerificationGasLimit: string;
|
|
138
|
+
readonly paymasterPostOpGasLimit: string;
|
|
139
|
+
readonly paymasterData: string;
|
|
140
|
+
signature: string;
|
|
141
|
+
}
|
|
142
|
+
/** EIP-712 typed data from the quote for signing. */
|
|
143
|
+
export interface TypedDataToSign {
|
|
144
|
+
readonly domain: {
|
|
145
|
+
readonly name: string;
|
|
146
|
+
readonly version: string;
|
|
147
|
+
readonly chainId: number;
|
|
148
|
+
readonly verifyingContract: string;
|
|
149
|
+
};
|
|
150
|
+
readonly types: Readonly<Record<string, readonly TypeField[]>>;
|
|
151
|
+
readonly primaryType: string;
|
|
152
|
+
readonly message: Readonly<Record<string, unknown>>;
|
|
153
|
+
}
|
|
154
|
+
export interface TypeField {
|
|
155
|
+
readonly name: string;
|
|
156
|
+
readonly type: string;
|
|
157
|
+
}
|
|
158
|
+
export interface SolanaInstruction {
|
|
159
|
+
readonly programId: string;
|
|
160
|
+
readonly data: string;
|
|
161
|
+
readonly keys: readonly SolanaAccountMeta[];
|
|
162
|
+
}
|
|
163
|
+
export interface SolanaAccountMeta {
|
|
164
|
+
readonly pubkey: string;
|
|
165
|
+
readonly isSigner: boolean;
|
|
166
|
+
readonly isWritable: boolean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The execute-quote request is the full QuoteResponse with signatures populated
|
|
170
|
+
* in originChainsOperations[].userOp.signature (EVM) or
|
|
171
|
+
* originChainsOperations[].signature (Solana).
|
|
172
|
+
*/
|
|
173
|
+
export type ExecuteQuoteRequest = QuoteResponse;
|
|
174
|
+
export type ExecutionStatus = 'PENDING' | 'IN_PROGRESS' | 'EXECUTED' | 'COMPLETED' | 'REFUNDED' | 'FAILED';
|
|
175
|
+
export interface ExecutionStatusResponse {
|
|
176
|
+
readonly quoteId: string;
|
|
177
|
+
readonly status: ExecutionStatus;
|
|
178
|
+
readonly user: string;
|
|
179
|
+
readonly recipientAccountId: string;
|
|
180
|
+
readonly failReason?: {
|
|
181
|
+
readonly name: string;
|
|
182
|
+
readonly message: string;
|
|
183
|
+
};
|
|
184
|
+
readonly originChainOperations: readonly OperationDetails[];
|
|
185
|
+
readonly destinationChainOperations?: readonly OperationDetails[];
|
|
186
|
+
}
|
|
187
|
+
export interface OperationDetails {
|
|
188
|
+
readonly hash: string;
|
|
189
|
+
readonly chain: string;
|
|
190
|
+
readonly explorerUrl: string;
|
|
191
|
+
}
|
|
192
|
+
/** Map numeric chain IDs to CAIP-2 identifiers. */
|
|
193
|
+
export declare const CHAIN_ID_TO_CAIP2: Readonly<Record<number, string>>;
|
|
194
|
+
/** The CAIP-2 identifier for Solana mainnet. */
|
|
195
|
+
export declare const SOLANA_CAIP2: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
196
|
+
/**
|
|
197
|
+
* Convert a numeric EVM chain ID to CAIP-2 format.
|
|
198
|
+
* Returns undefined for unknown chains.
|
|
199
|
+
*/
|
|
200
|
+
export declare function toCaip2(chainId: number): string | undefined;
|
|
201
|
+
//# sourceMappingURL=onebalance-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onebalance-types.d.ts","sourceRoot":"","sources":["../../src/internal/onebalance-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,gEAAgE;AAChE,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,gBAAgB,GAChB,aAAa,CAAC;AAElB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAMD,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE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C;AAMhD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,aAAa,GACb,UAAU,GACV,WAAW,GACX,UAAU,GACV,QAAQ,CAAC;AAEb,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1E,QAAQ,CAAC,qBAAqB,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC5D,QAAQ,CAAC,0BAA0B,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACnE;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAMD,mDAAmD;AACnD,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAarD,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,YAAY,EAAG,yCAAkD,CAAC;AAE/E;;;GAGG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OneBalance API types matching the v3 REST API.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These types mirror the OneBalance OpenAPI spec (v1.6.2).
|
|
6
|
+
* All amounts are strings in smallest unit (wei, lamports).
|
|
7
|
+
* Chain identifiers use CAIP-2 format (e.g. "eip155:8453").
|
|
8
|
+
* Asset identifiers use either aggregated ("ob:usdc") or CAIP-19 format.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// CAIP-2 Chain ID Mapping
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
/** Map numeric chain IDs to CAIP-2 identifiers. */
|
|
16
|
+
export const CHAIN_ID_TO_CAIP2 = {
|
|
17
|
+
1: 'eip155:1',
|
|
18
|
+
10: 'eip155:10',
|
|
19
|
+
56: 'eip155:56',
|
|
20
|
+
137: 'eip155:137',
|
|
21
|
+
8453: 'eip155:8453',
|
|
22
|
+
42161: 'eip155:42161',
|
|
23
|
+
43114: 'eip155:43114',
|
|
24
|
+
59144: 'eip155:59144',
|
|
25
|
+
81457: 'eip155:81457',
|
|
26
|
+
80094: 'eip155:80094',
|
|
27
|
+
130: 'eip155:130',
|
|
28
|
+
999: 'eip155:999',
|
|
29
|
+
};
|
|
30
|
+
/** The CAIP-2 identifier for Solana mainnet. */
|
|
31
|
+
export const SOLANA_CAIP2 = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
|
|
32
|
+
/**
|
|
33
|
+
* Convert a numeric EVM chain ID to CAIP-2 format.
|
|
34
|
+
* Returns undefined for unknown chains.
|
|
35
|
+
*/
|
|
36
|
+
export function toCaip2(chainId) {
|
|
37
|
+
return CHAIN_ID_TO_CAIP2[chainId];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=onebalance-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onebalance-types.js","sourceRoot":"","sources":["../../src/internal/onebalance-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAkOH,8EAA8E;AAC9E,0BAA0B;AAC1B,8EAA8E;AAE9E,mDAAmD;AACnD,MAAM,CAAC,MAAM,iBAAiB,GAAqC;IACjE,CAAC,EAAE,UAAU;IACb,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,GAAG,EAAE,YAAY;IACjB,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,GAAG,EAAE,YAAY;IACjB,GAAG,EAAE,YAAY;CACT,CAAC;AAEX,gDAAgD;AAChD,MAAM,CAAC,MAAM,YAAY,GAAG,yCAAkD,CAAC;AAE/E;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe;IACrC,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform detection for OWS signer selection.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
import type { Platform } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Detect the current runtime platform.
|
|
8
|
+
*
|
|
9
|
+
* @returns The detected platform: 'ios', 'node', or 'browser'.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectPlatform(): Platform;
|
|
14
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/internal/platform.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAmBzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect the current runtime platform.
|
|
3
|
+
*
|
|
4
|
+
* @returns The detected platform: 'ios', 'node', or 'browser'.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function detectPlatform() {
|
|
9
|
+
// React Native on iOS
|
|
10
|
+
if (typeof globalThis !== 'undefined' &&
|
|
11
|
+
'ReactNativeWebView' in globalThis) {
|
|
12
|
+
return 'ios';
|
|
13
|
+
}
|
|
14
|
+
// Node.js
|
|
15
|
+
if (typeof process !== 'undefined' &&
|
|
16
|
+
process.versions?.node !== undefined) {
|
|
17
|
+
return 'node';
|
|
18
|
+
}
|
|
19
|
+
// Browser fallback
|
|
20
|
+
return 'browser';
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/internal/platform.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc;IAC5B,sBAAsB;IACtB,IACE,OAAO,UAAU,KAAK,WAAW;QACjC,oBAAoB,IAAI,UAAU,EAClC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU;IACV,IACE,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,QAAQ,EAAE,IAAI,KAAK,SAAS,EACpC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,mBAAmB;IACnB,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side OneBalance quote integrity verification.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Verifies that a quote from OneBalance matches the original request
|
|
6
|
+
* before signing. Prevents blind-signing attacks where a compromised
|
|
7
|
+
* or man-in-the-middle API could present malicious EIP-712 payloads.
|
|
8
|
+
*
|
|
9
|
+
* Checks performed:
|
|
10
|
+
* 1. Quote has not expired
|
|
11
|
+
* 2. Origin asset matches the requested asset
|
|
12
|
+
* 3. Origin amount matches the requested amount (within tolerance)
|
|
13
|
+
* 4. EVM operation senders match the wallet's smart account address
|
|
14
|
+
* 5. Destination asset matches the requested asset
|
|
15
|
+
* 6. Tamper-proof signature is present
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { verifyQuoteIntegrity } from '@prism-ing/wallet';
|
|
20
|
+
*
|
|
21
|
+
* const violation = verifyQuoteIntegrity(quote, {
|
|
22
|
+
* fromAsset: 'ob:usdc',
|
|
23
|
+
* toAsset: 'ob:eth',
|
|
24
|
+
* amount: '1000000',
|
|
25
|
+
* accountAddress: wallet.evmAddress,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* if (violation !== undefined) {
|
|
29
|
+
* console.error('Quote verification failed:', violation.reason);
|
|
30
|
+
* return;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
import type { WalletError } from '../errors.js';
|
|
37
|
+
import type { QuoteResponse, EvmChainOperation } from './onebalance-types.js';
|
|
38
|
+
/** Parameters for verifying a quote against the original request. */
|
|
39
|
+
export interface QuoteVerificationParams {
|
|
40
|
+
/** The requested source asset (aggregated or CAIP-19). */
|
|
41
|
+
readonly fromAsset: string;
|
|
42
|
+
/** The requested destination asset. */
|
|
43
|
+
readonly toAsset: string;
|
|
44
|
+
/** The requested amount in smallest unit. */
|
|
45
|
+
readonly amount: string;
|
|
46
|
+
/** The wallet's smart account address (to verify EVM operation senders). */
|
|
47
|
+
readonly accountAddress?: string;
|
|
48
|
+
/** Maximum acceptable slippage on the origin amount as a fraction (0.01 = 1%). Defaults to 0.01. */
|
|
49
|
+
readonly maxOriginSlippageFraction?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verify that a OneBalance quote matches the original request.
|
|
53
|
+
*
|
|
54
|
+
* @param quote - The quote response from OneBalance.
|
|
55
|
+
* @param params - The original request parameters to verify against.
|
|
56
|
+
* @returns A QuoteVerificationFailedError if verification fails, undefined if valid.
|
|
57
|
+
*/
|
|
58
|
+
export declare function verifyQuoteIntegrity(quote: QuoteResponse, params: QuoteVerificationParams): WalletError | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Verify a single EVM operation's typed data integrity.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Checks that the EIP-712 domain and message fields are internally consistent
|
|
64
|
+
* with the operation metadata (chain, amount, sender).
|
|
65
|
+
*
|
|
66
|
+
* @param operation - The EVM chain operation to verify.
|
|
67
|
+
* @param accountAddress - The expected smart account address.
|
|
68
|
+
* @returns A QuoteVerificationFailedError if verification fails, undefined if valid.
|
|
69
|
+
*/
|
|
70
|
+
export declare function verifyEvmOperation(operation: EvmChainOperation, accountAddress: string): WalletError | undefined;
|
|
71
|
+
//# sourceMappingURL=quote-verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote-verifier.d.ts","sourceRoot":"","sources":["../../src/internal/quote-verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAM/B,qEAAqE;AACrE,MAAM,WAAW,uBAAuB;IACtC,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,oGAAoG;IACpG,QAAQ,CAAC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CAC7C;AAmBD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,uBAAuB,GAC9B,WAAW,GAAG,SAAS,CAgCzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,EAC5B,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAuCzB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { walletErrors } from '../errors.js';
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Type Guards
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
function isEvmOperation(op) {
|
|
6
|
+
return (typeof op === 'object' &&
|
|
7
|
+
op !== null &&
|
|
8
|
+
'userOp' in op &&
|
|
9
|
+
'typedDataToSign' in op);
|
|
10
|
+
}
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Quote Verification
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/**
|
|
15
|
+
* Verify that a OneBalance quote matches the original request.
|
|
16
|
+
*
|
|
17
|
+
* @param quote - The quote response from OneBalance.
|
|
18
|
+
* @param params - The original request parameters to verify against.
|
|
19
|
+
* @returns A QuoteVerificationFailedError if verification fails, undefined if valid.
|
|
20
|
+
*/
|
|
21
|
+
export function verifyQuoteIntegrity(quote, params) {
|
|
22
|
+
// 1. Check expiration
|
|
23
|
+
const expirationCheck = checkExpiration(quote);
|
|
24
|
+
if (expirationCheck !== undefined)
|
|
25
|
+
return expirationCheck;
|
|
26
|
+
// 2. Check tamper-proof signature exists
|
|
27
|
+
const tamperCheck = checkTamperProofSignature(quote);
|
|
28
|
+
if (tamperCheck !== undefined)
|
|
29
|
+
return tamperCheck;
|
|
30
|
+
// 3. Check origin asset matches
|
|
31
|
+
const originAssetCheck = checkOriginAsset(quote, params.fromAsset);
|
|
32
|
+
if (originAssetCheck !== undefined)
|
|
33
|
+
return originAssetCheck;
|
|
34
|
+
// 4. Check origin amount (within slippage tolerance)
|
|
35
|
+
const amountCheck = checkOriginAmount(quote, params.amount, params.maxOriginSlippageFraction ?? 0.01);
|
|
36
|
+
if (amountCheck !== undefined)
|
|
37
|
+
return amountCheck;
|
|
38
|
+
// 5. Check destination asset matches
|
|
39
|
+
const destAssetCheck = checkDestinationAsset(quote, params.toAsset);
|
|
40
|
+
if (destAssetCheck !== undefined)
|
|
41
|
+
return destAssetCheck;
|
|
42
|
+
// 6. Verify EVM operation senders match the account address
|
|
43
|
+
if (params.accountAddress !== undefined) {
|
|
44
|
+
const senderCheck = checkEvmOperationSenders(quote, params.accountAddress);
|
|
45
|
+
if (senderCheck !== undefined)
|
|
46
|
+
return senderCheck;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Verify a single EVM operation's typed data integrity.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Checks that the EIP-712 domain and message fields are internally consistent
|
|
55
|
+
* with the operation metadata (chain, amount, sender).
|
|
56
|
+
*
|
|
57
|
+
* @param operation - The EVM chain operation to verify.
|
|
58
|
+
* @param accountAddress - The expected smart account address.
|
|
59
|
+
* @returns A QuoteVerificationFailedError if verification fails, undefined if valid.
|
|
60
|
+
*/
|
|
61
|
+
export function verifyEvmOperation(operation, accountAddress) {
|
|
62
|
+
// Verify the userOp sender matches the account address
|
|
63
|
+
const senderLower = operation.userOp.sender.toLowerCase();
|
|
64
|
+
const accountLower = accountAddress.toLowerCase();
|
|
65
|
+
if (senderLower !== accountLower) {
|
|
66
|
+
return walletErrors.quoteVerificationFailed(`EVM operation sender "${operation.userOp.sender}" does not match account address "${accountAddress}"`);
|
|
67
|
+
}
|
|
68
|
+
// Verify typed data domain has a valid chain ID
|
|
69
|
+
const { domain } = operation.typedDataToSign;
|
|
70
|
+
if (typeof domain.chainId !== 'number' || domain.chainId <= 0) {
|
|
71
|
+
return walletErrors.quoteVerificationFailed(`EVM operation has invalid chain ID: ${String(domain.chainId)}`);
|
|
72
|
+
}
|
|
73
|
+
// Verify verifying contract is present
|
|
74
|
+
if (typeof domain.verifyingContract !== 'string' ||
|
|
75
|
+
!domain.verifyingContract.startsWith('0x')) {
|
|
76
|
+
return walletErrors.quoteVerificationFailed(`EVM operation has invalid verifying contract: ${String(domain.verifyingContract)}`);
|
|
77
|
+
}
|
|
78
|
+
// Verify the typed data message sender matches the userOp sender
|
|
79
|
+
const msgSender = operation.typedDataToSign.message.sender;
|
|
80
|
+
if (typeof msgSender === 'string') {
|
|
81
|
+
if (msgSender.toLowerCase() !== senderLower) {
|
|
82
|
+
return walletErrors.quoteVerificationFailed(`EIP-712 message sender "${String(msgSender)}" does not match userOp sender "${operation.userOp.sender}"`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Individual Checks
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
function checkExpiration(quote) {
|
|
91
|
+
const expiration = parseInt(quote.expirationTimestamp, 10);
|
|
92
|
+
if (Number.isNaN(expiration)) {
|
|
93
|
+
return walletErrors.quoteVerificationFailed(`Invalid expiration timestamp: "${quote.expirationTimestamp}"`);
|
|
94
|
+
}
|
|
95
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
96
|
+
if (nowSec >= expiration) {
|
|
97
|
+
return walletErrors.quoteVerificationFailed(`Quote expired at ${expiration}, current time is ${nowSec}`);
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
function checkTamperProofSignature(quote) {
|
|
102
|
+
if (typeof quote.tamperProofSignature !== 'string' ||
|
|
103
|
+
quote.tamperProofSignature.length === 0) {
|
|
104
|
+
return walletErrors.quoteVerificationFailed('Quote is missing tamper-proof signature');
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
function checkOriginAsset(quote, expectedAsset) {
|
|
109
|
+
const originId = quote.originToken.aggregatedAssetId;
|
|
110
|
+
// Direct match on aggregated ID
|
|
111
|
+
if (originId === expectedAsset)
|
|
112
|
+
return undefined;
|
|
113
|
+
// Check if any of the specific asset types match the expected asset.
|
|
114
|
+
// Use segment-based matching: the expected asset must appear as a complete
|
|
115
|
+
// segment (delimited by '/' or ':' or exact match), not as a substring.
|
|
116
|
+
const assetTypes = quote.originToken.assetType;
|
|
117
|
+
const matchesSpecific = assetTypes.some((at) => at === expectedAsset || isAssetSegmentMatch(at, expectedAsset));
|
|
118
|
+
if (matchesSpecific)
|
|
119
|
+
return undefined;
|
|
120
|
+
return walletErrors.quoteVerificationFailed(`Origin asset "${originId}" (types: [${assetTypes.join(', ')}]) does not match requested asset "${expectedAsset}"`);
|
|
121
|
+
}
|
|
122
|
+
function checkOriginAmount(quote, expectedAmount, maxSlippageFraction) {
|
|
123
|
+
const quoteAmount = BigInt(quote.originToken.amount);
|
|
124
|
+
const expected = BigInt(expectedAmount);
|
|
125
|
+
if (expected === 0n)
|
|
126
|
+
return undefined;
|
|
127
|
+
// Allow the quote to use up to (1 + slippage) times the requested amount
|
|
128
|
+
// This accounts for fees and rounding
|
|
129
|
+
const maxAllowed = expected + (expected * BigInt(Math.floor(maxSlippageFraction * 10000))) / 10000n;
|
|
130
|
+
if (quoteAmount > maxAllowed) {
|
|
131
|
+
return walletErrors.quoteVerificationFailed(`Origin amount ${String(quoteAmount)} exceeds requested amount ${expectedAmount} plus ${maxSlippageFraction * 100}% slippage tolerance (max: ${String(maxAllowed)})`);
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
function checkDestinationAsset(quote, expectedAsset) {
|
|
136
|
+
const destId = quote.destinationToken.aggregatedAssetId;
|
|
137
|
+
const destType = quote.destinationToken.assetType;
|
|
138
|
+
if (destId === expectedAsset)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (destType === expectedAsset)
|
|
141
|
+
return undefined;
|
|
142
|
+
if (isAssetSegmentMatch(destType, expectedAsset))
|
|
143
|
+
return undefined;
|
|
144
|
+
return walletErrors.quoteVerificationFailed(`Destination asset "${destId}" (type: "${destType}") does not match requested asset "${expectedAsset}"`);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if an asset type string contains the expected asset as a complete
|
|
148
|
+
* segment (delimited by '/' or ':'), not as an arbitrary substring.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* isAssetSegmentMatch('eip155:8453/erc20:0xabc', 'ob:usdc') → false
|
|
152
|
+
* isAssetSegmentMatch('ob:usdc/eip155:8453', 'ob:usdc') → true
|
|
153
|
+
* isAssetSegmentMatch('malicious-ob:usdc-drain', 'ob:usdc') → false
|
|
154
|
+
*/
|
|
155
|
+
function isAssetSegmentMatch(assetType, expected) {
|
|
156
|
+
// Split by '/' segments and check for exact segment match
|
|
157
|
+
const segments = assetType.split('/');
|
|
158
|
+
return segments.some((segment) => segment === expected);
|
|
159
|
+
}
|
|
160
|
+
function checkEvmOperationSenders(quote, accountAddress) {
|
|
161
|
+
const accountLower = accountAddress.toLowerCase();
|
|
162
|
+
for (const op of quote.originChainsOperations) {
|
|
163
|
+
if (!isEvmOperation(op))
|
|
164
|
+
continue;
|
|
165
|
+
const senderLower = op.userOp.sender.toLowerCase();
|
|
166
|
+
if (senderLower !== accountLower) {
|
|
167
|
+
return walletErrors.quoteVerificationFailed(`EVM operation sender "${op.userOp.sender}" does not match wallet account "${accountAddress}"`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=quote-verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote-verifier.js","sourceRoot":"","sources":["../../src/internal/quote-verifier.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAwB5C,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,SAAS,cAAc,CAAC,EAAW;IACjC,OAAO,CACL,OAAO,EAAE,KAAK,QAAQ;QACtB,EAAE,KAAK,IAAI;QACX,QAAQ,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AI,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC;QAAE,OAAO,SAAS,CAAC;IAEnE,OAAO,YAAY,CAAC,uBAAuB,CACzC,sBAAsB,MAAM,aAAa,QAAQ,sCAAsC,aAAa,GAAG,CACxG,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,mBAAmB,CAAC,SAAiB,EAAE,QAAgB;IAC9D,0DAA0D;IAC1D,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,wBAAwB,CAC/B,KAAoB,EACpB,cAAsB;IAEtB,MAAM,YAAY,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAElD,KAAK,MAAM,EAAE,IAAI,KAAK,CAAC,sBAAsB,EAAE,CAAC;QAC9C,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YAAE,SAAS;QAElC,MAAM,WAAW,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;YACjC,OAAO,YAAY,CAAC,uBAAuB,CACzC,yBAAyB,EAAE,CAAC,MAAM,CAAC,MAAM,oCAAoC,cAAc,GAAG,CAC/F,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address } from '../result.js';
|
|
2
|
+
import type { RecoveryManager, RecoveryBackends } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a recovery manager for the given wallet signer.
|
|
5
|
+
*
|
|
6
|
+
* @param currentSignerEvmAddress - The EVM address of the current authorized signer.
|
|
7
|
+
* @param currentSignerSolanaAddress - The Solana address of the current authorized signer.
|
|
8
|
+
* @param backends - Injected on-chain recovery backends.
|
|
9
|
+
* @returns A fully-wired {@link RecoveryManager}.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRecoveryManager(currentSignerEvmAddress: Address, currentSignerSolanaAddress: string, backends: RecoveryBackends): RecoveryManager;
|
|
14
|
+
/**
|
|
15
|
+
* Build a dynamic recovery challenge that binds to the specific recovery operation.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The challenge includes:
|
|
19
|
+
* - A domain tag ("prism-recovery-v1") to prevent cross-protocol replay
|
|
20
|
+
* - The current signer address being rotated away
|
|
21
|
+
* - The new signer address being rotated to
|
|
22
|
+
* - A timestamp to prevent replay of old proofs
|
|
23
|
+
*
|
|
24
|
+
* This is hashed with keccak256 to produce a fixed-size challenge.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildRecoveryChallenge(currentSigner: Address, newSigner: Address): Uint8Array;
|
|
29
|
+
//# sourceMappingURL=recovery-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-manager.d.ts","sourceRoot":"","sources":["../../src/internal/recovery-manager.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAEV,eAAe,EACf,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAWrB;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,uBAAuB,EAAE,OAAO,EAChC,0BAA0B,EAAE,MAAM,EAClC,QAAQ,EAAE,gBAAgB,GACzB,eAAe,CAqGjB;AAwBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,OAAO,EACtB,SAAS,EAAE,OAAO,GACjB,UAAU,CASZ"}
|