@keelcodes/sdk 0.0.0-stage → 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.
@@ -0,0 +1,490 @@
1
+ import { HttpClient } from './http';
2
+ export type WalletType = 'waas' | 'mpc' | 'safe' | 'aa';
3
+ export interface CreateWalletParams {
4
+ type: WalletType;
5
+ chain?: string;
6
+ /** 幂等键(同 reference 不重复建钱包)。 */
7
+ reference?: string;
8
+ }
9
+ export interface ImportWalletParams {
10
+ type: WalletType;
11
+ seed?: string;
12
+ privateKey?: string;
13
+ }
14
+ export interface WalletCreated {
15
+ walletId: string;
16
+ address: string;
17
+ }
18
+ export interface SignParams {
19
+ walletId: string;
20
+ message?: string;
21
+ typedData?: Record<string, unknown>;
22
+ digest?: string;
23
+ chain?: string;
24
+ }
25
+ export interface SignResult {
26
+ signature: string;
27
+ address: string;
28
+ }
29
+ export interface SendParams {
30
+ walletId: string;
31
+ to: string;
32
+ amount: string;
33
+ chain: string;
34
+ tokenAddress?: string;
35
+ /** 幂等键(防重复转账)。 */
36
+ reference?: string;
37
+ }
38
+ export interface SendResult {
39
+ txHash: string;
40
+ status: string;
41
+ }
42
+ export interface ChainParams {
43
+ chain: string;
44
+ method: string;
45
+ params?: unknown[];
46
+ rawTransaction?: string;
47
+ }
48
+ export interface ChainResult {
49
+ result?: unknown;
50
+ txHash?: string;
51
+ }
52
+ export interface WalletBalanceParams {
53
+ address: string;
54
+ chain?: string;
55
+ token?: string;
56
+ }
57
+ export interface WalletChainBalance {
58
+ chain: string;
59
+ address: string;
60
+ balances: Array<{
61
+ token: string;
62
+ token_address: string;
63
+ /** 人类可读金额:EVM 为原生币小数(18 位),Solana 为 SOL 小数(9 位) */
64
+ balance: string;
65
+ /** 仅 Solana:原始 lamports(十进制字符串) */
66
+ balance_lamports?: string;
67
+ usd_value: string;
68
+ }>;
69
+ usdTotal: string;
70
+ error?: string;
71
+ }
72
+ export interface WalletBalanceResult {
73
+ chainBalances: WalletChainBalance[];
74
+ totalUsd: string;
75
+ }
76
+ export interface SolanaDeriveAccountParams {
77
+ chain: string;
78
+ accountIndex: string | number;
79
+ smartAccountIndex?: string | number;
80
+ }
81
+ export interface SolanaDerivedAccount {
82
+ chain: string;
83
+ accountIndex: string;
84
+ smartAccountIndex: number;
85
+ settingsPda: string;
86
+ smartAccountPda: string;
87
+ }
88
+ export interface SolanaCreateAccountParams {
89
+ chain: string;
90
+ blockhash: string;
91
+ treasury: string;
92
+ creator: string;
93
+ settingsPda: string;
94
+ signers: Array<Record<string, unknown>>;
95
+ settingsAuthority?: string;
96
+ threshold?: number;
97
+ timeLock?: number;
98
+ rentCollector?: string;
99
+ memo?: string;
100
+ }
101
+ export interface SolanaInstallPolicyParams {
102
+ chain: string;
103
+ blockhash: string;
104
+ feePayer: string;
105
+ creator: string;
106
+ settingsPda: string;
107
+ transactionIndex: string | number;
108
+ signer: Record<string, unknown>;
109
+ /** 旧口径 `SettingsAction::AddSpendingLimit`(已 deprecated) */
110
+ spendingLimit?: Record<string, unknown>;
111
+ /** 新口径 `SettingsAction::PolicyCreate`(spending limit policy) */
112
+ spendingLimitPolicy?: SolanaSpendingLimitPolicy;
113
+ }
114
+ /** 新口径 spending limit policy(`PolicyCreate`;金额/seed 为十进制整数,可用字符串)。 */
115
+ export interface SolanaSpendingLimitPolicy {
116
+ seed: string | number;
117
+ mint: string;
118
+ sourceAccountIndex?: number;
119
+ amount: string | number;
120
+ maxPerUse?: string | number;
121
+ /** 旧 `Period` 枚举值(0=OneTime / 1=Day / 2=Week / 3=Month) */
122
+ period?: number;
123
+ start?: string | number;
124
+ expiration?: string | number;
125
+ accumulateUnused?: boolean;
126
+ enforceExactQuantity?: boolean;
127
+ destinations?: string[];
128
+ signers: Array<Record<string, unknown>>;
129
+ threshold?: number;
130
+ timeLock?: number;
131
+ }
132
+ export interface SolanaCreatePolicyTransactionParams {
133
+ chain: string;
134
+ blockhash: string;
135
+ feePayer: string;
136
+ /** policy PDA */
137
+ policy: string;
138
+ transactionIndex: string | number;
139
+ creator: string;
140
+ rentPayer?: string;
141
+ accountIndex?: number;
142
+ amount: string | number;
143
+ destination: string;
144
+ decimals: number;
145
+ }
146
+ export interface SolanaCreateProposalParams {
147
+ chain: string;
148
+ blockhash: string;
149
+ feePayer: string;
150
+ /** 共识账户:settings PDA(settings 交易)或 policy PDA(policy 交易) */
151
+ settingsPda: string;
152
+ transactionIndex: string | number;
153
+ creator: string;
154
+ rentPayer?: string;
155
+ isDraft?: boolean;
156
+ }
157
+ export interface SolanaApproveProposalParams {
158
+ chain: string;
159
+ blockhash: string;
160
+ feePayer: string;
161
+ /** 共识账户:settings PDA(settings 交易)或 policy PDA(policy 交易) */
162
+ settingsPda: string;
163
+ transactionIndex: string | number;
164
+ signer: string;
165
+ memo?: string;
166
+ }
167
+ export interface SolanaExecutePolicyTransactionParams {
168
+ chain: string;
169
+ blockhash: string;
170
+ feePayer: string;
171
+ /** policy PDA */
172
+ policy: string;
173
+ transactionIndex: string | number;
174
+ signer: string;
175
+ /** 策略执行所需的剩余账户(native SOL: [source, destination, systemProgram]) */
176
+ anchorRemainingAccounts: Array<{
177
+ pubkey: string;
178
+ isWritable?: boolean;
179
+ isSigner?: boolean;
180
+ }>;
181
+ }
182
+ export interface SolanaRemovePolicyParams {
183
+ chain: string;
184
+ blockhash: string;
185
+ feePayer: string;
186
+ creator: string;
187
+ settingsPda: string;
188
+ transactionIndex: string | number;
189
+ /** 待删除的 policy PDA(同时需在 execute 时作为 remaining account 传入) */
190
+ policy: string;
191
+ rentPayer?: string;
192
+ memo?: string;
193
+ }
194
+ export interface SolanaCloseTransactionParams {
195
+ chain: string;
196
+ blockhash: string;
197
+ feePayer: string;
198
+ /** 共识账户:policy PDA(policy 交易)或 settings PDA(settings 交易) */
199
+ settingsPda: string;
200
+ transactionIndex: string | number;
201
+ /** transaction 账户 rent 回收地址;缺省 feePayer */
202
+ transactionRentCollector?: string;
203
+ /** proposal 账户 rent 回收地址;缺省 transactionRentCollector */
204
+ proposalRentCollector?: string;
205
+ }
206
+ export interface SolanaExecutePolicyPayloadParams {
207
+ chain: string;
208
+ blockhash: string;
209
+ feePayer: string;
210
+ /** policy PDA */
211
+ policy: string;
212
+ accountIndex?: number;
213
+ numSigners: number;
214
+ amount: string | number;
215
+ destination: string;
216
+ decimals: number;
217
+ instructionAccounts: Array<{
218
+ pubkey: string;
219
+ isWritable?: boolean;
220
+ isSigner?: boolean;
221
+ }>;
222
+ }
223
+ export interface SolanaCloseSettingsParams {
224
+ chain: string;
225
+ blockhash: string;
226
+ feePayer: string;
227
+ settingsPda: string;
228
+ transactionIndex: string | number;
229
+ transactionRentCollector?: string;
230
+ proposalRentCollector?: string;
231
+ }
232
+ export interface SolanaExecutePolicyParams {
233
+ chain: string;
234
+ blockhash: string;
235
+ feePayer: string;
236
+ settingsPda: string;
237
+ transactionIndex: string | number;
238
+ signer: string;
239
+ rentPayer?: string;
240
+ spendingLimits?: Array<Record<string, unknown>>;
241
+ /** `PolicyCreate` / `PolicyRemove` 的 policy PDA 列表(remaining accounts) */
242
+ policies?: string[];
243
+ }
244
+ export interface SolanaExecuteParams {
245
+ chain: string;
246
+ blockhash: string;
247
+ feePayer: string;
248
+ settingsPda: string;
249
+ signer: string;
250
+ spendingLimit: string;
251
+ mint?: string;
252
+ accountIndex: number;
253
+ amount: string | number;
254
+ decimals: number;
255
+ destination: string;
256
+ tokenProgram?: string;
257
+ memo?: string;
258
+ }
259
+ export interface SolanaRemoveSignerParams {
260
+ chain: string;
261
+ blockhash: string;
262
+ feePayer: string;
263
+ settingsPda: string;
264
+ settingsAuthority: string;
265
+ oldSigner: string;
266
+ memo?: string;
267
+ }
268
+ export interface SolanaSubmitParams {
269
+ chain: string;
270
+ transaction: string;
271
+ }
272
+ /** 构建端点返回的未签名交易(base64)。 */
273
+ export interface SolanaUnsignedTransaction {
274
+ chain: string;
275
+ transaction: string;
276
+ feePayer?: string;
277
+ instructionCount?: number;
278
+ }
279
+ export interface SolanaSubmitResult {
280
+ chain: string;
281
+ signature: string;
282
+ feePayer?: string;
283
+ }
284
+ export interface MpcSendCodeParams {
285
+ email: string;
286
+ }
287
+ export interface MpcVerifyParams {
288
+ email: string;
289
+ code: string;
290
+ }
291
+ export interface MpcBalanceParams {
292
+ token: string;
293
+ chain?: string;
294
+ tokenAddress?: string;
295
+ }
296
+ export interface MpcSignMessageParams {
297
+ token: string;
298
+ message: string;
299
+ }
300
+ export interface MpcSignTypedDataParams {
301
+ token: string;
302
+ domain: Record<string, unknown>;
303
+ types: Record<string, unknown>;
304
+ value: Record<string, unknown>;
305
+ }
306
+ export interface MpcSendTransactionParams {
307
+ token: string;
308
+ to: string;
309
+ amount: string;
310
+ chain?: string;
311
+ tokenAddress?: string;
312
+ }
313
+ export interface MpcContractCallParams {
314
+ contractAddress: string;
315
+ abi: unknown[];
316
+ method: string;
317
+ args?: unknown[];
318
+ chain?: string;
319
+ }
320
+ export interface MpcContractWriteParams extends MpcContractCallParams {
321
+ token: string;
322
+ value?: string;
323
+ gasLimit?: string;
324
+ }
325
+ export interface MpcGasEstimateParams {
326
+ to?: string;
327
+ value?: string;
328
+ data?: string;
329
+ chain?: string;
330
+ }
331
+ export declare class WalletAPI {
332
+ private http;
333
+ constructor(http: HttpClient);
334
+ create(params: CreateWalletParams): Promise<WalletCreated>;
335
+ import(params: ImportWalletParams): Promise<WalletCreated>;
336
+ sign(params: SignParams): Promise<SignResult>;
337
+ send(params: SendParams): Promise<SendResult>;
338
+ /** 预估交易 gas(不耗资金)。 */
339
+ estimateGas(params: {
340
+ walletId: string;
341
+ toAddress: string;
342
+ amount: string;
343
+ chain: string;
344
+ tokenAddress?: string;
345
+ }): Promise<Record<string, unknown>>;
346
+ /** 清空钱包原生余额到指定地址(sweep)。 */
347
+ sweep(params: {
348
+ walletId: string;
349
+ toAddress: string;
350
+ chain: string;
351
+ paymentPassword: string;
352
+ }): Promise<Record<string, unknown>>;
353
+ /** 按 txHash 查交易状态(链上回执)。 */
354
+ txStatus(txHash: string): Promise<Record<string, unknown>>;
355
+ /** 链上读写(读 + 广播统一,走 chain-rpc 聚合层)。 */
356
+ chain(params: ChainParams): Promise<ChainResult>;
357
+ balance(params: WalletBalanceParams): Promise<WalletBalanceResult>;
358
+ /** Chain-RPC 子域:池状态 / 读套餐订阅面(canonical `/v1/wallet/chain/*`)。 */
359
+ chainRpc: {
360
+ /** chain-rpc 网关池状态(各链健康 / 活跃端点,脱敏)。 */
361
+ status: () => Promise<unknown>;
362
+ /** chain-rpc 网关健康检查。 */
363
+ health: () => Promise<unknown>;
364
+ /** RPC 读套餐订阅面。 */
365
+ subscription: {
366
+ /** 套餐目录 + 完整链表(公开,无需 key)。 */
367
+ plans: () => Promise<unknown>;
368
+ /** 发起订阅支付(rx_ key 鉴权):免费即时激活,付费返回支付意图。 */
369
+ checkout: (p: {
370
+ rpcKey: string;
371
+ planId: string;
372
+ rail?: string;
373
+ subscriber?: string;
374
+ }) => Promise<unknown>;
375
+ /** 轮询订阅支付状态(chain rail 链上确认)。 */
376
+ paymentCheck: (p: {
377
+ rpcKey: string;
378
+ subscriber?: string;
379
+ }) => Promise<unknown>;
380
+ /** 确认 x402 rail 支付(提交 base64 PAYMENT-SIGNATURE)以激活订阅。 */
381
+ verify: (p: {
382
+ rpcKey: string;
383
+ paymentSignature: string;
384
+ }) => Promise<unknown>;
385
+ /** 查询订阅用量(套餐 / 月配额 / 当前用量 / 日聚合)。 */
386
+ usage: (rpcKey: string) => Promise<unknown>;
387
+ };
388
+ };
389
+ safe: {
390
+ /** Vault 概览:Safe 总数 / 待签 / 启用风控规则数。 */
391
+ dashboard: () => Promise<unknown>;
392
+ /** 列出多签 Safe(按 userId 过滤)。 */
393
+ list: (userId?: string) => Promise<unknown>;
394
+ /** 单个 Safe 详情(含交易历史)。 */
395
+ info: (address: string) => Promise<unknown>;
396
+ /** 创建并链上部署多签 Safe。 */
397
+ create: (p: {
398
+ chainId: string;
399
+ owners: string[];
400
+ threshold: number;
401
+ name?: string;
402
+ userId?: string;
403
+ }) => Promise<unknown>;
404
+ propose: (p: {
405
+ safeAddress: string;
406
+ to: string;
407
+ value?: string;
408
+ data?: string;
409
+ }) => Promise<unknown>;
410
+ confirm: (p: {
411
+ safeAddress: string;
412
+ safeTxHash: string;
413
+ signature: string;
414
+ }) => Promise<unknown>;
415
+ execute: (p: {
416
+ safeTxHash: string;
417
+ }) => Promise<unknown>;
418
+ /** 更新 owner 集合与阈值(走链上多签提案)。 */
419
+ updateOwners: (address: string, p: {
420
+ owners: string[];
421
+ threshold: number;
422
+ signature?: string;
423
+ userId?: string;
424
+ }) => Promise<unknown>;
425
+ /** 重试待部署 Safe(可按 chainId)。 */
426
+ retry: (chainId?: string) => Promise<unknown>;
427
+ /** 执行所有已达阈值的交易。 */
428
+ executeReady: (safeAddress?: string) => Promise<unknown>;
429
+ /** 同步 Safe 链上状态到库。 */
430
+ sync: (safeAddress: string) => Promise<unknown>;
431
+ /** Safe 状态(enabled / count)。 */
432
+ status: (walletAddress?: string) => Promise<unknown>;
433
+ /** 风控检查(按链规则判定单笔是否超限)。 */
434
+ riskCheck: (p: {
435
+ amount: string;
436
+ chain: string;
437
+ }) => Promise<unknown>;
438
+ };
439
+ session: {
440
+ create: (p: Record<string, unknown>) => Promise<unknown>;
441
+ revoke: (sessionId: string) => Promise<unknown>;
442
+ execute: (p: Record<string, unknown>) => Promise<unknown>;
443
+ /** Solana(Squads Smart Account):构建未签名交易 + 广播已签名交易。 */
444
+ solana: {
445
+ deriveAccount: (p: SolanaDeriveAccountParams) => Promise<SolanaDerivedAccount>;
446
+ createAccount: (p: SolanaCreateAccountParams) => Promise<SolanaUnsignedTransaction>;
447
+ installPolicy: (p: SolanaInstallPolicyParams) => Promise<SolanaUnsignedTransaction>;
448
+ executePolicy: (p: SolanaExecutePolicyParams) => Promise<SolanaUnsignedTransaction>;
449
+ /** 新口径:创建 spending limit policy 交易(待多签审批)。 */
450
+ createPolicyTransaction: (p: SolanaCreatePolicyTransactionParams) => Promise<SolanaUnsignedTransaction>;
451
+ /** settings / policy 交易提案:创建。 */
452
+ createProposal: (p: SolanaCreateProposalParams) => Promise<SolanaUnsignedTransaction>;
453
+ /** settings / policy 交易提案:审批(threshold 达成即 Approved)。 */
454
+ approveProposal: (p: SolanaApproveProposalParams) => Promise<SolanaUnsignedTransaction>;
455
+ /** 新口径:异步执行已批准的 policy 交易。 */
456
+ executePolicyTransaction: (p: SolanaExecutePolicyTransactionParams) => Promise<SolanaUnsignedTransaction>;
457
+ /** 新口径:删除 policy(PolicyRemove)并回收其 rent。 */
458
+ removePolicy: (p: SolanaRemovePolicyParams) => Promise<SolanaUnsignedTransaction>;
459
+ /** 新口径:同步执行 spending limit policy。 */
460
+ executePolicyPayload: (p: SolanaExecutePolicyPayloadParams) => Promise<SolanaUnsignedTransaction>;
461
+ /** 关闭废弃 settings 交易并回收 rent。 */
462
+ closeSettings: (p: SolanaCloseSettingsParams) => Promise<SolanaUnsignedTransaction>;
463
+ /** 关闭 policy 交易并回收 transaction/proposal rent。 */
464
+ closeTransaction: (p: SolanaCloseTransactionParams) => Promise<SolanaUnsignedTransaction>;
465
+ execute: (p: SolanaExecuteParams) => Promise<SolanaUnsignedTransaction>;
466
+ removeSigner: (p: SolanaRemoveSignerParams) => Promise<SolanaUnsignedTransaction>;
467
+ submit: (p: SolanaSubmitParams) => Promise<SolanaSubmitResult>;
468
+ };
469
+ };
470
+ /** MPC(email 分片钱包)子域:canonical `/v1/wallet/mpc/*`。 */
471
+ mpc: {
472
+ sendCode: (p: MpcSendCodeParams) => Promise<unknown>;
473
+ register: (p: MpcVerifyParams) => Promise<unknown>;
474
+ recover: (p: MpcVerifyParams) => Promise<unknown>;
475
+ status: (email: string) => Promise<unknown>;
476
+ wallets: (email?: string) => Promise<unknown>;
477
+ sessionUnlock: (p: MpcVerifyParams) => Promise<unknown>;
478
+ sessionLock: (p: {
479
+ token: string;
480
+ }) => Promise<unknown>;
481
+ sessionStatus: (token: string) => Promise<unknown>;
482
+ balance: (p: MpcBalanceParams) => Promise<unknown>;
483
+ signMessage: (p: MpcSignMessageParams) => Promise<unknown>;
484
+ signTypedData: (p: MpcSignTypedDataParams) => Promise<unknown>;
485
+ sendTransaction: (p: MpcSendTransactionParams) => Promise<unknown>;
486
+ contractRead: (p: MpcContractCallParams) => Promise<unknown>;
487
+ contractWrite: (p: MpcContractWriteParams) => Promise<unknown>;
488
+ gasEstimate: (p: MpcGasEstimateParams) => Promise<unknown>;
489
+ };
490
+ }
package/dist/wallet.js ADDED
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // @keelcodes/sdk — wallet 模块
4
+ // ---------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WalletAPI = void 0;
7
+ class WalletAPI {
8
+ constructor(http) {
9
+ this.http = http;
10
+ /** Chain-RPC 子域:池状态 / 读套餐订阅面(canonical `/v1/wallet/chain/*`)。 */
11
+ this.chainRpc = {
12
+ /** chain-rpc 网关池状态(各链健康 / 活跃端点,脱敏)。 */
13
+ status: () => this.http.get('/v1/wallet/chain/status'),
14
+ /** chain-rpc 网关健康检查。 */
15
+ health: () => this.http.get('/v1/wallet/chain/health'),
16
+ /** RPC 读套餐订阅面。 */
17
+ subscription: {
18
+ /** 套餐目录 + 完整链表(公开,无需 key)。 */
19
+ plans: () => this.http.get('/v1/wallet/chain/subscription/plans'),
20
+ /** 发起订阅支付(rx_ key 鉴权):免费即时激活,付费返回支付意图。 */
21
+ checkout: (p) => this.http.post('/v1/wallet/chain/subscription/checkout', { plan_id: p.planId, rail: p.rail, subscriber: p.subscriber }, { 'x-rpc-key': p.rpcKey }),
22
+ /** 轮询订阅支付状态(chain rail 链上确认)。 */
23
+ paymentCheck: (p) => this.http.post('/v1/wallet/chain/subscription/payment-check', { subscriber: p.subscriber }, { 'x-rpc-key': p.rpcKey }),
24
+ /** 确认 x402 rail 支付(提交 base64 PAYMENT-SIGNATURE)以激活订阅。 */
25
+ verify: (p) => this.http.post('/v1/wallet/chain/subscription/verify', { paymentSignature: p.paymentSignature }, { 'x-rpc-key': p.rpcKey }),
26
+ /** 查询订阅用量(套餐 / 月配额 / 当前用量 / 日聚合)。 */
27
+ usage: (rpcKey) => this.http.get('/v1/wallet/chain/subscription/usage', { 'x-rpc-key': rpcKey }),
28
+ },
29
+ };
30
+ this.safe = {
31
+ /** Vault 概览:Safe 总数 / 待签 / 启用风控规则数。 */
32
+ dashboard: () => this.http.get('/v1/wallet/safe/dashboard'),
33
+ /** 列出多签 Safe(按 userId 过滤)。 */
34
+ list: (userId) => this.http.get('/v1/wallet/safe/list' + (userId ? '?userId=' + encodeURIComponent(userId) : '')),
35
+ /** 单个 Safe 详情(含交易历史)。 */
36
+ info: (address) => this.http.get('/v1/wallet/safe/' + encodeURIComponent(address)),
37
+ /** 创建并链上部署多签 Safe。 */
38
+ create: (p) => this.http.post('/v1/wallet/safe/create', p),
39
+ propose: (p) => this.http.post('/v1/wallet/safe/propose', p),
40
+ confirm: (p) => this.http.post('/v1/wallet/safe/confirm', p),
41
+ execute: (p) => this.http.post('/v1/wallet/safe/execute', p),
42
+ /** 更新 owner 集合与阈值(走链上多签提案)。 */
43
+ updateOwners: (address, p) => this.http.put('/v1/wallet/safe/' + encodeURIComponent(address) + '/owners', p),
44
+ /** 重试待部署 Safe(可按 chainId)。 */
45
+ retry: (chainId) => this.http.post('/v1/wallet/safe/retry', { chainId }),
46
+ /** 执行所有已达阈值的交易。 */
47
+ executeReady: (safeAddress) => this.http.post('/v1/wallet/safe/execute-ready', { safeAddress }),
48
+ /** 同步 Safe 链上状态到库。 */
49
+ sync: (safeAddress) => this.http.post('/v1/wallet/safe/sync', { safeAddress }),
50
+ /** Safe 状态(enabled / count)。 */
51
+ status: (walletAddress) => this.http.get('/v1/wallet/safe/status' + (walletAddress ? '?walletAddress=' + encodeURIComponent(walletAddress) : '')),
52
+ /** 风控检查(按链规则判定单笔是否超限)。 */
53
+ riskCheck: (p) => this.http.post('/v1/wallet/safe/risk/check', p),
54
+ };
55
+ this.session = {
56
+ create: (p) => this.http.post('/v1/wallet/session/create', p),
57
+ revoke: (sessionId) => this.http.post('/v1/wallet/session/revoke', { sessionId }),
58
+ execute: (p) => this.http.post('/v1/wallet/session/execute', p),
59
+ /** Solana(Squads Smart Account):构建未签名交易 + 广播已签名交易。 */
60
+ solana: {
61
+ deriveAccount: (p) => this.http.post('/v1/wallet/session/solana/account/derive', p),
62
+ createAccount: (p) => this.http.post('/v1/wallet/session/solana/account/create', p),
63
+ installPolicy: (p) => this.http.post('/v1/wallet/session/solana/session/policy', p),
64
+ executePolicy: (p) => this.http.post('/v1/wallet/session/solana/session/policy/execute', p),
65
+ /** 新口径:创建 spending limit policy 交易(待多签审批)。 */
66
+ createPolicyTransaction: (p) => this.http.post('/v1/wallet/session/solana/session/policy/create-transaction', p),
67
+ /** settings / policy 交易提案:创建。 */
68
+ createProposal: (p) => this.http.post('/v1/wallet/session/solana/session/proposal', p),
69
+ /** settings / policy 交易提案:审批(threshold 达成即 Approved)。 */
70
+ approveProposal: (p) => this.http.post('/v1/wallet/session/solana/session/proposal/approve', p),
71
+ /** 新口径:异步执行已批准的 policy 交易。 */
72
+ executePolicyTransaction: (p) => this.http.post('/v1/wallet/session/solana/session/policy/execute-transaction', p),
73
+ /** 新口径:删除 policy(PolicyRemove)并回收其 rent。 */
74
+ removePolicy: (p) => this.http.post('/v1/wallet/session/solana/session/policy/remove', p),
75
+ /** 新口径:同步执行 spending limit policy。 */
76
+ executePolicyPayload: (p) => this.http.post('/v1/wallet/session/solana/session/policy/execute-payload', p),
77
+ /** 关闭废弃 settings 交易并回收 rent。 */
78
+ closeSettings: (p) => this.http.post('/v1/wallet/session/solana/settings/close', p),
79
+ /** 关闭 policy 交易并回收 transaction/proposal rent。 */
80
+ closeTransaction: (p) => this.http.post('/v1/wallet/session/solana/session/policy/close-transaction', p),
81
+ execute: (p) => this.http.post('/v1/wallet/session/solana/session/execute', p),
82
+ removeSigner: (p) => this.http.post('/v1/wallet/session/solana/session/remove-signer', p),
83
+ submit: (p) => this.http.post('/v1/wallet/session/solana/submit', p),
84
+ },
85
+ };
86
+ /** MPC(email 分片钱包)子域:canonical `/v1/wallet/mpc/*`。 */
87
+ this.mpc = {
88
+ sendCode: (p) => this.http.post('/v1/wallet/mpc/send-code', p),
89
+ register: (p) => this.http.post('/v1/wallet/mpc/register', p),
90
+ recover: (p) => this.http.post('/v1/wallet/mpc/recover', p),
91
+ status: (email) => this.http.get('/v1/wallet/mpc/status?email=' + encodeURIComponent(email)),
92
+ wallets: (email) => this.http.get('/v1/wallet/mpc/wallets' + (email ? '?email=' + encodeURIComponent(email) : '')),
93
+ sessionUnlock: (p) => this.http.post('/v1/wallet/mpc/session/unlock', p),
94
+ sessionLock: (p) => this.http.post('/v1/wallet/mpc/session/lock', p),
95
+ sessionStatus: (token) => this.http.get('/v1/wallet/mpc/session/status?token=' + encodeURIComponent(token)),
96
+ balance: (p) => this.http.post('/v1/wallet/mpc/balance', p),
97
+ signMessage: (p) => this.http.post('/v1/wallet/mpc/sign-message', p),
98
+ signTypedData: (p) => this.http.post('/v1/wallet/mpc/sign-typed-data', p),
99
+ sendTransaction: (p) => this.http.post('/v1/wallet/mpc/send-transaction', p),
100
+ contractRead: (p) => this.http.post('/v1/wallet/mpc/contract-read', p),
101
+ contractWrite: (p) => this.http.post('/v1/wallet/mpc/contract-write', p),
102
+ gasEstimate: (p) => this.http.post('/v1/wallet/mpc/gas-estimate', p),
103
+ };
104
+ }
105
+ create(params) {
106
+ return this.http.post('/v1/wallet/create', params);
107
+ }
108
+ import(params) {
109
+ return this.http.post('/v1/wallet/import', params);
110
+ }
111
+ sign(params) {
112
+ return this.http.post('/v1/wallet/sign', params);
113
+ }
114
+ send(params) {
115
+ return this.http.post('/v1/wallet/send', params);
116
+ }
117
+ /** 预估交易 gas(不耗资金)。 */
118
+ estimateGas(params) {
119
+ return this.http.post('/v1/wallet/estimate-gas', params);
120
+ }
121
+ /** 清空钱包原生余额到指定地址(sweep)。 */
122
+ sweep(params) {
123
+ return this.http.post('/v1/wallet/sweep', params);
124
+ }
125
+ /** 按 txHash 查交易状态(链上回执)。 */
126
+ txStatus(txHash) {
127
+ return this.http.get('/v1/wallet/status/' + encodeURIComponent(txHash));
128
+ }
129
+ /** 链上读写(读 + 广播统一,走 chain-rpc 聚合层)。 */
130
+ chain(params) {
131
+ return this.http.post('/v1/wallet/chain', params);
132
+ }
133
+ balance(params) {
134
+ const q = new URLSearchParams({ address: params.address });
135
+ if (params.chain)
136
+ q.set('chain', params.chain);
137
+ if (params.token)
138
+ q.set('token', params.token);
139
+ return this.http.get('/v1/wallet/balance?' + q.toString());
140
+ }
141
+ }
142
+ exports.WalletAPI = WalletAPI;
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@keelcodes/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "Keel SDK — unified access to payment / wallet / data / account modules over https://keel.codes",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./payment": {
13
+ "types": "./dist/payment.d.ts",
14
+ "default": "./dist/payment.js"
15
+ },
16
+ "./wallet": {
17
+ "types": "./dist/wallet.d.ts",
18
+ "default": "./dist/wallet.js"
19
+ },
20
+ "./data": {
21
+ "types": "./dist/data.d.ts",
22
+ "default": "./dist/data.js"
23
+ },
24
+ "./account": {
25
+ "types": "./dist/account.d.ts",
26
+ "default": "./dist/account.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "keywords": [
43
+ "keel",
44
+ "payment",
45
+ "wallet",
46
+ "data",
47
+ "account",
48
+ "sdk"
49
+ ],
50
+ "license": "MIT",
51
+ "author": "Keel",
52
+ "devDependencies": {
53
+ "typescript": "^5.0.0"
54
+ }
55
+ }