@sequence0/sdk 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/core/atomic.d.ts +76 -0
  2. package/dist/core/atomic.d.ts.map +1 -0
  3. package/dist/core/atomic.js +39 -0
  4. package/dist/core/atomic.js.map +1 -0
  5. package/dist/core/client.d.ts +238 -0
  6. package/dist/core/client.d.ts.map +1 -1
  7. package/dist/core/client.js +536 -4
  8. package/dist/core/client.js.map +1 -1
  9. package/dist/core/delegation.d.ts +184 -0
  10. package/dist/core/delegation.d.ts.map +1 -0
  11. package/dist/core/delegation.js +37 -0
  12. package/dist/core/delegation.js.map +1 -0
  13. package/dist/core/programmable.d.ts +66 -0
  14. package/dist/core/programmable.d.ts.map +1 -0
  15. package/dist/core/programmable.js +36 -0
  16. package/dist/core/programmable.js.map +1 -0
  17. package/dist/core/solvency.d.ts +223 -0
  18. package/dist/core/solvency.d.ts.map +1 -0
  19. package/dist/core/solvency.js +267 -0
  20. package/dist/core/solvency.js.map +1 -0
  21. package/dist/core/types.d.ts +11 -0
  22. package/dist/core/types.d.ts.map +1 -1
  23. package/dist/core/universal-account.d.ts +438 -0
  24. package/dist/core/universal-account.d.ts.map +1 -0
  25. package/dist/core/universal-account.js +597 -0
  26. package/dist/core/universal-account.js.map +1 -0
  27. package/dist/core/witness.d.ts +197 -0
  28. package/dist/core/witness.d.ts.map +1 -0
  29. package/dist/core/witness.js +298 -0
  30. package/dist/core/witness.js.map +1 -0
  31. package/dist/erc4337/types.js +2 -2
  32. package/dist/index.d.ts +12 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +15 -3
  35. package/dist/index.js.map +1 -1
  36. package/dist/settlement/settlement.d.ts +152 -0
  37. package/dist/settlement/settlement.d.ts.map +1 -0
  38. package/dist/settlement/settlement.js +172 -0
  39. package/dist/settlement/settlement.js.map +1 -0
  40. package/dist/utils/eip712.js +2 -2
  41. package/dist/utils/fee.d.ts +2 -2
  42. package/dist/utils/fee.js +2 -2
  43. package/dist/wallet/wallet.d.ts +52 -0
  44. package/dist/wallet/wallet.d.ts.map +1 -1
  45. package/dist/wallet/wallet.js +204 -0
  46. package/dist/wallet/wallet.js.map +1 -1
  47. package/package.json +1 -1
