@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,200 @@
|
|
|
1
|
+
import { Ok, Err, fromPromise } from './result.js';
|
|
2
|
+
import { walletErrors } from './errors.js';
|
|
3
|
+
import { verifyQuoteIntegrity } from './internal/quote-verifier.js';
|
|
4
|
+
import { base58Encode } from './internal/base58.js';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Quote + Sign + Execute
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
/**
|
|
9
|
+
* Execute a cross-chain swap or transfer via OneBalance.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Flow:
|
|
13
|
+
* 1. Get a quote from OneBalance (includes typed data to sign per chain operation)
|
|
14
|
+
* 2. Sign each operation — EVM via signTypedData, Solana via signTransaction
|
|
15
|
+
* 3. Submit the signed quote to OneBalance for execution via Resource Locks
|
|
16
|
+
*
|
|
17
|
+
* @param client - The OneBalance API client.
|
|
18
|
+
* @param signer - The PrismSigner for this wallet.
|
|
19
|
+
* @param params - Quote parameters (assets, amount, slippage).
|
|
20
|
+
* @param accounts - The MultiAccount array for this wallet.
|
|
21
|
+
* @returns A Result with the execution status or a WalletError.
|
|
22
|
+
*/
|
|
23
|
+
export async function executeCrossChain(client, signer, params, accounts, options) {
|
|
24
|
+
// 1. Get quote
|
|
25
|
+
const quoteRequest = {
|
|
26
|
+
from: {
|
|
27
|
+
accounts,
|
|
28
|
+
asset: { assetId: params.fromAsset },
|
|
29
|
+
amount: params.amount,
|
|
30
|
+
},
|
|
31
|
+
to: {
|
|
32
|
+
asset: { assetId: params.toAsset },
|
|
33
|
+
...(params.recipient && { account: params.recipient }),
|
|
34
|
+
},
|
|
35
|
+
...(params.slippageTolerance !== undefined && {
|
|
36
|
+
slippageTolerance: params.slippageTolerance,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
const quoteResult = await fromPromise(client.getQuote(quoteRequest), (e) => toWalletError(e, 'getQuote'));
|
|
40
|
+
if (!quoteResult.ok)
|
|
41
|
+
return quoteResult;
|
|
42
|
+
const quote = quoteResult.value;
|
|
43
|
+
// 2. Verify quote integrity before signing
|
|
44
|
+
if (params.skipVerification !== true) {
|
|
45
|
+
const verificationParams = {
|
|
46
|
+
fromAsset: params.fromAsset,
|
|
47
|
+
toAsset: params.toAsset,
|
|
48
|
+
amount: params.amount,
|
|
49
|
+
...(params.accountAddress !== undefined && { accountAddress: params.accountAddress }),
|
|
50
|
+
};
|
|
51
|
+
const verificationError = verifyQuoteIntegrity(quote, verificationParams);
|
|
52
|
+
if (verificationError !== undefined)
|
|
53
|
+
return Err(verificationError);
|
|
54
|
+
}
|
|
55
|
+
// 3. Sign all operations
|
|
56
|
+
const signResult = await signQuoteOperations(signer, quote, options?.backend);
|
|
57
|
+
if (!signResult.ok)
|
|
58
|
+
return signResult;
|
|
59
|
+
const signedQuote = signResult.value;
|
|
60
|
+
// 4. Execute
|
|
61
|
+
const execResult = await fromPromise(client.executeQuote(signedQuote), (e) => toWalletError(e, 'executeQuote'));
|
|
62
|
+
if (!execResult.ok)
|
|
63
|
+
return execResult;
|
|
64
|
+
return Ok({
|
|
65
|
+
quoteId: signedQuote.id,
|
|
66
|
+
status: 'PENDING',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// Signing Orchestration
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* Sign all operations in a quote.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* Creates a shallow clone of the quote with cloned operations to avoid
|
|
77
|
+
* mutating the original. EVM operations: signs via signTypedData (EIP-712).
|
|
78
|
+
* Solana operations: signs via signTransaction.
|
|
79
|
+
*/
|
|
80
|
+
async function signQuoteOperations(signer, quote, backend) {
|
|
81
|
+
// Shallow clone — only operations are mutated (signature fields)
|
|
82
|
+
const clonedOps = quote.originChainsOperations.map((op) => ({ ...op }));
|
|
83
|
+
const signed = { ...quote, originChainsOperations: clonedOps };
|
|
84
|
+
const doSign = async () => {
|
|
85
|
+
for (const operation of signed.originChainsOperations) {
|
|
86
|
+
if (isSolanaOperation(operation)) {
|
|
87
|
+
const result = await signSolanaOperation(signer, operation);
|
|
88
|
+
if (!result.ok)
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const result = await signEvmOperation(signer, operation);
|
|
93
|
+
if (!result.ok)
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return Ok(signed);
|
|
98
|
+
};
|
|
99
|
+
// Batch under single auth context if backend supports it
|
|
100
|
+
if (backend?.withAuthContext !== undefined) {
|
|
101
|
+
const ctxResult = await backend.withAuthContext('Authorize transaction', async () => {
|
|
102
|
+
const inner = await doSign();
|
|
103
|
+
if (!inner.ok) {
|
|
104
|
+
// Propagate the WalletError through the auth context boundary
|
|
105
|
+
const err = new Error(inner.error.code);
|
|
106
|
+
err.walletError = inner.error;
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
return inner.value;
|
|
110
|
+
});
|
|
111
|
+
if (!ctxResult.ok)
|
|
112
|
+
return ctxResult;
|
|
113
|
+
return Ok(ctxResult.value);
|
|
114
|
+
}
|
|
115
|
+
return doSign();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sign an EVM chain operation via EIP-712 typed data.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* For Kernel v3.1 accounts, OneBalance provides the typed data to sign
|
|
122
|
+
* in the operation's `typedDataToSign` field. The resulting signature is
|
|
123
|
+
* placed in `userOp.signature`.
|
|
124
|
+
*/
|
|
125
|
+
async function signEvmOperation(signer, operation) {
|
|
126
|
+
try {
|
|
127
|
+
const signature = await signer.signTypedData({
|
|
128
|
+
domain: operation.typedDataToSign.domain,
|
|
129
|
+
types: operation.typedDataToSign.types,
|
|
130
|
+
primaryType: operation.typedDataToSign.primaryType,
|
|
131
|
+
message: operation.typedDataToSign.message,
|
|
132
|
+
});
|
|
133
|
+
operation.userOp.signature = signature;
|
|
134
|
+
return Ok(undefined);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
return Err(walletErrors.signingRejected(`EVM operation signing failed: ${String(e)}`));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Sign a Solana chain operation.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* OneBalance provides `dataToSign` as base64-encoded serialized transaction.
|
|
145
|
+
* We sign via PrismSigner.signTransaction and extract the signature.
|
|
146
|
+
*/
|
|
147
|
+
async function signSolanaOperation(signer, operation) {
|
|
148
|
+
try {
|
|
149
|
+
// The PrismSigner.signTransaction expects a transaction-like object.
|
|
150
|
+
// For Solana OneBalance operations, we create a minimal signable wrapper
|
|
151
|
+
// around the base64 dataToSign.
|
|
152
|
+
const dataBytes = base64ToBytes(operation.dataToSign);
|
|
153
|
+
const txLike = {
|
|
154
|
+
message: {
|
|
155
|
+
serialize() {
|
|
156
|
+
return dataBytes;
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
signatures: [new Uint8Array(64)],
|
|
160
|
+
};
|
|
161
|
+
const signed = await signer.signTransaction(txLike);
|
|
162
|
+
const sigBytes = signed.signatures[0];
|
|
163
|
+
if (sigBytes) {
|
|
164
|
+
operation.signature = base58Encode(sigBytes);
|
|
165
|
+
}
|
|
166
|
+
return Ok(undefined);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
return Err(walletErrors.signingRejected(`Solana operation signing failed: ${String(e)}`));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// Type Guards
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
function isSolanaOperation(op) {
|
|
176
|
+
return 'type' in op && op.type === 'solana';
|
|
177
|
+
}
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// Helpers
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
function toWalletError(e, operation) {
|
|
182
|
+
if (e instanceof Error && e.name === 'AbortError') {
|
|
183
|
+
return walletErrors.oneBalanceTimeout(30_000);
|
|
184
|
+
}
|
|
185
|
+
if (e instanceof Error &&
|
|
186
|
+
'statusCode' in e &&
|
|
187
|
+
typeof e.statusCode === 'number') {
|
|
188
|
+
return walletErrors.oneBalanceApi(e.statusCode, String(e));
|
|
189
|
+
}
|
|
190
|
+
return walletErrors.oneBalanceApi(0, `${operation}: ${String(e)}`);
|
|
191
|
+
}
|
|
192
|
+
function base64ToBytes(b64) {
|
|
193
|
+
const binary = atob(b64);
|
|
194
|
+
const bytes = new Uint8Array(binary.length);
|
|
195
|
+
for (let i = 0; i < binary.length; i++) {
|
|
196
|
+
bytes[i] = binary.charCodeAt(i);
|
|
197
|
+
}
|
|
198
|
+
return bytes;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=cross-chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-chain.js","sourceRoot":"","sources":["../src/cross-chain.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAoCpD,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAwB,EACxB,MAAmB,EACnB,MAA6B,EAC7B,QAA0C,EAC1C,OAA+C;IAE/C,eAAe;IACf,MAAM,YAAY,GAAiB;QACjC,IAAI,EAAE;YACJ,QAAQ;YACR,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE;YACpC,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB;QACD,EAAE,EAAE;YACF,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;YAClC,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;SACvD;QACD,GAAG,CAAC,MAAM,CAAC,iBAAiB,KAAK,SAAS,IAAI;YAC5C,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;SAC5C,CAAC;KACH,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,WAAW,CAC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O,YAAY,CAAC,aAAa,CAAC,CAAC,EAAE,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for @prism-ing/wallet.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* All errors are discriminated unions keyed by `code`.
|
|
6
|
+
* No `new Error('...')` — every failure is typed and matchable.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* All possible errors from @prism-ing/wallet operations.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Use the `code` field to match on specific error types.
|
|
15
|
+
* Each variant carries the minimum context needed for debugging.
|
|
16
|
+
*/
|
|
17
|
+
export type WalletError = EnclaveUnavailableError | OneBalanceTimeoutError | OneBalanceApiError | RecoveryGuardianInvalidError | SigningRejectedError | AccountNotInitializedError | InsufficientBalanceError | KeyNotFoundError | ValidationError | SessionKeyExpiredError | SessionKeyPolicyViolationError | QuoteVerificationFailedError | SpendCapNotEnforceableError | RecoveryNotConfiguredError;
|
|
18
|
+
/** Secure Enclave is not available on this platform. */
|
|
19
|
+
export interface EnclaveUnavailableError {
|
|
20
|
+
readonly code: 'ENCLAVE_UNAVAILABLE';
|
|
21
|
+
readonly platform: string;
|
|
22
|
+
}
|
|
23
|
+
/** OneBalance API did not respond within the timeout. */
|
|
24
|
+
export interface OneBalanceTimeoutError {
|
|
25
|
+
readonly code: 'ONEBALANCE_TIMEOUT';
|
|
26
|
+
readonly durationMs: number;
|
|
27
|
+
}
|
|
28
|
+
/** OneBalance API returned an error response. */
|
|
29
|
+
export interface OneBalanceApiError {
|
|
30
|
+
readonly code: 'ONEBALANCE_API_ERROR';
|
|
31
|
+
readonly statusCode: number;
|
|
32
|
+
readonly body: string;
|
|
33
|
+
}
|
|
34
|
+
/** The provided guardian address is not a valid recovery guardian. */
|
|
35
|
+
export interface RecoveryGuardianInvalidError {
|
|
36
|
+
readonly code: 'RECOVERY_GUARDIAN_INVALID';
|
|
37
|
+
readonly address: string;
|
|
38
|
+
readonly reason: string;
|
|
39
|
+
}
|
|
40
|
+
/** The user rejected the signing request (biometric failure, cancellation). */
|
|
41
|
+
export interface SigningRejectedError {
|
|
42
|
+
readonly code: 'SIGNING_REJECTED';
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
}
|
|
45
|
+
/** Attempted an operation on an account that has not been initialized. */
|
|
46
|
+
export interface AccountNotInitializedError {
|
|
47
|
+
readonly code: 'ACCOUNT_NOT_INITIALIZED';
|
|
48
|
+
readonly evmAddress: string;
|
|
49
|
+
}
|
|
50
|
+
/** The account does not have sufficient balance for this operation. */
|
|
51
|
+
export interface InsufficientBalanceError {
|
|
52
|
+
readonly code: 'INSUFFICIENT_BALANCE';
|
|
53
|
+
readonly required: string;
|
|
54
|
+
readonly available: string;
|
|
55
|
+
readonly token: string;
|
|
56
|
+
}
|
|
57
|
+
/** The requested key pair was not found in this signing backend. */
|
|
58
|
+
export interface KeyNotFoundError {
|
|
59
|
+
readonly code: 'KEY_NOT_FOUND';
|
|
60
|
+
readonly evmAddress: string;
|
|
61
|
+
}
|
|
62
|
+
/** Input validation failed (Zod parse error). */
|
|
63
|
+
export interface ValidationError {
|
|
64
|
+
readonly code: 'VALIDATION_ERROR';
|
|
65
|
+
readonly field: string;
|
|
66
|
+
readonly message: string;
|
|
67
|
+
}
|
|
68
|
+
/** Session key has expired. */
|
|
69
|
+
export interface SessionKeyExpiredError {
|
|
70
|
+
readonly code: 'SESSION_KEY_EXPIRED';
|
|
71
|
+
readonly sessionId: string;
|
|
72
|
+
readonly expiredAt: number;
|
|
73
|
+
}
|
|
74
|
+
/** Operation violates session key policy constraints. */
|
|
75
|
+
export interface SessionKeyPolicyViolationError {
|
|
76
|
+
readonly code: 'SESSION_KEY_POLICY_VIOLATION';
|
|
77
|
+
readonly sessionId: string;
|
|
78
|
+
readonly violation: string;
|
|
79
|
+
}
|
|
80
|
+
/** OneBalance quote failed client-side integrity verification. */
|
|
81
|
+
export interface QuoteVerificationFailedError {
|
|
82
|
+
readonly code: 'QUOTE_VERIFICATION_FAILED';
|
|
83
|
+
readonly reason: string;
|
|
84
|
+
}
|
|
85
|
+
/** maxTotalAmount was set but no persistence or on-chain backend was provided. */
|
|
86
|
+
export interface SpendCapNotEnforceableError {
|
|
87
|
+
readonly code: 'SPEND_CAP_NOT_ENFORCEABLE';
|
|
88
|
+
readonly sessionId: string;
|
|
89
|
+
}
|
|
90
|
+
/** Wallet cannot be activated because no recovery guardian has been configured. */
|
|
91
|
+
export interface RecoveryNotConfiguredError {
|
|
92
|
+
readonly code: 'RECOVERY_NOT_CONFIGURED';
|
|
93
|
+
readonly platform: string;
|
|
94
|
+
}
|
|
95
|
+
export declare const walletErrors: {
|
|
96
|
+
readonly enclaveUnavailable: (platform: string) => EnclaveUnavailableError;
|
|
97
|
+
readonly oneBalanceTimeout: (durationMs: number) => OneBalanceTimeoutError;
|
|
98
|
+
readonly oneBalanceApi: (statusCode: number, body: string) => OneBalanceApiError;
|
|
99
|
+
readonly recoveryGuardianInvalid: (address: string, reason: string) => RecoveryGuardianInvalidError;
|
|
100
|
+
readonly signingRejected: (reason: string) => SigningRejectedError;
|
|
101
|
+
readonly accountNotInitialized: (evmAddress: string) => AccountNotInitializedError;
|
|
102
|
+
readonly insufficientBalance: (required: string, available: string, token: string) => InsufficientBalanceError;
|
|
103
|
+
readonly keyNotFound: (evmAddress: string) => KeyNotFoundError;
|
|
104
|
+
readonly validation: (field: string, message: string) => ValidationError;
|
|
105
|
+
readonly sessionKeyExpired: (sessionId: string, expiredAt: number) => SessionKeyExpiredError;
|
|
106
|
+
readonly sessionKeyPolicyViolation: (sessionId: string, violation: string) => SessionKeyPolicyViolationError;
|
|
107
|
+
readonly quoteVerificationFailed: (reason: string) => QuoteVerificationFailedError;
|
|
108
|
+
readonly spendCapNotEnforceable: (sessionId: string) => SpendCapNotEnforceableError;
|
|
109
|
+
readonly recoveryNotConfigured: (platform: string) => RecoveryNotConfiguredError;
|
|
110
|
+
};
|
|
111
|
+
/** Type guard: is this error retryable? */
|
|
112
|
+
export declare const isRetryableError: (error: WalletError) => boolean;
|
|
113
|
+
/** Type guard: is this a user-facing error that should be shown as-is? */
|
|
114
|
+
export declare const isUserFacingError: (error: WalletError) => boolean;
|
|
115
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB,uBAAuB,GACvB,sBAAsB,GACtB,kBAAkB,GAClB,4BAA4B,GAC5B,oBAAoB,GACpB,0BAA0B,GAC1B,wBAAwB,GACxB,gBAAgB,GAChB,eAAe,GACf,sBAAsB,GACtB,8BAA8B,GAC9B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,CAAC;AAE/B,wDAAwD;AACxD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,yDAAyD;AACzD,M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Aa,MAAM,KAAG,8BAA8B;+CAM/D,MAAM,KAAG,4BAA4B;iDAKnC,MAAM,KAAG,2BAA2B;+CAKtC,MAAM,KAAG,0BAA0B;CAI7D,CAAC;AAMX,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB,GAAI,OAAO,WAAW,KAAG,OAMrD,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,GAAI,OAAO,WAAW,KAAG,OAMtD,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for @prism-ing/wallet.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* All errors are discriminated unions keyed by `code`.
|
|
6
|
+
* No `new Error('...')` — every failure is typed and matchable.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Error Constructors — prefer these over raw object literals
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
export const walletErrors = {
|
|
14
|
+
enclaveUnavailable: (platform) => ({
|
|
15
|
+
code: 'ENCLAVE_UNAVAILABLE',
|
|
16
|
+
platform,
|
|
17
|
+
}),
|
|
18
|
+
oneBalanceTimeout: (durationMs) => ({
|
|
19
|
+
code: 'ONEBALANCE_TIMEOUT',
|
|
20
|
+
durationMs,
|
|
21
|
+
}),
|
|
22
|
+
oneBalanceApi: (statusCode, body) => ({
|
|
23
|
+
code: 'ONEBALANCE_API_ERROR',
|
|
24
|
+
statusCode,
|
|
25
|
+
body,
|
|
26
|
+
}),
|
|
27
|
+
recoveryGuardianInvalid: (address, reason) => ({
|
|
28
|
+
code: 'RECOVERY_GUARDIAN_INVALID',
|
|
29
|
+
address,
|
|
30
|
+
reason,
|
|
31
|
+
}),
|
|
32
|
+
signingRejected: (reason) => ({
|
|
33
|
+
code: 'SIGNING_REJECTED',
|
|
34
|
+
reason,
|
|
35
|
+
}),
|
|
36
|
+
accountNotInitialized: (evmAddress) => ({
|
|
37
|
+
code: 'ACCOUNT_NOT_INITIALIZED',
|
|
38
|
+
evmAddress,
|
|
39
|
+
}),
|
|
40
|
+
insufficientBalance: (required, available, token) => ({
|
|
41
|
+
code: 'INSUFFICIENT_BALANCE',
|
|
42
|
+
required,
|
|
43
|
+
available,
|
|
44
|
+
token,
|
|
45
|
+
}),
|
|
46
|
+
keyNotFound: (evmAddress) => ({
|
|
47
|
+
code: 'KEY_NOT_FOUND',
|
|
48
|
+
evmAddress,
|
|
49
|
+
}),
|
|
50
|
+
validation: (field, message) => ({
|
|
51
|
+
code: 'VALIDATION_ERROR',
|
|
52
|
+
field,
|
|
53
|
+
message,
|
|
54
|
+
}),
|
|
55
|
+
sessionKeyExpired: (sessionId, expiredAt) => ({
|
|
56
|
+
code: 'SESSION_KEY_EXPIRED',
|
|
57
|
+
sessionId,
|
|
58
|
+
expiredAt,
|
|
59
|
+
}),
|
|
60
|
+
sessionKeyPolicyViolation: (sessionId, violation) => ({
|
|
61
|
+
code: 'SESSION_KEY_POLICY_VIOLATION',
|
|
62
|
+
sessionId,
|
|
63
|
+
violation,
|
|
64
|
+
}),
|
|
65
|
+
quoteVerificationFailed: (reason) => ({
|
|
66
|
+
code: 'QUOTE_VERIFICATION_FAILED',
|
|
67
|
+
reason,
|
|
68
|
+
}),
|
|
69
|
+
spendCapNotEnforceable: (sessionId) => ({
|
|
70
|
+
code: 'SPEND_CAP_NOT_ENFORCEABLE',
|
|
71
|
+
sessionId,
|
|
72
|
+
}),
|
|
73
|
+
recoveryNotConfigured: (platform) => ({
|
|
74
|
+
code: 'RECOVERY_NOT_CONFIGURED',
|
|
75
|
+
platform,
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Error Matching Utilities
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
/** Type guard: is this error retryable? */
|
|
82
|
+
export const isRetryableError = (error) => {
|
|
83
|
+
const retryableCodes = new Set([
|
|
84
|
+
'ONEBALANCE_TIMEOUT',
|
|
85
|
+
'ONEBALANCE_API_ERROR',
|
|
86
|
+
]);
|
|
87
|
+
return retryableCodes.has(error.code);
|
|
88
|
+
};
|
|
89
|
+
/** Type guard: is this a user-facing error that should be shown as-is? */
|
|
90
|
+
export const isUserFacingError = (error) => {
|
|
91
|
+
const userFacingCodes = new Set([
|
|
92
|
+
'SIGNING_REJECTED',
|
|
93
|
+
'INSUFFICIENT_BALANCE',
|
|
94
|
+
]);
|
|
95
|
+
return userFacingCodes.has(error.code);
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoHH,8EAA8E;AAC9E,6DAA6D;AAC7D,8EAA8E;AAE9E,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,kBAAkB,EAAE,CAAC,QAAgB,EAA2B,EAAE,CAAC,CAAC;QAClE,IAAI,EAAE,qBAAqB;QAC3B,QAAQ;KACT,CAAC;IAEF,iBAAiB,EAAE,CAAC,UAAkB,EAA0B,EAAE,CAAC,CAAC;QAClE,IAAI,EAAE,oBAAoB;QAC1B,UAAU;KACX,CAAC;IAEF,aAAa,EAAE,CAAC,UAAkB,EAAE,IAAY,EAAsB,EAAE,CAAC,CAAC;QACxE,IAAI,EAAE,sBAAsB;QAC5B,UAAU;QACV,IAAI;KACL,CAAC;IAEF,uBAAuB,EAAE,CAAC,OAAe,EAAE,MAAc,EAAgC,EAAE,CAAC,CAAC;QAC3F,IAAI,EAAE,2BAA2B;QACjC,OAAO;QACP,MAAM;KACP,CAAC;IAEF,eAAe,EAAE,CAAC,MAAc,EAAwB,EAAE,CAAC,CAAC;QAC1D,IAAI,EAAE,kBAAkB;QACxB,MAAM;KACP,CAAC;IAEF,qBAAqB,EAAE,CAAC,UA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I,GAAG,CAAC;QAC/D,oBAAoB;QACpB,sBAAsB;KACvB,CAAC,CAAC;IACH,OAAO,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAAW,EAAE;IAC/D,MAAM,eAAe,GAAqC,IAAI,GAAG,CAAC;QAChE,kBAAkB;QAClB,sBAAsB;KACvB,CAAC,CAAC;IACH,OAAO,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @prism-ing/wallet — Production-grade, framework-agnostic wallet SDK.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Wraps OWS (Secure Enclave signing), OneBalance (account abstraction),
|
|
6
|
+
* ZeroDev Social Recovery (EVM), and Squads V4 (Solana) into a single
|
|
7
|
+
* coherent API.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createWallet, type WalletAccount } from '@prism-ing/wallet';
|
|
12
|
+
*
|
|
13
|
+
* const result = await createWallet(config, deps);
|
|
14
|
+
* if (!result.ok) {
|
|
15
|
+
* console.error(result.error.code);
|
|
16
|
+
* return;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* const wallet: WalletAccount = result.value;
|
|
20
|
+
* const balance = await wallet.getBalance();
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { createWallet, createProductionWallet, isPendingRecovery } from './create-wallet.js';
|
|
26
|
+
export type { WalletDeps, ProductionWalletOptions } from './create-wallet.js';
|
|
27
|
+
export type { Result, PrismError, BrandError, Address, Hex, SolanaPublicKey, Bps, Lamports, } from './result.js';
|
|
28
|
+
export { Ok, Err, mapResult, flatMapResult, unwrapResult, fromPromise, toAddress, toHex, toSolanaPublicKey, toBps, toLamports, assertNever, } from './result.js';
|
|
29
|
+
export type { PrismSigner, TypedDataPayload, TypedDataField, WalletAccount, WalletPendingRecovery, UnifiedBalance, ChainBalance, TokenBalance, DepositParams, TxResult, TxStatus, CrossChainSwapParams, SwapResult, RecoveryManager, PasskeyGuardian, RecoveryTx, WalletConfig, SignerConfig, RecoveryConfig, AccountType, Platform, SessionKeyPolicy, SessionKeyHandle, SessionKeyManager, SessionKeyBackend, SpendPersistence, } from './types.js';
|
|
30
|
+
export type { WalletError, EnclaveUnavailableError, OneBalanceTimeoutError, OneBalanceApiError, RecoveryGuardianInvalidError, SigningRejectedError, AccountNotInitializedError, InsufficientBalanceError, KeyNotFoundError, ValidationError, SessionKeyExpiredError, SessionKeyPolicyViolationError, QuoteVerificationFailedError, SpendCapNotEnforceableError, RecoveryNotConfiguredError, } from './errors.js';
|
|
31
|
+
export { walletErrors, isRetryableError, isUserFacingError } from './errors.js';
|
|
32
|
+
export { WalletConfigSchema, SignerConfigSchema, AccountTypeSchema, DepositParamsSchema, CrossChainSwapParamsSchema, AddressSchema, SolanaPublicKeySchema, } from './schemas.js';
|
|
33
|
+
export { executeCrossChain } from './cross-chain.js';
|
|
34
|
+
export type { CrossChainQuoteParams, CrossChainResult } from './cross-chain.js';
|
|
35
|
+
export type { OWSAdapter, OWSKeyPair, SigningBackend } from './signers/ows-adapter.js';
|
|
36
|
+
export { createOWSAdapter } from './signers/ows-adapter.js';
|
|
37
|
+
export { createOWSSigningBackend } from './signers/ows-signing-backend.js';
|
|
38
|
+
export type { OWSBackendConfig } from './signers/ows-signing-backend.js';
|
|
39
|
+
export { createNodeSigningBackend } from './signers/node-signing-backend.js';
|
|
40
|
+
export { createSecureEnclaveBackend } from './signers/secure-enclave-backend.js';
|
|
41
|
+
export type { SecureEnclaveConfig, SecureEnclaveNativeBridge, } from './signers/secure-enclave-types.js';
|
|
42
|
+
export { createSessionKeyManager, validateSessionOperation, recordSessionSpend } from './session-keys.js';
|
|
43
|
+
export { createFileSpendPersistence } from './internal/file-spend-persistence.js';
|
|
44
|
+
export { verifyQuoteIntegrity, verifyEvmOperation } from './internal/quote-verifier.js';
|
|
45
|
+
export type { QuoteVerificationParams } from './internal/quote-verifier.js';
|
|
46
|
+
export { buildRecoveryChallenge } from './internal/recovery-manager.js';
|
|
47
|
+
export { createZeroDevSessionBackend } from './backends/zerodev-session-backend.js';
|
|
48
|
+
export { mapSessionPolicyToZeroDev, resolveAssetToContract } from './backends/zerodev-policy-mapper.js';
|
|
49
|
+
export type { ZeroDevSessionBackendConfig, ZeroDevPolicy, ZeroDevTimestampPolicy, ZeroDevCallPolicy, ZeroDevCallPermission, ZeroDevParamRule, ZeroDevGasPolicy, ZeroDevRateLimitPolicy, ZeroDevSudoPolicy, CallPolicyVersion, ParamCondition, } from './backends/zerodev-types.js';
|
|
50
|
+
export { RECOMMENDED_CALL_POLICY_VERSION, PARAM_CONDITION_VALUES } from './backends/zerodev-types.js';
|
|
51
|
+
export type { RecoveryBackends, EvmRecoveryBackend, SolanaRecoveryBackend, PasskeyBackend, } from './types.js';
|
|
52
|
+
export { createSquadsRecoveryBackend } from './backends/squads-recovery-backend.js';
|
|
53
|
+
export type { SquadsRecoveryBackendConfig, SquadsNativeBridge, SquadsConfigAction, SquadsMemberPermissions, } from './backends/squads-types.js';
|
|
54
|
+
export { FULL_PERMISSIONS, VOTER_PERMISSIONS } from './backends/squads-types.js';
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC7F,YAAY,EAAE,UAAU,EAAE,uBA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pB,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,YAAY,EACV,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @prism-ing/wallet — Production-grade, framework-agnostic wallet SDK.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Wraps OWS (Secure Enclave signing), OneBalance (account abstraction),
|
|
6
|
+
* ZeroDev Social Recovery (EVM), and Squads V4 (Solana) into a single
|
|
7
|
+
* coherent API.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createWallet, type WalletAccount } from '@prism-ing/wallet';
|
|
12
|
+
*
|
|
13
|
+
* const result = await createWallet(config, deps);
|
|
14
|
+
* if (!result.ok) {
|
|
15
|
+
* console.error(result.error.code);
|
|
16
|
+
* return;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* const wallet: WalletAccount = result.value;
|
|
20
|
+
* const balance = await wallet.getBalance();
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
// Public API
|
|
26
|
+
export { createWallet, createProductionWallet, isPendingRecovery } from './create-wallet.js';
|
|
27
|
+
export { Ok, Err, mapResult, flatMapResult, unwrapResult, fromPromise, toAddress, toHex, toSolanaPublicKey, toBps, toLamports, assertNever, } from './result.js';
|
|
28
|
+
export { walletErrors, isRetryableError, isUserFacingError } from './errors.js';
|
|
29
|
+
// Schemas (for consumers who want to validate inputs themselves)
|
|
30
|
+
export { WalletConfigSchema, SignerConfigSchema, AccountTypeSchema, DepositParamsSchema, CrossChainSwapParamsSchema, AddressSchema, SolanaPublicKeySchema, } from './schemas.js';
|
|
31
|
+
// Cross-chain execution
|
|
32
|
+
export { executeCrossChain } from './cross-chain.js';
|
|
33
|
+
export { createOWSAdapter } from './signers/ows-adapter.js';
|
|
34
|
+
export { createOWSSigningBackend } from './signers/ows-signing-backend.js';
|
|
35
|
+
export { createNodeSigningBackend } from './signers/node-signing-backend.js';
|
|
36
|
+
export { createSecureEnclaveBackend } from './signers/secure-enclave-backend.js';
|
|
37
|
+
// Session keys
|
|
38
|
+
export { createSessionKeyManager, validateSessionOperation, recordSessionSpend } from './session-keys.js';
|
|
39
|
+
// Spend persistence
|
|
40
|
+
export { createFileSpendPersistence } from './internal/file-spend-persistence.js';
|
|
41
|
+
// Quote verification
|
|
42
|
+
export { verifyQuoteIntegrity, verifyEvmOperation } from './internal/quote-verifier.js';
|
|
43
|
+
// Recovery (internal export for advanced usage)
|
|
44
|
+
export { buildRecoveryChallenge } from './internal/recovery-manager.js';
|
|
45
|
+
// ZeroDev on-chain session key backend
|
|
46
|
+
export { createZeroDevSessionBackend } from './backends/zerodev-session-backend.js';
|
|
47
|
+
export { mapSessionPolicyToZeroDev, resolveAssetToContract } from './backends/zerodev-policy-mapper.js';
|
|
48
|
+
export { RECOMMENDED_CALL_POLICY_VERSION, PARAM_CONDITION_VALUES } from './backends/zerodev-types.js';
|
|
49
|
+
// Squads V4 Solana recovery backend
|
|
50
|
+
export { createSquadsRecoveryBackend } from './backends/squads-recovery-backend.js';
|
|
51
|
+
export { FULL_PERMISSIONS, VOTER_PERMISSIONS } from './backends/squads-types.js';
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,aAAa;AACb,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAc7F,OAAO,EACL,EAAE,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uCAAuC,CAAC;AAOpF,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/internal/base58.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAwBtD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base58 encoding (Bitcoin alphabet).
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
7
|
+
/** Encode a Uint8Array as a Base58 string. */
|
|
8
|
+
export function base58Encode(bytes) {
|
|
9
|
+
const digits = [0];
|
|
10
|
+
for (const byte of bytes) {
|
|
11
|
+
let carry = byte;
|
|
12
|
+
for (let j = 0; j < digits.length; j++) {
|
|
13
|
+
carry += digits[j] << 8;
|
|
14
|
+
digits[j] = carry % 58;
|
|
15
|
+
carry = (carry / 58) | 0;
|
|
16
|
+
}
|
|
17
|
+
while (carry > 0) {
|
|
18
|
+
digits.push(carry % 58);
|
|
19
|
+
carry = (carry / 58) | 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Leading zeros
|
|
23
|
+
let result = '';
|
|
24
|
+
for (const byte of bytes) {
|
|
25
|
+
if (byte !== 0)
|
|
26
|
+
break;
|
|
27
|
+
result += BASE58_ALPHABET[0];
|
|
28
|
+
}
|
|
29
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
30
|
+
result += BASE58_ALPHABET[digits[i]];
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=base58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TypedDataPayload } from '../types.js';
|
|
2
|
+
/** Strip `0x` prefix and convert hex string to bytes. */
|
|
3
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
4
|
+
export declare function encodeType(primaryType: string, types: Record<string, readonly {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}[]>): string;
|
|
8
|
+
export declare function typeHash(primaryType: string, types: Record<string, readonly {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[]>): Uint8Array;
|
|
12
|
+
export declare function encodeValue(type: string, value: unknown, types: Record<string, readonly {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}[]>): Uint8Array;
|
|
16
|
+
export declare function encodeData(primaryType: string, data: Record<string, unknown>, types: Record<string, readonly {
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
}[]>): Uint8Array;
|
|
20
|
+
export declare function hashStruct(primaryType: string, data: Record<string, unknown>, types: Record<string, readonly {
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
}[]>): Uint8Array;
|
|
24
|
+
export declare function abiEncodeAtomic(type: string, value: unknown): Uint8Array;
|
|
25
|
+
/** Infer the EIP712Domain type from the domain object's keys. */
|
|
26
|
+
export declare function inferDomainType(domain: Record<string, unknown>): readonly {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}[];
|
|
30
|
+
/** Hash a complete EIP-712 typed data payload. */
|
|
31
|
+
export declare function hashTypedData(payload: TypedDataPayload): Uint8Array;
|
|
32
|
+
/** Hash a message per EIP-191 personal sign standard. */
|
|
33
|
+
export declare function personalSignHash(message: string): Uint8Array;
|
|
34
|
+
export interface SolanaLikeTransaction {
|
|
35
|
+
message: {
|
|
36
|
+
serialize(): Uint8Array;
|
|
37
|
+
};
|
|
38
|
+
signatures: Uint8Array[];
|
|
39
|
+
}
|
|
40
|
+
export declare function isSolanaTransaction(tx: unknown): tx is SolanaLikeTransaction;
|
|
41
|
+
//# sourceMappingURL=eip712.d.ts.map
|