@sequence0/sdk 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/README.md +154 -0
- package/dist/chains/bitcoin.d.ts +44 -0
- package/dist/chains/bitcoin.d.ts.map +1 -0
- package/dist/chains/bitcoin.js +152 -0
- package/dist/chains/bitcoin.js.map +1 -0
- package/dist/chains/ethereum.d.ts +60 -0
- package/dist/chains/ethereum.d.ts.map +1 -0
- package/dist/chains/ethereum.js +179 -0
- package/dist/chains/ethereum.js.map +1 -0
- package/dist/chains/solana.d.ts +48 -0
- package/dist/chains/solana.d.ts.map +1 -0
- package/dist/chains/solana.js +157 -0
- package/dist/chains/solana.js.map +1 -0
- package/dist/core/client.d.ts +123 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +311 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/types.d.ts +150 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +8 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/errors.d.ts +26 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +53 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/http.d.ts +23 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +64 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/websocket.d.ts +45 -0
- package/dist/utils/websocket.d.ts.map +1 -0
- package/dist/utils/websocket.js +130 -0
- package/dist/utils/websocket.js.map +1 -0
- package/dist/wallet/wallet.d.ts +144 -0
- package/dist/wallet/wallet.d.ts.map +1 -0
- package/dist/wallet/wallet.js +254 -0
- package/dist/wallet/wallet.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Class
|
|
3
|
+
*
|
|
4
|
+
* Represents a Sequence0 threshold wallet. Sign transactions
|
|
5
|
+
* on any blockchain without holding any private keys — the FROST
|
|
6
|
+
* network handles distributed signing.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const wallet = await s0.createWallet({ chain: 'ethereum' });
|
|
11
|
+
*
|
|
12
|
+
* // Sign and send ETH
|
|
13
|
+
* const txHash = await wallet.sendTransaction({
|
|
14
|
+
* to: '0xRecipientAddress',
|
|
15
|
+
* value: '1000000000000000000', // 1 ETH in wei
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Sign a message (EIP-191)
|
|
19
|
+
* const sig = await wallet.signMessage('Hello, World!');
|
|
20
|
+
*
|
|
21
|
+
* // Get balance
|
|
22
|
+
* const balance = await wallet.getBalance();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { Chain, Threshold, SignedTransaction, EvmTransaction, BtcTransaction, SolTransaction } from '../core/types';
|
|
26
|
+
export interface WalletConfig {
|
|
27
|
+
walletId: string;
|
|
28
|
+
chain: Chain;
|
|
29
|
+
address: string;
|
|
30
|
+
threshold: Threshold;
|
|
31
|
+
network: string;
|
|
32
|
+
agentUrl: string;
|
|
33
|
+
rpcUrl: string;
|
|
34
|
+
curve: string;
|
|
35
|
+
}
|
|
36
|
+
export declare class Wallet {
|
|
37
|
+
/** The wallet's unique ID in the Sequence0 network */
|
|
38
|
+
readonly walletId: string;
|
|
39
|
+
/** Target blockchain */
|
|
40
|
+
readonly chain: Chain;
|
|
41
|
+
/** On-chain address (derived from FROST public key) */
|
|
42
|
+
readonly address: string;
|
|
43
|
+
/** Threshold configuration (t-of-n) */
|
|
44
|
+
readonly threshold: Threshold;
|
|
45
|
+
/** Elliptic curve used */
|
|
46
|
+
readonly curve: string;
|
|
47
|
+
private network;
|
|
48
|
+
private http;
|
|
49
|
+
private adapter;
|
|
50
|
+
private agentUrl;
|
|
51
|
+
constructor(config: WalletConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Sign a transaction using the FROST threshold network
|
|
54
|
+
*
|
|
55
|
+
* Builds a chain-native unsigned transaction, submits it to the
|
|
56
|
+
* agent network for distributed signing, waits for t-of-n agents
|
|
57
|
+
* to produce partial signatures, and returns the aggregated result.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const signed = await wallet.sign({
|
|
62
|
+
* to: '0x...',
|
|
63
|
+
* value: '1000000000000000000',
|
|
64
|
+
* });
|
|
65
|
+
* console.log(signed.hash);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
sign(transaction: EvmTransaction | BtcTransaction | SolTransaction): Promise<SignedTransaction>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign and broadcast a transaction in one call
|
|
71
|
+
*
|
|
72
|
+
* @returns Transaction hash on the target chain
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Send ETH
|
|
77
|
+
* const txHash = await wallet.sendTransaction({
|
|
78
|
+
* to: '0xRecipient',
|
|
79
|
+
* value: '500000000000000000', // 0.5 ETH
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Send with contract call
|
|
83
|
+
* const txHash2 = await wallet.sendTransaction({
|
|
84
|
+
* to: '0xContract',
|
|
85
|
+
* data: '0xa9059cbb000000...', // ERC-20 transfer
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
sendTransaction(transaction: EvmTransaction | BtcTransaction | SolTransaction): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Broadcast an already-signed transaction to the blockchain
|
|
92
|
+
*
|
|
93
|
+
* @returns Transaction hash
|
|
94
|
+
*/
|
|
95
|
+
broadcast(signedTx: SignedTransaction): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Sign a message (EIP-191 for EVM, raw for others)
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const sig = await wallet.signMessage('Hello from Sequence0!');
|
|
102
|
+
* // Verify: ethers.verifyMessage('Hello from Sequence0!', sig) === wallet.address
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
signMessage(message: string): Promise<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Sign EIP-712 typed data (EVM only)
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const sig = await wallet.signTypedData({
|
|
112
|
+
* domain: { name: 'MyDApp', version: '1', chainId: 1 },
|
|
113
|
+
* types: { Permit: [...] },
|
|
114
|
+
* message: { owner: '0x...', spender: '0x...', value: 100 },
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
signTypedData(typedData: {
|
|
119
|
+
domain: Record<string, unknown>;
|
|
120
|
+
types: Record<string, Array<{
|
|
121
|
+
name: string;
|
|
122
|
+
type: string;
|
|
123
|
+
}>>;
|
|
124
|
+
primaryType?: string;
|
|
125
|
+
message: Record<string, unknown>;
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Get the wallet's native token balance
|
|
129
|
+
*
|
|
130
|
+
* @returns Balance as string (wei for EVM, satoshis for BTC, lamports for SOL)
|
|
131
|
+
*/
|
|
132
|
+
getBalance(): Promise<string>;
|
|
133
|
+
/**
|
|
134
|
+
* Get wallet info summary
|
|
135
|
+
*/
|
|
136
|
+
info(): Record<string, unknown>;
|
|
137
|
+
/**
|
|
138
|
+
* Submit a message for FROST signing and wait for the result
|
|
139
|
+
*/
|
|
140
|
+
private requestAndWaitSignature;
|
|
141
|
+
private createAdapter;
|
|
142
|
+
private isEvmChain;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"m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OAQG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBnD;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,SAAS,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC,CAAC;QAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBnB;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAe/B;;OAEG;YACW,uBAAuB;IAgDrC,OAAO,CAAC,aAAa;IAuBrB,OAAO,CAAC,UAAU;CAKrB"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wallet Class
|
|
4
|
+
*
|
|
5
|
+
* Represents a Sequence0 threshold wallet. Sign transactions
|
|
6
|
+
* on any blockchain without holding any private keys — the FROST
|
|
7
|
+
* network handles distributed signing.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const wallet = await s0.createWallet({ chain: 'ethereum' });
|
|
12
|
+
*
|
|
13
|
+
* // Sign and send ETH
|
|
14
|
+
* const txHash = await wallet.sendTransaction({
|
|
15
|
+
* to: '0xRecipientAddress',
|
|
16
|
+
* value: '1000000000000000000', // 1 ETH in wei
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Sign a message (EIP-191)
|
|
20
|
+
* const sig = await wallet.signMessage('Hello, World!');
|
|
21
|
+
*
|
|
22
|
+
* // Get balance
|
|
23
|
+
* const balance = await wallet.getBalance();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Wallet = void 0;
|
|
28
|
+
const http_1 = require("../utils/http");
|
|
29
|
+
const websocket_1 = require("../utils/websocket");
|
|
30
|
+
const errors_1 = require("../utils/errors");
|
|
31
|
+
const ethereum_1 = require("../chains/ethereum");
|
|
32
|
+
const bitcoin_1 = require("../chains/bitcoin");
|
|
33
|
+
const solana_1 = require("../chains/solana");
|
|
34
|
+
class Wallet {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.walletId = config.walletId;
|
|
37
|
+
this.chain = config.chain;
|
|
38
|
+
this.address = config.address;
|
|
39
|
+
this.threshold = config.threshold;
|
|
40
|
+
this.curve = config.curve;
|
|
41
|
+
this.network = config.network;
|
|
42
|
+
this.agentUrl = config.agentUrl;
|
|
43
|
+
this.http = new http_1.HttpClient({ baseUrl: config.agentUrl });
|
|
44
|
+
this.adapter = this.createAdapter(config.chain, config.rpcUrl);
|
|
45
|
+
}
|
|
46
|
+
// ────────────────────────────────────────────────
|
|
47
|
+
// Transaction Signing
|
|
48
|
+
// ────────────────────────────────────────────────
|
|
49
|
+
/**
|
|
50
|
+
* Sign a transaction using the FROST threshold network
|
|
51
|
+
*
|
|
52
|
+
* Builds a chain-native unsigned transaction, submits it to the
|
|
53
|
+
* agent network for distributed signing, waits for t-of-n agents
|
|
54
|
+
* to produce partial signatures, and returns the aggregated result.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const signed = await wallet.sign({
|
|
59
|
+
* to: '0x...',
|
|
60
|
+
* value: '1000000000000000000',
|
|
61
|
+
* });
|
|
62
|
+
* console.log(signed.hash);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async sign(transaction) {
|
|
66
|
+
// 1. Build the unsigned transaction using the chain adapter
|
|
67
|
+
const unsignedTx = await this.adapter.buildTransaction(transaction, this.address);
|
|
68
|
+
// 2. Submit to agent network for FROST signing
|
|
69
|
+
const signature = await this.requestAndWaitSignature(unsignedTx);
|
|
70
|
+
// 3. Attach signature to the transaction
|
|
71
|
+
const rawTransaction = await this.adapter.attachSignature(unsignedTx, signature);
|
|
72
|
+
// 4. Parse signature components
|
|
73
|
+
const sig = signature.startsWith('0x') ? signature.slice(2) : signature;
|
|
74
|
+
return {
|
|
75
|
+
rawTransaction,
|
|
76
|
+
hash: '', // Will be filled on broadcast
|
|
77
|
+
signature: {
|
|
78
|
+
r: '0x' + sig.slice(0, 64),
|
|
79
|
+
s: '0x' + sig.slice(64, 128),
|
|
80
|
+
v: sig.length >= 130 ? parseInt(sig.slice(128, 130), 16) : undefined,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sign and broadcast a transaction in one call
|
|
86
|
+
*
|
|
87
|
+
* @returns Transaction hash on the target chain
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Send ETH
|
|
92
|
+
* const txHash = await wallet.sendTransaction({
|
|
93
|
+
* to: '0xRecipient',
|
|
94
|
+
* value: '500000000000000000', // 0.5 ETH
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // Send with contract call
|
|
98
|
+
* const txHash2 = await wallet.sendTransaction({
|
|
99
|
+
* to: '0xContract',
|
|
100
|
+
* data: '0xa9059cbb000000...', // ERC-20 transfer
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
async sendTransaction(transaction) {
|
|
105
|
+
const signed = await this.sign(transaction);
|
|
106
|
+
return this.broadcast(signed);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Broadcast an already-signed transaction to the blockchain
|
|
110
|
+
*
|
|
111
|
+
* @returns Transaction hash
|
|
112
|
+
*/
|
|
113
|
+
async broadcast(signedTx) {
|
|
114
|
+
const hash = await this.adapter.broadcast(signedTx.rawTransaction);
|
|
115
|
+
signedTx.hash = hash;
|
|
116
|
+
return hash;
|
|
117
|
+
}
|
|
118
|
+
// ────────────────────────────────────────────────
|
|
119
|
+
// Message Signing
|
|
120
|
+
// ────────────────────────────────────────────────
|
|
121
|
+
/**
|
|
122
|
+
* Sign a message (EIP-191 for EVM, raw for others)
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const sig = await wallet.signMessage('Hello from Sequence0!');
|
|
127
|
+
* // Verify: ethers.verifyMessage('Hello from Sequence0!', sig) === wallet.address
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async signMessage(message) {
|
|
131
|
+
// EIP-191 prefix for EVM chains
|
|
132
|
+
const isEvm = this.isEvmChain();
|
|
133
|
+
let messageToSign;
|
|
134
|
+
if (isEvm) {
|
|
135
|
+
const prefix = `\x19Ethereum Signed Message:\n${message.length}`;
|
|
136
|
+
const prefixed = prefix + message;
|
|
137
|
+
// Hash with keccak256
|
|
138
|
+
const encoder = new TextEncoder();
|
|
139
|
+
const bytes = encoder.encode(prefixed);
|
|
140
|
+
messageToSign = Buffer.from(bytes).toString('hex');
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
messageToSign = Buffer.from(message).toString('hex');
|
|
144
|
+
}
|
|
145
|
+
return this.requestAndWaitSignature(messageToSign);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sign EIP-712 typed data (EVM only)
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const sig = await wallet.signTypedData({
|
|
153
|
+
* domain: { name: 'MyDApp', version: '1', chainId: 1 },
|
|
154
|
+
* types: { Permit: [...] },
|
|
155
|
+
* message: { owner: '0x...', spender: '0x...', value: 100 },
|
|
156
|
+
* });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
async signTypedData(typedData) {
|
|
160
|
+
if (!this.isEvmChain()) {
|
|
161
|
+
throw new errors_1.Sequence0Error('signTypedData is only supported on EVM chains');
|
|
162
|
+
}
|
|
163
|
+
// Encode the typed data hash (EIP-712)
|
|
164
|
+
const encoded = JSON.stringify(typedData);
|
|
165
|
+
const messageHex = Buffer.from(encoded).toString('hex');
|
|
166
|
+
return this.requestAndWaitSignature(messageHex);
|
|
167
|
+
}
|
|
168
|
+
// ────────────────────────────────────────────────
|
|
169
|
+
// Balance & Info
|
|
170
|
+
// ────────────────────────────────────────────────
|
|
171
|
+
/**
|
|
172
|
+
* Get the wallet's native token balance
|
|
173
|
+
*
|
|
174
|
+
* @returns Balance as string (wei for EVM, satoshis for BTC, lamports for SOL)
|
|
175
|
+
*/
|
|
176
|
+
async getBalance() {
|
|
177
|
+
return this.adapter.getBalance(this.address);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get wallet info summary
|
|
181
|
+
*/
|
|
182
|
+
info() {
|
|
183
|
+
return {
|
|
184
|
+
walletId: this.walletId,
|
|
185
|
+
chain: this.chain,
|
|
186
|
+
address: this.address,
|
|
187
|
+
threshold: `${this.threshold.t}-of-${this.threshold.n}`,
|
|
188
|
+
curve: this.curve,
|
|
189
|
+
network: this.network,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// ────────────────────────────────────────────────
|
|
193
|
+
// Internals
|
|
194
|
+
// ────────────────────────────────────────────────
|
|
195
|
+
/**
|
|
196
|
+
* Submit a message for FROST signing and wait for the result
|
|
197
|
+
*/
|
|
198
|
+
async requestAndWaitSignature(messageHex, timeoutMs = 30000) {
|
|
199
|
+
// Submit signing request
|
|
200
|
+
const response = await this.http.post('/sign', {
|
|
201
|
+
wallet_id: this.walletId,
|
|
202
|
+
message: messageHex,
|
|
203
|
+
});
|
|
204
|
+
const requestId = response.request_id;
|
|
205
|
+
// Try WebSocket first for instant notification
|
|
206
|
+
try {
|
|
207
|
+
const wsUrl = this.agentUrl.replace(/^http/, 'ws') + '/ws';
|
|
208
|
+
const ws = new websocket_1.WsClient({
|
|
209
|
+
url: wsUrl,
|
|
210
|
+
walletId: this.walletId,
|
|
211
|
+
autoReconnect: false,
|
|
212
|
+
});
|
|
213
|
+
await ws.connect();
|
|
214
|
+
const result = await ws.waitFor('SigningComplete', (e) => e.request_id === requestId, timeoutMs);
|
|
215
|
+
ws.disconnect();
|
|
216
|
+
return result.signature;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// WebSocket failed, fall back to polling
|
|
220
|
+
}
|
|
221
|
+
// Polling fallback
|
|
222
|
+
const deadline = Date.now() + timeoutMs;
|
|
223
|
+
while (Date.now() < deadline) {
|
|
224
|
+
const result = await this.http.get(`/sign/${requestId}`);
|
|
225
|
+
if (result.status === 'complete' && result.signature) {
|
|
226
|
+
return result.signature;
|
|
227
|
+
}
|
|
228
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
229
|
+
}
|
|
230
|
+
throw new errors_1.TimeoutError(`Signing timed out after ${timeoutMs}ms (request: ${requestId})`);
|
|
231
|
+
}
|
|
232
|
+
createAdapter(chain, rpcUrl) {
|
|
233
|
+
switch (chain) {
|
|
234
|
+
case 'bitcoin':
|
|
235
|
+
return new bitcoin_1.BitcoinAdapter(this.network === 'testnet' ? 'testnet' : 'mainnet');
|
|
236
|
+
case 'solana':
|
|
237
|
+
return new solana_1.SolanaAdapter(this.network === 'testnet' ? 'devnet' : 'mainnet', rpcUrl);
|
|
238
|
+
case 'ethereum':
|
|
239
|
+
case 'polygon':
|
|
240
|
+
case 'arbitrum':
|
|
241
|
+
case 'optimism':
|
|
242
|
+
case 'base':
|
|
243
|
+
case 'bsc':
|
|
244
|
+
case 'avalanche':
|
|
245
|
+
default:
|
|
246
|
+
return new ethereum_1.EthereumAdapter(chain, rpcUrl);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
isEvmChain() {
|
|
250
|
+
return ['ethereum', 'polygon', 'arbitrum', 'optimism', 'base', 'bsc', 'avalanche'].includes(this.chain);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.Wallet = Wallet;
|
|
254
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAaH,wCAA2C;AAC3C,kDAA8C;AAC9C,4CAAyF;AACzF,iDAAqD;AACrD,+CAAmD;AACnD,6CAAiD;AAajD,MAAa,MAAM;IAiBf,YAAY,MAAoB;QAC5B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEhC,IAAI,CAAC,IAAI,GAAG,IAAI,iBAAU,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAED,mDAAmD;IACnD,uBAAuB;IACvB,mDAAmD;IAEnD;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,IAAI,CAAC,WAA6D;QACpE,4DAA4D;QAC5D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,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,MAAM,CAAC;YACZ,KAAK,KAAK,CAAC;YACX,KAAK,WAAW,CAAC;YACjB;gBACI,OAAO,IAAI,0BAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;IAEO,UAAU;QACd,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,QAAQ,CACvF,IAAI,CAAC,KAAK,CACb,CAAC;IACN,CAAC;CACJ;AAzRD,wBAyRC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sequence0/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Sequence0 Network SDK — Decentralized threshold signatures for any blockchain",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"lint": "eslint src/**/*.ts"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"sequence0",
|
|
20
|
+
"threshold-signatures",
|
|
21
|
+
"mpc",
|
|
22
|
+
"frost",
|
|
23
|
+
"dkg",
|
|
24
|
+
"blockchain",
|
|
25
|
+
"wallet",
|
|
26
|
+
"signing",
|
|
27
|
+
"multi-chain",
|
|
28
|
+
"decentralized"
|
|
29
|
+
],
|
|
30
|
+
"author": "Sequence0 Network",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/sequence0-network/sdk-typescript"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://sequence0.network",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@solana/web3.js": "^1.90.0",
|
|
39
|
+
"ethers": "^6.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.19.33",
|
|
43
|
+
"eslint": "^8.0.0",
|
|
44
|
+
"jest": "^29.0.0",
|
|
45
|
+
"ts-jest": "^29.0.0",
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
|
+
}
|
|
48
|
+
}
|