@@ -0,0 +1,152 @@
1
+ /**
2
+ * K3: Universal Settlement Network -- multilateral netting + atomic settlement
3
+ *
4
+ * Provides a settlement layer for batching and netting payment intents across
5
+ * multiple wallets and chains. Instead of executing every individual transfer
6
+ * on-chain, the settlement engine accumulates intents during a cycle, computes
7
+ * net positions via multilateral netting, and settles only the net amounts
8
+ * atomically using K2 cross-chain signing.
9
+ *
10
+ * Settlement cycles:
11
+ * 1. OPEN -- intents are accepted and queued
12
+ * 2. NETTING -- cycle closes, net positions are computed (off-chain)
13
+ * 3. SETTLING -- atomic signing + broadcast of net transfers (via K2)
14
+ * 4. COMPLETE -- all net transfers confirmed on-chain
15
+ * 5. FAILED -- one or more net transfers could not settle
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { Sequence0 } from '@sequence0/sdk';
20
+ *
21
+ * const s0 = new Sequence0({ network: 'mainnet', ownerPrivateKey: '0x...' });
22
+ * const settlement = s0.getSettlementClient();
23
+ *
24
+ * // Submit a payment intent
25
+ * const { intentHash, cycleId } = await settlement.submitIntent(
26
+ * {
27
+ * senderWalletId: 'alice-eth-wallet',
28
+ * recipientWalletId: 'bob-eth-wallet',
29
+ * chain: 'ethereum',
30
+ * amount: '1000000000000000000', // 1 ETH
31
+ * },
32
+ * ownerSignature,
33
+ * timestamp,
34
+ * );
35
+ *
36
+ * // Check current cycle status
37
+ * const cycle = await settlement.getCurrentCycle();
38
+ * console.log(cycle.status); // 'open' | 'netting' | 'settling' | 'complete'
39
+ * ```
40
+ */
41
+ import { Chain } from '../core/types';
42
+ import { HttpClient } from '../utils/http';
43
+ export interface SettlementIntent {
44
+ /** Wallet ID of the sender */
45
+ senderWalletId: string;
46
+ /** Wallet ID of the recipient */
47
+ recipientWalletId: string;
48
+ /** Target blockchain for settlement */
49
+ chain: Chain;
50
+ /** Amount in the chain's smallest denomination (e.g. wei, lamports) */
51
+ amount: string;
52
+ /** Token contract address. Omit for native token transfers. */
53
+ token?: string;
54
+ }
55
+ export interface SettlementCycle {
56
+ /** Unique cycle identifier */
57
+ cycleId: number;
58
+ /** Current cycle status */
59
+ status: 'open' | 'netting' | 'settling' | 'complete' | 'failed';
60
+ /** Number of intents in this cycle */
61
+ intentCount: number;
62
+ /** Unix timestamp when the cycle opened */
63
+ openedAt: number;
64
+ /** Unix timestamp when the cycle closed (undefined if still open) */
65
+ closedAt?: number;
66
+ }
67
+ export interface NetPosition {
68
+ /** Sender wallet ID (after netting) */
69
+ senderWallet: string;
70
+ /** Recipient wallet ID (after netting) */
71
+ recipientWallet: string;
72
+ /** Chain for this net transfer */
73
+ chain: string;
74
+ /** Net amount to transfer (smallest denomination) */
75
+ netAmount: string;
76
+ }
77
+ export interface SettlementResult {
78
+ /** Cycle that was settled */
79
+ cycleId: number;
80
+ /** K2 atomic manifest ID used for settlement */
81
+ manifestId: string;
82
+ /** Final status */
83
+ status: 'complete' | 'failed';
84
+ /** Computed net positions that were settled */
85
+ netPositions: NetPosition[];
86
+ /** Error message if settlement failed */
87
+ error?: string;
88
+ }
89
+ /**
90
+ * Settlement client for K3 Universal Settlement Network.
91
+ *
92
+ * Communicates with settlement endpoints on the agent node to submit
93
+ * payment intents, query cycle status, and retrieve settlement history.
94
+ */
95
+ export declare class SettlementClient {
96
+ private httpClient;
97
+ /**
98
+ * Create a new SettlementClient
99
+ *
100
+ * @param baseUrl - Agent node REST API URL
101
+ * @param httpClient - Shared HttpClient instance for making requests
102
+ */
103
+ constructor(baseUrl: string, httpClient: HttpClient);
104
+ /**
105
+ * Submit a payment intent to the current open settlement cycle.
106
+ *
107
+ * The intent is queued for netting when the cycle closes. The caller must
108
+ * provide an ownership proof (signature + timestamp) to authorize the
109
+ * sender wallet.
110
+ *
111
+ * @param intent - Payment intent details
112
+ * @param ownerSignature - EIP-712 ownership proof signature (hex string)
113
+ * @param timestamp - Unix timestamp used in the ownership proof
114
+ * @returns The intent hash and the cycle it was assigned to
115
+ *
116
+ * @throws {Sequence0Error} If the intent is invalid or the cycle is not open
117
+ * @throws {NetworkError} If the agent is unreachable
118
+ */
119
+ submitIntent(intent: SettlementIntent, ownerSignature: string, timestamp: number): Promise<{
120
+ intentHash: string;
121
+ cycleId: number;
122
+ }>;
123
+ /**
124
+ * Get the current open settlement cycle.
125
+ *
126
+ * @returns Current cycle status
127
+ * @throws {NetworkError} If the agent is unreachable
128
+ */
129
+ getCurrentCycle(): Promise<SettlementCycle>;
130
+ /**
131
+ * Get a specific settlement cycle by ID.
132
+ *
133
+ * @param cycleId - The cycle ID to look up
134
+ * @returns Cycle status and details
135
+ * @throws {Sequence0Error} If the cycle is not found
136
+ * @throws {NetworkError} If the agent is unreachable
137
+ */
138
+ getCycle(cycleId: number): Promise<SettlementCycle>;
139
+ /**
140
+ * Get settlement cycle history.
141
+ *
142
+ * @param limit - Max number of cycles to return (default: 20)
143
+ * @returns Array of settlement cycles, most recent first
144
+ * @throws {NetworkError} If the agent is unreachable
145
+ */
146
+ getCycleHistory(limit?: number): Promise<SettlementCycle[]>;
147
+ /**
148
+ * Map a raw cycle response from the agent to the SettlementCycle interface.
149
+ */
150
+ private mapCycleResponse;
151
+ }
152
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../../src/settlement/settlement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,MAAM,WAAW,gBAAgB;IAC7B,8BAA8B;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB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MAAM,GAClB,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IA0CnD;;;;;OAKG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,CAAC;IAYjD;;;;;;;OAOG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAgBzD;;;;;;OAMG;IACG,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAuBjE;;OAEG;IACH,OAAO,CAAC,gBAAgB;CA0B3B"}
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /**
3
+ * K3: Universal Settlement Network -- multilateral netting + atomic settlement
4
+ *
5
+ * Provides a settlement layer for batching and netting payment intents across
6
+ * multiple wallets and chains. Instead of executing every individual transfer
7
+ * on-chain, the settlement engine accumulates intents during a cycle, computes
8
+ * net positions via multilateral netting, and settles only the net amounts
9
+ * atomically using K2 cross-chain signing.
10
+ *
11
+ * Settlement cycles:
12
+ * 1. OPEN -- intents are accepted and queued
13
+ * 2. NETTING -- cycle closes, net positions are computed (off-chain)
14
+ * 3. SETTLING -- atomic signing + broadcast of net transfers (via K2)
15
+ * 4. COMPLETE -- all net transfers confirmed on-chain
16
+ * 5. FAILED -- one or more net transfers could not settle
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { Sequence0 } from '@sequence0/sdk';
21
+ *
22
+ * const s0 = new Sequence0({ network: 'mainnet', ownerPrivateKey: '0x...' });
23
+ * const settlement = s0.getSettlementClient();
24
+ *
25
+ * // Submit a payment intent
26
+ * const { intentHash, cycleId } = await settlement.submitIntent(
27
+ * {
28
+ * senderWalletId: 'alice-eth-wallet',
29
+ * recipientWalletId: 'bob-eth-wallet',
30
+ * chain: 'ethereum',
31
+ * amount: '1000000000000000000', // 1 ETH
32
+ * },
33
+ * ownerSignature,
34
+ * timestamp,
35
+ * );
36
+ *
37
+ * // Check current cycle status
38
+ * const cycle = await settlement.getCurrentCycle();
39
+ * console.log(cycle.status); // 'open' | 'netting' | 'settling' | 'complete'
40
+ * ```
41
+ */
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.SettlementClient = void 0;
44
+ const errors_1 = require("../utils/errors");
45
+ // ── Settlement Client ──
46
+ /**
47
+ * Settlement client for K3 Universal Settlement Network.
48
+ *
49
+ * Communicates with settlement endpoints on the agent node to submit
50
+ * payment intents, query cycle status, and retrieve settlement history.
51
+ */
52
+ class SettlementClient {
53
+ /**
54
+ * Create a new SettlementClient
55
+ *
56
+ * @param baseUrl - Agent node REST API URL
57
+ * @param httpClient - Shared HttpClient instance for making requests
58
+ */
59
+ constructor(baseUrl, httpClient) {
60
+ this.httpClient = httpClient;
61
+ }
62
+ /**
63
+ * Submit a payment intent to the current open settlement cycle.
64
+ *
65
+ * The intent is queued for netting when the cycle closes. The caller must
66
+ * provide an ownership proof (signature + timestamp) to authorize the
67
+ * sender wallet.
68
+ *
69
+ * @param intent - Payment intent details
70
+ * @param ownerSignature - EIP-712 ownership proof signature (hex string)
71
+ * @param timestamp - Unix timestamp used in the ownership proof
72
+ * @returns The intent hash and the cycle it was assigned to
73
+ *
74
+ * @throws {Sequence0Error} If the intent is invalid or the cycle is not open
75
+ * @throws {NetworkError} If the agent is unreachable
76
+ */
77
+ async submitIntent(intent, ownerSignature, timestamp) {
78
+ if (!intent.senderWalletId || typeof intent.senderWalletId !== 'string') {
79
+ throw new errors_1.Sequence0Error('senderWalletId must be a non-empty string');
80
+ }
81
+ if (!intent.recipientWalletId || typeof intent.recipientWalletId !== 'string') {
82
+ throw new errors_1.Sequence0Error('recipientWalletId must be a non-empty string');
83
+ }
84
+ if (!intent.amount || typeof intent.amount !== 'string') {
85
+ throw new errors_1.Sequence0Error('amount must be a non-empty string');
86
+ }
87
+ if (!ownerSignature || typeof ownerSignature !== 'string') {
88
+ throw new errors_1.Sequence0Error('ownerSignature must be a non-empty string');
89
+ }
90
+ if (typeof timestamp !== 'number' || timestamp <= 0) {
91
+ throw new errors_1.Sequence0Error('timestamp must be a positive number');
92
+ }
93
+ const response = await this.httpClient.post('/settlement/submit-intent', {
94
+ sender_wallet_id: intent.senderWalletId,
95
+ recipient_wallet_id: intent.recipientWalletId,
96
+ chain: intent.chain,
97
+ amount: intent.amount,
98
+ token: intent.token,
99
+ owner_signature: ownerSignature,
100
+ timestamp,
101
+ });
102
+ if (!response || typeof response.intent_hash !== 'string') {
103
+ throw new errors_1.Sequence0Error('Invalid response from /settlement/submit-intent: missing intent_hash');
104
+ }
105
+ return {
106
+ intentHash: response.intent_hash,
107
+ cycleId: response.cycle_id,
108
+ };
109
+ }
110
+ /**
111
+ * Get the current open settlement cycle.
112
+ *
113
+ * @returns Current cycle status
114
+ * @throws {NetworkError} If the agent is unreachable
115
+ */
116
+ async getCurrentCycle() {
117
+ const response = await this.httpClient.get('/settlement/cycle/current');
118
+ return this.mapCycleResponse(response);
119
+ }
120
+ /**
121
+ * Get a specific settlement cycle by ID.
122
+ *
123
+ * @param cycleId - The cycle ID to look up
124
+ * @returns Cycle status and details
125
+ * @throws {Sequence0Error} If the cycle is not found
126
+ * @throws {NetworkError} If the agent is unreachable
127
+ */
128
+ async getCycle(cycleId) {
129
+ if (typeof cycleId !== 'number' || cycleId < 0) {
130
+ throw new errors_1.Sequence0Error('cycleId must be a non-negative number');
131
+ }
132
+ const response = await this.httpClient.get(`/settlement/cycle/${cycleId}`);
133
+ return this.mapCycleResponse(response);
134
+ }
135
+ /**
136
+ * Get settlement cycle history.
137
+ *
138
+ * @param limit - Max number of cycles to return (default: 20)
139
+ * @returns Array of settlement cycles, most recent first
140
+ * @throws {NetworkError} If the agent is unreachable
141
+ */
142
+ async getCycleHistory(limit) {
143
+ const queryLimit = limit && limit > 0 ? limit : 20;
144
+ const response = await this.httpClient.get(`/settlement/history?limit=${queryLimit}`);
145
+ if (!response || !Array.isArray(response.cycles)) {
146
+ throw new errors_1.Sequence0Error('Invalid response from /settlement/history: missing cycles array');
147
+ }
148
+ return response.cycles.map((c) => this.mapCycleResponse(c));
149
+ }
150
+ // ── Internals ──
151
+ /**
152
+ * Map a raw cycle response from the agent to the SettlementCycle interface.
153
+ */
154
+ mapCycleResponse(response) {
155
+ if (!response || typeof response.cycle_id !== 'number') {
156
+ throw new errors_1.Sequence0Error('Invalid settlement cycle response: missing cycle_id');
157
+ }
158
+ const validStatuses = ['open', 'netting', 'settling', 'complete', 'failed'];
159
+ const status = validStatuses.includes(response.status)
160
+ ? response.status
161
+ : 'open';
162
+ return {
163
+ cycleId: response.cycle_id,
164
+ status,
165
+ intentCount: response.intent_count ?? 0,
166
+ openedAt: response.opened_at ?? 0,
167
+ closedAt: response.closed_at,
168
+ };
169
+ }
170
+ }
171
+ exports.SettlementClient = SettlementClient;
172
+ //# sourceMappingURL=settlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.js","sourceRoot":"","sources":["../../src/settlement/settlement.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAIH,4CAA6E;AA4D7E,0BAA0B;AAE1B;;;;;GAKG;AACH,MAAa,gBAAgB;IAGzB;;;;;OAKG;IACH,YAAY,OAAe,EAAE,UAAsB;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,YAAY,CACd,MAAwB,EACxB,cAAsB,EACtB,SAAiB;QAEjB,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,EAAE,CAAC;YACtE,MAAM,IAAI,uBAAc,CAAC,2CAA2C,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,OAAO,MAAM,CAAC,iBAAiB,KAAK,QAAQ,EAAE,CAAC;YAC5E,MAAM,IAAI,uBAAc,CAAC,8CAA8C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M,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAClD,CAAC,CAAE,QAAQ,CAAC,MAAoC;YAChD,CAAC,CAAC,MAAM,CAAC;QAEb,OAAO;YACH,OAAO,EAAE,QAAQ,CAAC,QAAQ;YAC1B,MAAM;YACN,WAAW,EAAE,QAAQ,CAAC,YAAY,IAAI,CAAC;YACvC,QAAQ,EAAE,QAAQ,CAAC,SAAS,IAAI,CAAC;YACjC,QAAQ,EAAE,QAAQ,CAAC,SAAS;SAC/B,CAAC;IACN,CAAC;CACJ;AA/KD,4CA+KC"}
@@ -29,8 +29,8 @@ function abiEncode(slots) {
29
29
  }
30
30
  /** WalletFactory contract addresses (EIP-712 verifyingContract) */
31
31
  exports.WALLET_FACTORY_ADDRESSES = {
32
- testnet: '0x2379786fa3fb6e9de621df5ae91ec6035f9122ed',
33
- mainnet: '0x06f3556ffa89ca7060c727fff0f7e2444380cb58',
32
+ testnet: '0x0fdb2d2147b80fd2e9ad4b8d1a70b68c1353afe3',
33
+ mainnet: '0x05b4df6ab0684bcc82a4a92677e4b46007638604',
34
34
  };
35
35
  /** Sequence0 chain IDs (EIP-712 chainId) */
36
36
  exports.SEQUENCE0_CHAIN_IDS = {
@@ -12,8 +12,8 @@
12
12
  * ```typescript
13
13
  * const fee = new FeeManager({
14
14
  * rpcUrl: 'https://rpc.sequence0.network',
15
- * feeCollectorAddress: '0x1977f852aa0d16a59c4ea71b6cc72db02803395f',
16
- * registryAddress: '0x774d9a0dc937bfdc7636cbc6e0fc37f9a0809177',
15
+ * feeCollectorAddress: '0xccd70007534c33b0ab3997d81207fea5e59ca54a',
16
+ * registryAddress: '0xdefa5ab7ea6a87ac51628f4cde55bb4d49e62f50',
17
17
  * });
18
18
  *
19
19
  * // Get the current per-signature fee
package/dist/utils/fee.js CHANGED
@@ -13,8 +13,8 @@
13
13
  * ```typescript
14
14
  * const fee = new FeeManager({
15
15
  * rpcUrl: 'https://rpc.sequence0.network',
16
- * feeCollectorAddress: '0x1977f852aa0d16a59c4ea71b6cc72db02803395f',
17
- * registryAddress: '0x774d9a0dc937bfdc7636cbc6e0fc37f9a0809177',
16
+ * feeCollectorAddress: '0xccd70007534c33b0ab3997d81207fea5e59ca54a',
17
+ * registryAddress: '0xdefa5ab7ea6a87ac51628f4cde55bb4d49e62f50',
18
18
  * });
19
19
  *
20
20
  * // Get the current per-signature fee
@@ -23,6 +23,8 @@
23
23
  * ```
24
24
  */
25
25
  import { Chain, Threshold, SignedTransaction, EvmTransaction, BtcTransaction, SolTransaction, OwnerSigner } from '../core/types';
26
+ import { AtomicOperation, AtomicSignResult } from '../core/atomic';
27
+ import { DelegateOptions, SubDelegateOptions, DelegationGrant, DelegationTree } from '../core/delegation';
26
28
  export interface WalletConfig {
27
29
  walletId: string;
28
30
  chain: Chain;
@@ -134,6 +136,32 @@ export declare class Wallet {
134
136
  primaryType?: string;
135
137
  message: Record<string, unknown>;
136
138
  }): Promise<string>;
139
+ /**
140
+ * Sign this wallet's transaction as part of an atomic multi-chain operation.
141
+ *
142
+ * Builds the signing message from the provided transaction, combines it
143
+ * with the other operations, and submits the entire batch atomically via
144
+ * the agent network. Either all operations succeed or none do.
145
+ *
146
+ * @param transaction - Transaction to build and sign for this wallet
147
+ * @param otherOperations - Other wallet operations in the atomic batch
148
+ * @returns Atomic result with all signatures or abort error
149
+ *
150
+ * @throws {Sequence0Error} If no ownerSigner is configured
151
+ * @throws {TimeoutError} If the atomic signing times out
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const ethWallet = await s0.getWallet('eth-wallet');
156
+ * const result = await ethWallet.signInAtomic(
157
+ * { to: '0x...', value: '1000000000000000000' },
158
+ * [
159
+ * { walletId: 'arb-wallet', chain: 'arbitrum', message: '0x...' },
160
+ * ],
161
+ * );
162
+ * ```
163
+ */
164
+ signInAtomic(transaction: EvmTransaction | BtcTransaction | SolTransaction, otherOperations: AtomicOperation[]): Promise<AtomicSignResult>;
137
165
  /**
138
166
  * Get the wallet's native token balance
139
167
  *
@@ -173,5 +201,29 @@ export declare class Wallet {
173
201
  * higher level via the BitcoinTaprootAdapter's direct API.
174
202
  */
175
203
  private extractBitcoinSighash;
204
+ /**
205
+ * Delegate signing authority to another address.
206
+ */
207
+ delegate(options: DelegateOptions): Promise<DelegationGrant>;
208
+ /**
209
+ * Create a sub-delegation from an existing delegation grant.
210
+ */
211
+ delegateFrom(options: SubDelegateOptions): Promise<DelegationGrant>;
212
+ /**
213
+ * Revoke a delegation grant (cascading to all sub-grants).
214
+ */
215
+ revoke(delegationId: string): Promise<void>;
216
+ /**
217
+ * List all delegation grants for this wallet.
218
+ */
219
+ listDelegations(): Promise<DelegationGrant[]>;
220
+ /**
221
+ * Get the delegation tree for this wallet.
222
+ */
223
+ getDelegationTree(): Promise<DelegationTree>;
224
+ /**
225
+ * Send heartbeat for dead-man's switch delegation grants.
226
+ */
227
+ heartbeat(): Promise<void>;
176
228
  }
177
229
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACH,KAAK,EACL,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EAId,WAAW,EACd,MAAM,eAAe,CAAC;AA+BvB,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,qBAAa,MAAM;IACf,sDAAsD;IACtD,QAAQ,C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,EAAE,cAAc,GAAG,cAAc,GAAG,cAAc,EAC7D,eAAe,EAAE,eAAe,EAAE,GACnC,OAAO,CAAC,gBAAgB,CAAC;IAkH5B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAe/B;;OAEG;YACW,uBAAuB;IAsErC;;;;;;;;;OASG;YACW,kBAAkB;IAqBhC,OAAO,CAAC,aAAa;IAgDrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAYhC;IAEF,OAAO,CAAC,UAAU;IAIlB;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IAiB7B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAqBlE;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC;IA2BzE;;OAEG;IACG,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjD;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAOnD;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAMlD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAWnC"}
@@ -215,6 +215,115 @@ class Wallet {
215
215
  return this.requestAndWaitSignature(messageHex);
216
216
  }
217
217
  // ────────────────────────────────────────────────
218
+ // Atomic Signing (K2)
219
+ // ────────────────────────────────────────────────
220
+ /**
221
+ * Sign this wallet's transaction as part of an atomic multi-chain operation.
222
+ *
223
+ * Builds the signing message from the provided transaction, combines it
224
+ * with the other operations, and submits the entire batch atomically via
225
+ * the agent network. Either all operations succeed or none do.
226
+ *
227
+ * @param transaction - Transaction to build and sign for this wallet
228
+ * @param otherOperations - Other wallet operations in the atomic batch
229
+ * @returns Atomic result with all signatures or abort error
230
+ *
231
+ * @throws {Sequence0Error} If no ownerSigner is configured
232
+ * @throws {TimeoutError} If the atomic signing times out
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const ethWallet = await s0.getWallet('eth-wallet');
237
+ * const result = await ethWallet.signInAtomic(
238
+ * { to: '0x...', value: '1000000000000000000' },
239
+ * [
240
+ * { walletId: 'arb-wallet', chain: 'arbitrum', message: '0x...' },
241
+ * ],
242
+ * );
243
+ * ```
244
+ */
245
+ async signInAtomic(transaction, otherOperations) {
246
+ // Build the unsigned transaction to get the signing message
247
+ const unsignedTx = await this.adapter.buildTransaction(transaction, this.address);
248
+ let signingMessage;
249
+ if (this.adapter.getSigningPayload) {
250
+ signingMessage = this.adapter.getSigningPayload(unsignedTx);
251
+ }
252
+ else if (this.chain === 'bitcoin') {
253
+ signingMessage = this.extractBitcoinSighash(unsignedTx);
254
+ }
255
+ else {
256
+ signingMessage = unsignedTx;
257
+ }
258
+ // Build the ownership proof for this wallet
259
+ const proof = await this.signOwnershipProof('atomic-sign');
260
+ if (!proof) {
261
+ throw new errors_1.Sequence0Error('ownerSigner or ownerPrivateKey is required for atomic signing');
262
+ }
263
+ // Build proofs for other operations
264
+ const otherProofs = [];
265
+ for (const op of otherOperations) {
266
+ const otherProof = await this.signOwnershipProof('atomic-sign');
267
+ otherProofs.push(otherProof || { owner_signature: '', timestamp: 0 });
268
+ }
269
+ // Combine this wallet's operation with the others
270
+ const thisOperation = {
271
+ wallet_id: this.walletId,
272
+ chain: this.chain,
273
+ message: signingMessage,
274
+ owner_signature: proof.owner_signature,
275
+ timestamp: proof.timestamp,
276
+ };
277
+ const allOperations = [
278
+ thisOperation,
279
+ ...otherOperations.map((op, i) => ({
280
+ wallet_id: op.walletId,
281
+ chain: op.chain,
282
+ message: op.message,
283
+ owner_signature: otherProofs[i].owner_signature,
284
+ timestamp: otherProofs[i].timestamp,
285
+ })),
286
+ ];
287
+ // Submit the atomic signing request
288
+ const rawResponse = await this.http.post('/sign-atomic', {
289
+ operations: allOperations,
290
+ deadline_blocks: 50,
291
+ });
292
+ if (!rawResponse || typeof rawResponse.manifest_id !== 'string') {
293
+ throw new errors_1.Sequence0Error('Invalid response from /sign-atomic: missing manifest_id');
294
+ }
295
+ const manifestId = rawResponse.manifest_id;
296
+ const timeout = 60000;
297
+ const deadline = Date.now() + timeout;
298
+ // Poll for completion
299
+ while (Date.now() < deadline) {
300
+ const result = await this.http.get(`/sign-atomic/${manifestId}`);
301
+ if (result.status === 'committed') {
302
+ const signatures = new Map();
303
+ if (result.signatures) {
304
+ for (const [reqId, sig] of Object.entries(result.signatures)) {
305
+ signatures.set(reqId, sig);
306
+ }
307
+ }
308
+ return {
309
+ manifestId,
310
+ status: 'committed',
311
+ signatures,
312
+ };
313
+ }
314
+ if (result.status === 'aborted') {
315
+ return {
316
+ manifestId,
317
+ status: 'aborted',
318
+ signatures: new Map(),
319
+ error: result.error || 'Atomic signing batch aborted by the agent network',
320
+ };
321
+ }
322
+ await new Promise((r) => setTimeout(r, 1000));
323
+ }
324
+ throw new errors_1.TimeoutError(`Atomic signing manifest ${manifestId} timed out after ${timeout}ms`);
325
+ }
326
+ // ────────────────────────────────────────────────
218
327
  // Balance & Info
219
328
  // ────────────────────────────────────────────────
220
329
  /**
@@ -389,6 +498,101 @@ class Wallet {
389
498
  }
390
499
  return unsignedTxHex;
391
500
  }
501
+ // ────────────────────────────────────────────────
502
+ // K4: Sovereign Agency Protocol — Delegation
503
+ // ────────────────────────────────────────────────
504
+ /**
505
+ * Delegate signing authority to another address.
506
+ */
507
+ async delegate(options) {
508
+ const proof = await this.signOwnershipProof('delegate');
509
+ if (!proof) {
510
+ throw new errors_1.Sequence0Error('ownerSigner is required to create delegation grants');
511
+ }
512
+ return this.http.post('/delegations', {
513
+ wallet_id: this.walletId,
514
+ delegate: options.to,
515
+ chains: options.chains,
516
+ wasm_policy_id: options.wasmPolicyId,
517
+ constraints: options.constraints,
518
+ valid_from: options.validFrom || new Date().toISOString(),
519
+ valid_until: options.validUntil,
520
+ sub_delegation: options.subDelegation ?? false,
521
+ max_sub_depth: options.maxSubDepth ?? 0,
522
+ activation: options.activation,
523
+ owner_signature: proof.owner_signature,
524
+ timestamp: proof.timestamp,
525
+ });
526
+ }
527
+ /**
528
+ * Create a sub-delegation from an existing delegation grant.
529
+ */
530
+ async delegateFrom(options) {
531
+ const signerKey = options.signerKey.startsWith('0x') ? options.signerKey : '0x' + options.signerKey;
532
+ const { SigningKey: EthersSigningKey } = require('ethers');
533
+ const delegateSigningKey = new EthersSigningKey(signerKey);
534
+ const timestamp = Math.floor(Date.now() / 1000);
535
+ const chainId = eip712_1.SEQUENCE0_CHAIN_IDS[this.network] || eip712_1.SEQUENCE0_CHAIN_IDS.mainnet;
536
+ const walletFactory = eip712_1.WALLET_FACTORY_ADDRESSES[this.network] || eip712_1.WALLET_FACTORY_ADDRESSES.mainnet;
537
+ const digest = (0, eip712_1.computeEip712Digest)(this.walletId, 'sub-delegate', timestamp, chainId, walletFactory);
538
+ const sig = delegateSigningKey.sign(digest);
539
+ const v = sig.v === 27 ? '1b' : '1c';
540
+ const delegateSignature = '0x' + sig.r.slice(2) + sig.s.slice(2) + v;
541
+ return this.http.post('/delegations/sub', {
542
+ wallet_id: this.walletId,
543
+ parent_grant_id: options.parentGrantId,
544
+ delegate: options.to,
545
+ chains: options.chains,
546
+ constraints: options.constraints,
547
+ valid_from: options.validFrom || new Date().toISOString(),
548
+ valid_until: options.validUntil,
549
+ sub_delegation: options.subDelegation ?? false,
550
+ max_sub_depth: options.maxSubDepth ?? 0,
551
+ activation: options.activation,
552
+ delegate_signature: delegateSignature,
553
+ timestamp,
554
+ });
555
+ }
556
+ /**
557
+ * Revoke a delegation grant (cascading to all sub-grants).
558
+ */
559
+ async revoke(delegationId) {
560
+ const proof = await this.signOwnershipProof('revoke');
561
+ if (!proof) {
562
+ throw new errors_1.Sequence0Error('ownerSigner is required to revoke delegation grants');
563
+ }
564
+ await this.http.post(`/delegations/${delegationId}/revoke`, {
565
+ owner_signature: proof.owner_signature,
566
+ timestamp: proof.timestamp,
567
+ });
568
+ }
569
+ /**
570
+ * List all delegation grants for this wallet.
571
+ */
572
+ async listDelegations() {
573
+ const res = await this.http.get(`/delegations?wallet_id=${encodeURIComponent(this.walletId)}`);
574
+ return res.delegations;
575
+ }
576
+ /**
577
+ * Get the delegation tree for this wallet.
578
+ */
579
+ async getDelegationTree() {
580
+ return this.http.get(`/delegations/tree?wallet_id=${encodeURIComponent(this.walletId)}`);
581
+ }
582
+ /**
583
+ * Send heartbeat for dead-man's switch delegation grants.
584
+ */
585
+ async heartbeat() {
586
+ const proof = await this.signOwnershipProof('heartbeat');
587
+ if (!proof) {
588
+ throw new errors_1.Sequence0Error('ownerSigner is required for heartbeat');
589
+ }
590
+ await this.http.post('/delegations/heartbeat', {
591
+ wallet_id: this.walletId,
592
+ owner_signature: proof.owner_signature,
593
+ timestamp: proof.timestamp,
594
+ });
595
+ }
392
596
  }
393
597
  exports.Wallet = Wallet;
394
598
  Wallet.EVM_CHAINS = [