@rebelfi/agent-sdk 1.0.1
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 +337 -0
- package/dist/amount-utils.d.ts +9 -0
- package/dist/amount-utils.js +80 -0
- package/dist/amount-utils.js.map +1 -0
- package/dist/cjs/amount-utils.js +87 -0
- package/dist/cjs/amount-utils.js.map +1 -0
- package/dist/cjs/cli.js +189 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/client.js +49 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/commands/account.js +250 -0
- package/dist/cjs/commands/account.js.map +1 -0
- package/dist/cjs/commands/auth.js +78 -0
- package/dist/cjs/commands/auth.js.map +1 -0
- package/dist/cjs/commands/balance.js +15 -0
- package/dist/cjs/commands/balance.js.map +1 -0
- package/dist/cjs/commands/cancel.js +34 -0
- package/dist/cjs/commands/cancel.js.map +1 -0
- package/dist/cjs/commands/chat.js +15 -0
- package/dist/cjs/commands/chat.js.map +1 -0
- package/dist/cjs/commands/claim.js +34 -0
- package/dist/cjs/commands/claim.js.map +1 -0
- package/dist/cjs/commands/config.js +29 -0
- package/dist/cjs/commands/config.js.map +1 -0
- package/dist/cjs/commands/contacts.js +29 -0
- package/dist/cjs/commands/contacts.js.map +1 -0
- package/dist/cjs/commands/init.js +43 -0
- package/dist/cjs/commands/init.js.map +1 -0
- package/dist/cjs/commands/orders.js +167 -0
- package/dist/cjs/commands/orders.js.map +1 -0
- package/dist/cjs/commands/pay.js +41 -0
- package/dist/cjs/commands/pay.js.map +1 -0
- package/dist/cjs/commands/payments.js +27 -0
- package/dist/cjs/commands/payments.js.map +1 -0
- package/dist/cjs/commands/wallet.js +69 -0
- package/dist/cjs/commands/wallet.js.map +1 -0
- package/dist/cjs/config.js +91 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/contacts.js +87 -0
- package/dist/cjs/contacts.js.map +1 -0
- package/dist/cjs/errors.js +93 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +64 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intent/chains.js +29 -0
- package/dist/cjs/intent/chains.js.map +1 -0
- package/dist/cjs/intent/constraints.js +46 -0
- package/dist/cjs/intent/constraints.js.map +1 -0
- package/dist/cjs/intent/helpers.js +34 -0
- package/dist/cjs/intent/helpers.js.map +1 -0
- package/dist/cjs/intent/index.js +99 -0
- package/dist/cjs/intent/index.js.map +1 -0
- package/dist/cjs/intent/matcher.js +119 -0
- package/dist/cjs/intent/matcher.js.map +1 -0
- package/dist/cjs/intent/program-registry.js +68 -0
- package/dist/cjs/intent/program-registry.js.map +1 -0
- package/dist/cjs/intent/token-registry.js +99 -0
- package/dist/cjs/intent/token-registry.js.map +1 -0
- package/dist/cjs/intent/types.js +3 -0
- package/dist/cjs/intent/types.js.map +1 -0
- package/dist/cjs/orders/evaluate.js +168 -0
- package/dist/cjs/orders/evaluate.js.map +1 -0
- package/dist/cjs/orders/index.js +14 -0
- package/dist/cjs/orders/index.js.map +1 -0
- package/dist/cjs/orders/store.js +47 -0
- package/dist/cjs/orders/store.js.map +1 -0
- package/dist/cjs/orders/sugar.js +35 -0
- package/dist/cjs/orders/sugar.js.map +1 -0
- package/dist/cjs/orders/types.js +3 -0
- package/dist/cjs/orders/types.js.map +1 -0
- package/dist/cjs/output.js +47 -0
- package/dist/cjs/output.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transfers.js +15 -0
- package/dist/cjs/transfers.js.map +1 -0
- package/dist/cjs/validate.js +77 -0
- package/dist/cjs/validate.js.map +1 -0
- package/dist/cjs/verify/decoders/ata.js +19 -0
- package/dist/cjs/verify/decoders/ata.js.map +1 -0
- package/dist/cjs/verify/decoders/compute-budget.js +32 -0
- package/dist/cjs/verify/decoders/compute-budget.js.map +1 -0
- package/dist/cjs/verify/decoders/handshake.js +180 -0
- package/dist/cjs/verify/decoders/handshake.js.map +1 -0
- package/dist/cjs/verify/decoders/jupiter.js +39 -0
- package/dist/cjs/verify/decoders/jupiter.js.map +1 -0
- package/dist/cjs/verify/decoders/memo.js +12 -0
- package/dist/cjs/verify/decoders/memo.js.map +1 -0
- package/dist/cjs/verify/decoders/silkysig.js +162 -0
- package/dist/cjs/verify/decoders/silkysig.js.map +1 -0
- package/dist/cjs/verify/decoders/spl-token.js +125 -0
- package/dist/cjs/verify/decoders/spl-token.js.map +1 -0
- package/dist/cjs/verify/decoders/system.js +87 -0
- package/dist/cjs/verify/decoders/system.js.map +1 -0
- package/dist/cjs/verify/flags.js +87 -0
- package/dist/cjs/verify/flags.js.map +1 -0
- package/dist/cjs/verify/index.js +384 -0
- package/dist/cjs/verify/index.js.map +1 -0
- package/dist/cjs/verify/registry.js +24 -0
- package/dist/cjs/verify/registry.js.map +1 -0
- package/dist/cjs/verify/rpc.js +52 -0
- package/dist/cjs/verify/rpc.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +224 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +43 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/account.d.ts +21 -0
- package/dist/commands/account.js +239 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +70 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/balance.d.ts +3 -0
- package/dist/commands/balance.js +12 -0
- package/dist/commands/balance.js.map +1 -0
- package/dist/commands/cancel.d.ts +3 -0
- package/dist/commands/cancel.js +28 -0
- package/dist/commands/cancel.js.map +1 -0
- package/dist/commands/chat.d.ts +1 -0
- package/dist/commands/chat.js +12 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/claim.d.ts +3 -0
- package/dist/commands/claim.js +28 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.js +24 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/contacts.d.ts +4 -0
- package/dist/commands/contacts.js +23 -0
- package/dist/commands/contacts.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +37 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/orders.d.ts +19 -0
- package/dist/commands/orders.js +157 -0
- package/dist/commands/orders.js.map +1 -0
- package/dist/commands/pay.d.ts +4 -0
- package/dist/commands/pay.js +35 -0
- package/dist/commands/pay.js.map +1 -0
- package/dist/commands/payments.d.ts +4 -0
- package/dist/commands/payments.js +23 -0
- package/dist/commands/payments.js.map +1 -0
- package/dist/commands/wallet.d.ts +7 -0
- package/dist/commands/wallet.js +61 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.js +74 -0
- package/dist/config.js.map +1 -0
- package/dist/contacts.d.ts +15 -0
- package/dist/contacts.js +74 -0
- package/dist/contacts.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +87 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/intent/chains.d.ts +7 -0
- package/dist/intent/chains.js +24 -0
- package/dist/intent/chains.js.map +1 -0
- package/dist/intent/constraints.d.ts +8 -0
- package/dist/intent/constraints.js +43 -0
- package/dist/intent/constraints.js.map +1 -0
- package/dist/intent/helpers.d.ts +6 -0
- package/dist/intent/helpers.js +27 -0
- package/dist/intent/helpers.js.map +1 -0
- package/dist/intent/index.d.ts +11 -0
- package/dist/intent/index.js +87 -0
- package/dist/intent/index.js.map +1 -0
- package/dist/intent/matcher.d.ts +8 -0
- package/dist/intent/matcher.js +116 -0
- package/dist/intent/matcher.js.map +1 -0
- package/dist/intent/program-registry.d.ts +13 -0
- package/dist/intent/program-registry.js +65 -0
- package/dist/intent/program-registry.js.map +1 -0
- package/dist/intent/token-registry.d.ts +17 -0
- package/dist/intent/token-registry.js +96 -0
- package/dist/intent/token-registry.js.map +1 -0
- package/dist/intent/types.d.ts +89 -0
- package/dist/intent/types.js +2 -0
- package/dist/intent/types.js.map +1 -0
- package/dist/orders/evaluate.d.ts +28 -0
- package/dist/orders/evaluate.js +165 -0
- package/dist/orders/evaluate.js.map +1 -0
- package/dist/orders/index.d.ts +7 -0
- package/dist/orders/index.js +4 -0
- package/dist/orders/index.js.map +1 -0
- package/dist/orders/store.d.ts +9 -0
- package/dist/orders/store.js +37 -0
- package/dist/orders/store.js.map +1 -0
- package/dist/orders/sugar.d.ts +13 -0
- package/dist/orders/sugar.js +32 -0
- package/dist/orders/sugar.js.map +1 -0
- package/dist/orders/types.d.ts +37 -0
- package/dist/orders/types.js +2 -0
- package/dist/orders/types.js.map +1 -0
- package/dist/output.d.ts +4 -0
- package/dist/output.js +42 -0
- package/dist/output.js.map +1 -0
- package/dist/transfers.d.ts +32 -0
- package/dist/transfers.js +12 -0
- package/dist/transfers.js.map +1 -0
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +69 -0
- package/dist/validate.js.map +1 -0
- package/dist/verify/decoders/ata.d.ts +5 -0
- package/dist/verify/decoders/ata.js +16 -0
- package/dist/verify/decoders/ata.js.map +1 -0
- package/dist/verify/decoders/compute-budget.d.ts +5 -0
- package/dist/verify/decoders/compute-budget.js +29 -0
- package/dist/verify/decoders/compute-budget.js.map +1 -0
- package/dist/verify/decoders/handshake.d.ts +5 -0
- package/dist/verify/decoders/handshake.js +177 -0
- package/dist/verify/decoders/handshake.js.map +1 -0
- package/dist/verify/decoders/jupiter.d.ts +5 -0
- package/dist/verify/decoders/jupiter.js +36 -0
- package/dist/verify/decoders/jupiter.js.map +1 -0
- package/dist/verify/decoders/memo.d.ts +5 -0
- package/dist/verify/decoders/memo.js +9 -0
- package/dist/verify/decoders/memo.js.map +1 -0
- package/dist/verify/decoders/silkysig.d.ts +5 -0
- package/dist/verify/decoders/silkysig.js +159 -0
- package/dist/verify/decoders/silkysig.js.map +1 -0
- package/dist/verify/decoders/spl-token.d.ts +5 -0
- package/dist/verify/decoders/spl-token.js +122 -0
- package/dist/verify/decoders/spl-token.js.map +1 -0
- package/dist/verify/decoders/system.d.ts +5 -0
- package/dist/verify/decoders/system.js +84 -0
- package/dist/verify/decoders/system.js.map +1 -0
- package/dist/verify/flags.d.ts +3 -0
- package/dist/verify/flags.js +83 -0
- package/dist/verify/flags.js.map +1 -0
- package/dist/verify/index.d.ts +75 -0
- package/dist/verify/index.js +380 -0
- package/dist/verify/index.js.map +1 -0
- package/dist/verify/registry.d.ts +13 -0
- package/dist/verify/registry.js +21 -0
- package/dist/verify/registry.js.map +1 -0
- package/dist/verify/rpc.d.ts +14 -0
- package/dist/verify/rpc.js +48 -0
- package/dist/verify/rpc.js.map +1 -0
- package/package.json +85 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { walletCreate, walletList, walletFund } from './commands/wallet.js';
|
|
5
|
+
import { authRegister, authStatus, authRevoke } from './commands/auth.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const { version } = require('../package.json');
|
|
8
|
+
import { balance } from './commands/balance.js';
|
|
9
|
+
import { pay } from './commands/pay.js';
|
|
10
|
+
import { claim } from './commands/claim.js';
|
|
11
|
+
import { cancel } from './commands/cancel.js';
|
|
12
|
+
import { paymentsList, paymentsGet } from './commands/payments.js';
|
|
13
|
+
import { configSetCluster, configGetCluster, configResetCluster } from './commands/config.js';
|
|
14
|
+
import { accountSync, accountStatus, accountEvents, accountDeposit, accountWithdraw, accountSend } from './commands/account.js';
|
|
15
|
+
import { contactsAdd, contactsRemove, contactsList, contactsGet } from './commands/contacts.js';
|
|
16
|
+
import { chat } from './commands/chat.js';
|
|
17
|
+
import { init } from './commands/init.js';
|
|
18
|
+
import { ordersCreate, ordersList, ordersGet, ordersCancel, ordersEvaluate } from './commands/orders.js';
|
|
19
|
+
import { wrapCommand } from './output.js';
|
|
20
|
+
const program = new Command();
|
|
21
|
+
program
|
|
22
|
+
.name('silky')
|
|
23
|
+
.description('SilkyWay SDK — Agent banking and payments on Solana')
|
|
24
|
+
.version(version)
|
|
25
|
+
.option('--human', 'Human-readable output');
|
|
26
|
+
// init
|
|
27
|
+
program
|
|
28
|
+
.command('init')
|
|
29
|
+
.description('Initialize Silk CLI (create default wallet and agent ID)')
|
|
30
|
+
.action(wrapCommand(init));
|
|
31
|
+
// auth commands
|
|
32
|
+
const auth = program.command('auth').description('Manage API key authentication');
|
|
33
|
+
auth
|
|
34
|
+
.command('register')
|
|
35
|
+
.option('--wallet <label>', 'Wallet to sign the challenge with')
|
|
36
|
+
.description('Register and receive an API key via Solana signature')
|
|
37
|
+
.action(wrapCommand(authRegister));
|
|
38
|
+
auth
|
|
39
|
+
.command('status')
|
|
40
|
+
.description('Show API key status')
|
|
41
|
+
.action(wrapCommand(authStatus));
|
|
42
|
+
auth
|
|
43
|
+
.command('revoke')
|
|
44
|
+
.description('Revoke the current API key')
|
|
45
|
+
.action(wrapCommand(authRevoke));
|
|
46
|
+
// wallet commands
|
|
47
|
+
const wallet = program.command('wallet').description('Manage wallets');
|
|
48
|
+
wallet
|
|
49
|
+
.command('create')
|
|
50
|
+
.argument('[label]', 'wallet label', 'main')
|
|
51
|
+
.description('Create a new wallet')
|
|
52
|
+
.action(wrapCommand(walletCreate));
|
|
53
|
+
wallet
|
|
54
|
+
.command('list')
|
|
55
|
+
.description('List all wallets')
|
|
56
|
+
.action(wrapCommand(walletList));
|
|
57
|
+
wallet
|
|
58
|
+
.command('fund')
|
|
59
|
+
.option('--sol', 'Request SOL only')
|
|
60
|
+
.option('--usdc', 'Request USDC only')
|
|
61
|
+
.option('--wallet <label>', 'Wallet to fund')
|
|
62
|
+
.description('Fund wallet from devnet faucet (devnet only)')
|
|
63
|
+
.action(wrapCommand(walletFund));
|
|
64
|
+
// balance
|
|
65
|
+
program
|
|
66
|
+
.command('balance')
|
|
67
|
+
.option('--wallet <label>', 'Wallet to check')
|
|
68
|
+
.description('Check wallet balances')
|
|
69
|
+
.action(wrapCommand(balance));
|
|
70
|
+
// pay
|
|
71
|
+
program
|
|
72
|
+
.command('pay')
|
|
73
|
+
.argument('<recipient>', 'Recipient wallet address')
|
|
74
|
+
.argument('<amount>', 'Amount in USDC')
|
|
75
|
+
.option('--memo <text>', 'Payment memo')
|
|
76
|
+
.option('--wallet <label>', 'Sender wallet')
|
|
77
|
+
.description('Send a USDC payment')
|
|
78
|
+
.action(wrapCommand(pay));
|
|
79
|
+
// claim
|
|
80
|
+
program
|
|
81
|
+
.command('claim')
|
|
82
|
+
.argument('<transferPda>', 'Transfer PDA to claim')
|
|
83
|
+
.option('--wallet <label>', 'Wallet to claim with')
|
|
84
|
+
.description('Claim a received payment')
|
|
85
|
+
.action(wrapCommand(claim));
|
|
86
|
+
// cancel
|
|
87
|
+
program
|
|
88
|
+
.command('cancel')
|
|
89
|
+
.argument('<transferPda>', 'Transfer PDA to cancel')
|
|
90
|
+
.option('--wallet <label>', 'Wallet to cancel with')
|
|
91
|
+
.description('Cancel a sent payment')
|
|
92
|
+
.action(wrapCommand(cancel));
|
|
93
|
+
// payments
|
|
94
|
+
const payments = program.command('payments').description('View payment history');
|
|
95
|
+
payments
|
|
96
|
+
.command('list')
|
|
97
|
+
.option('--wallet <label>', 'Wallet to query')
|
|
98
|
+
.description('List transfers')
|
|
99
|
+
.action(wrapCommand(paymentsList));
|
|
100
|
+
payments
|
|
101
|
+
.command('get')
|
|
102
|
+
.argument('<transferPda>', 'Transfer PDA')
|
|
103
|
+
.description('Get transfer details')
|
|
104
|
+
.action(wrapCommand(paymentsGet));
|
|
105
|
+
// config
|
|
106
|
+
const config = program.command('config').description('SDK configuration');
|
|
107
|
+
config
|
|
108
|
+
.command('set-cluster')
|
|
109
|
+
.argument('<cluster>', 'Cluster: mainnet-beta or devnet')
|
|
110
|
+
.description('Set the Solana cluster')
|
|
111
|
+
.action(wrapCommand(configSetCluster));
|
|
112
|
+
config
|
|
113
|
+
.command('get-cluster')
|
|
114
|
+
.description('Show the current Solana cluster')
|
|
115
|
+
.action(wrapCommand(configGetCluster));
|
|
116
|
+
config
|
|
117
|
+
.command('reset-cluster')
|
|
118
|
+
.description('Reset cluster to default (mainnet-beta)')
|
|
119
|
+
.action(wrapCommand(configResetCluster));
|
|
120
|
+
// account commands
|
|
121
|
+
const account = program.command('account').description('Manage Silkysig account');
|
|
122
|
+
account
|
|
123
|
+
.command('sync')
|
|
124
|
+
.option('--wallet <label>', 'Wallet to sync')
|
|
125
|
+
.option('--account <pda>', 'Sync a specific account by PDA')
|
|
126
|
+
.description('Discover and sync your account')
|
|
127
|
+
.action(wrapCommand(accountSync));
|
|
128
|
+
account
|
|
129
|
+
.command('status')
|
|
130
|
+
.option('--wallet <label>', 'Wallet to check')
|
|
131
|
+
.description('Show account balance and policy')
|
|
132
|
+
.action(wrapCommand(accountStatus));
|
|
133
|
+
account
|
|
134
|
+
.command('events')
|
|
135
|
+
.option('--type <eventType>', 'Filter by event type')
|
|
136
|
+
.option('--wallet <label>', 'Wallet to check')
|
|
137
|
+
.description('List account events')
|
|
138
|
+
.action(wrapCommand(accountEvents));
|
|
139
|
+
account
|
|
140
|
+
.command('deposit')
|
|
141
|
+
.argument('<amount>', 'Amount in USDC')
|
|
142
|
+
.option('--wallet <label>', 'Wallet to deposit from')
|
|
143
|
+
.description('Deposit into account')
|
|
144
|
+
.action(wrapCommand(accountDeposit));
|
|
145
|
+
account
|
|
146
|
+
.command('withdraw')
|
|
147
|
+
.argument('<amount>', 'Amount in USDC')
|
|
148
|
+
.option('--wallet <label>', 'Wallet to withdraw to')
|
|
149
|
+
.description('Withdraw from account to your wallet')
|
|
150
|
+
.action(wrapCommand(accountWithdraw));
|
|
151
|
+
account
|
|
152
|
+
.command('send')
|
|
153
|
+
.argument('<recipient>', 'Recipient wallet address')
|
|
154
|
+
.argument('<amount>', 'Amount in USDC')
|
|
155
|
+
.option('--memo <text>', 'Payment memo')
|
|
156
|
+
.option('--wallet <label>', 'Sender wallet')
|
|
157
|
+
.description('Send from account (policy-enforced)')
|
|
158
|
+
.action(wrapCommand(accountSend));
|
|
159
|
+
// contacts commands
|
|
160
|
+
const contacts = program.command('contacts').description('Manage address book');
|
|
161
|
+
contacts
|
|
162
|
+
.command('add')
|
|
163
|
+
.argument('<name>', 'Contact name')
|
|
164
|
+
.argument('<address>', 'Solana wallet address')
|
|
165
|
+
.description('Add a contact')
|
|
166
|
+
.action(wrapCommand(contactsAdd));
|
|
167
|
+
contacts
|
|
168
|
+
.command('remove')
|
|
169
|
+
.argument('<name>', 'Contact name')
|
|
170
|
+
.description('Remove a contact')
|
|
171
|
+
.action(wrapCommand(contactsRemove));
|
|
172
|
+
contacts
|
|
173
|
+
.command('list')
|
|
174
|
+
.description('List all contacts')
|
|
175
|
+
.action(wrapCommand(contactsList));
|
|
176
|
+
contacts
|
|
177
|
+
.command('get')
|
|
178
|
+
.argument('<name>', 'Contact name')
|
|
179
|
+
.description('Get a contact address')
|
|
180
|
+
.action(wrapCommand(contactsGet));
|
|
181
|
+
// chat
|
|
182
|
+
program
|
|
183
|
+
.command('chat')
|
|
184
|
+
.argument('<message>', 'Message to send to support')
|
|
185
|
+
.description('Chat with SilkyWay support agent')
|
|
186
|
+
.action(wrapCommand(chat));
|
|
187
|
+
// orders commands
|
|
188
|
+
const orders = program.command('orders').description('Manage standing orders');
|
|
189
|
+
orders
|
|
190
|
+
.command('create')
|
|
191
|
+
.argument('<intent-or-action>', 'JSON intent string or action name (e.g., "swap")')
|
|
192
|
+
.option('--sell <amount-symbol>', 'Sell amount and symbol (e.g., "500 USDC")')
|
|
193
|
+
.option('--buy <symbol>', 'Buy token symbol (e.g., "SOL")')
|
|
194
|
+
.option('--price <number>', 'Target price')
|
|
195
|
+
.option('--slippage <percent>', 'Max slippage percent (default: 0.1, max: 10)')
|
|
196
|
+
.option('--expires <duration>', 'Expiry (e.g., "7d", "24h", "30m", or ISO date)')
|
|
197
|
+
.option('--cooldown <seconds>', 'Seconds between attempts (default: 60)')
|
|
198
|
+
.option('--max-attempts <number>', 'Max evaluation attempts')
|
|
199
|
+
.option('--wallet <label>', 'Wallet to use')
|
|
200
|
+
.description('Create a standing order from JSON intent or swap sugar')
|
|
201
|
+
.action(wrapCommand(ordersCreate));
|
|
202
|
+
orders
|
|
203
|
+
.command('list')
|
|
204
|
+
.option('--status <status>', 'Filter by status')
|
|
205
|
+
.description('List all standing orders')
|
|
206
|
+
.action(wrapCommand(ordersList));
|
|
207
|
+
orders
|
|
208
|
+
.command('get')
|
|
209
|
+
.argument('<orderId>', 'Order ID')
|
|
210
|
+
.description('Get order details')
|
|
211
|
+
.action(wrapCommand(ordersGet));
|
|
212
|
+
orders
|
|
213
|
+
.command('cancel')
|
|
214
|
+
.argument('<orderId>', 'Order ID')
|
|
215
|
+
.description('Cancel a pending order')
|
|
216
|
+
.action(wrapCommand(ordersCancel));
|
|
217
|
+
orders
|
|
218
|
+
.command('evaluate')
|
|
219
|
+
.option('--dry-run', 'Show what would happen without executing')
|
|
220
|
+
.option('--wallet <label>', 'Wallet to use')
|
|
221
|
+
.description('Evaluate all pending orders (run on heartbeat)')
|
|
222
|
+
.action(wrapCommand(ordersEvaluate));
|
|
223
|
+
program.parse();
|
|
224
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,OAAO,GAAG,aAAa,CAAC,MAA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AAE,gDAAgD,CAAC;KAChF,MAAM,CAAC,sBAAsB,EAAE,wCAAwC,CAAC;KACxE,MAAM,CAAC,yBAAyB,EAAE,yBAAyB,CAAC;KAC5D,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC;KAC3C,WAAW,CAAC,wDAAwD,CAAC;KACrE,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;AACrC,MAAM;KACH,OAAO,CAAC,MAAM,CAAC;KACf,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC;KAC/C,WAAW,CAAC,0BAA0B,CAAC;KACvC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AACnC,MAAM;KACH,OAAO,CAAC,KAAK,CAAC;KACd,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;KACjC,WAAW,CAAC,mBAAmB,CAAC;KAChC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;AAClC,MAAM;KACH,OAAO,CAAC,QAAQ,CAAC;KACjB,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;KACjC,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;AACrC,MAAM;KACH,OAAO,CAAC,UAAU,CAAC;KACnB,MAAM,CAAC,WAAW,EAAE,0CAA0C,CAAC;KAC/D,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC;KAC3C,WAAW,CAAC,gDAAgD,CAAC;KAC7D,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;AAEvC,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { SdkError, ANCHOR_ERROR_MAP } from './errors.js';
|
|
3
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
4
|
+
export function createHttpClient(config = {}) {
|
|
5
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
6
|
+
if (config.apiKey) {
|
|
7
|
+
headers['Authorization'] = `Bearer ${config.apiKey}`;
|
|
8
|
+
}
|
|
9
|
+
const client = axios.create({
|
|
10
|
+
baseURL: config.baseUrl || 'http://localhost:3000',
|
|
11
|
+
timeout: config.timeout || DEFAULT_TIMEOUT,
|
|
12
|
+
headers,
|
|
13
|
+
});
|
|
14
|
+
client.interceptors.response.use((response) => response, (error) => {
|
|
15
|
+
if (error.response?.status === 401) {
|
|
16
|
+
throw new SdkError('UNAUTHORIZED', 'API key required or invalid. Run `silky auth register` to get an API key.');
|
|
17
|
+
}
|
|
18
|
+
if (error.response?.data?.error) {
|
|
19
|
+
const apiCode = error.response.data.error;
|
|
20
|
+
const apiMessage = error.response.data.message || 'Unknown API error';
|
|
21
|
+
if (apiCode === 'TX_FAILED') {
|
|
22
|
+
const hexMatch = apiMessage.match(/0x([0-9a-fA-F]+)/);
|
|
23
|
+
if (hexMatch) {
|
|
24
|
+
const errorCode = parseInt(hexMatch[1], 16);
|
|
25
|
+
const anchor = ANCHOR_ERROR_MAP[errorCode];
|
|
26
|
+
if (anchor) {
|
|
27
|
+
throw new SdkError(anchor.code, anchor.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw new SdkError(apiCode, apiMessage);
|
|
32
|
+
}
|
|
33
|
+
if (error.response?.data?.message) {
|
|
34
|
+
throw new SdkError('API_ERROR', error.response.data.message);
|
|
35
|
+
}
|
|
36
|
+
if (error.code === 'ECONNABORTED') {
|
|
37
|
+
throw new SdkError('TIMEOUT', 'Request timeout — is the SilkyWay server running?');
|
|
38
|
+
}
|
|
39
|
+
throw new SdkError('NETWORK_ERROR', 'Network error — is the SilkyWay server running?');
|
|
40
|
+
});
|
|
41
|
+
return client;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client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EAAE,CAAC;oBACb,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;oBAC3C,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;oBAClD,CAAC;gBACH,CAAC;YACH,CAAC;YAED,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;YAClC,MAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAClC,MAAM,IAAI,QAAQ,CAAC,SAAS,EAAE,mDAAmD,CAAC,CAAC;QACrF,CAAC;QACD,MAAM,IAAI,QAAQ,CAAC,eAAe,EAAE,iDAAiD,CAAC,CAAC;IACzF,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare function accountSync(opts: {
|
|
2
|
+
wallet?: string;
|
|
3
|
+
account?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function accountStatus(opts: {
|
|
6
|
+
wallet?: string;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function accountEvents(opts: {
|
|
9
|
+
type?: string;
|
|
10
|
+
wallet?: string;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
export declare function accountDeposit(amount: string, opts: {
|
|
13
|
+
wallet?: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export declare function accountWithdraw(amount: string, opts: {
|
|
16
|
+
wallet?: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
export declare function accountSend(recipient: string, amount: string, opts: {
|
|
19
|
+
memo?: string;
|
|
20
|
+
wallet?: string;
|
|
21
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { Keypair, Transaction } from '@solana/web3.js';
|
|
2
|
+
import bs58 from 'bs58';
|
|
3
|
+
import { loadConfig, saveConfig, getWallet, getApiUrl, getApiKey, getSetupUrl } from '../config.js';
|
|
4
|
+
import { createHttpClient } from '../client.js';
|
|
5
|
+
import { outputSuccess } from '../output.js';
|
|
6
|
+
import { SdkError, toSilkysigError } from '../errors.js';
|
|
7
|
+
import { validateAddress, validateAmount } from '../validate.js';
|
|
8
|
+
import { resolveRecipient } from '../contacts.js';
|
|
9
|
+
export async function accountSync(opts) {
|
|
10
|
+
const config = loadConfig();
|
|
11
|
+
const wallet = getWallet(config, opts.wallet);
|
|
12
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
13
|
+
if (opts.account) {
|
|
14
|
+
// Direct PDA sync
|
|
15
|
+
validateAddress(opts.account, 'account');
|
|
16
|
+
const res = await client.get(`/api/account/${opts.account}`);
|
|
17
|
+
const acct = res.data.data;
|
|
18
|
+
// Verify wallet is an operator on this account
|
|
19
|
+
const op = acct.operators.find((o) => o.pubkey === wallet.address);
|
|
20
|
+
if (!op) {
|
|
21
|
+
throw new SdkError('NOT_OPERATOR', `Wallet "${wallet.label}" (${wallet.address}) is not an operator on account ${opts.account}`);
|
|
22
|
+
}
|
|
23
|
+
const accountInfo = {
|
|
24
|
+
pda: acct.pda,
|
|
25
|
+
owner: acct.owner,
|
|
26
|
+
mint: acct.mint,
|
|
27
|
+
mintDecimals: acct.mintDecimals,
|
|
28
|
+
operatorIndex: op.index,
|
|
29
|
+
perTxLimit: Number(op.perTxLimit),
|
|
30
|
+
syncedAt: new Date().toISOString(),
|
|
31
|
+
};
|
|
32
|
+
config.account = accountInfo;
|
|
33
|
+
saveConfig(config);
|
|
34
|
+
const balanceHuman = acct.mintDecimals > 0 ? acct.balance / 10 ** acct.mintDecimals : acct.balance;
|
|
35
|
+
const perTxLimitHuman = acct.mintDecimals > 0 ? Number(op.perTxLimit) / 10 ** acct.mintDecimals : Number(op.perTxLimit);
|
|
36
|
+
outputSuccess({
|
|
37
|
+
action: 'sync',
|
|
38
|
+
pda: acct.pda,
|
|
39
|
+
owner: acct.owner,
|
|
40
|
+
balance: balanceHuman,
|
|
41
|
+
perTxLimit: perTxLimitHuman,
|
|
42
|
+
mint: acct.mint,
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Discover by operator
|
|
47
|
+
const res = await client.get(`/api/account/by-operator/${wallet.address}`);
|
|
48
|
+
const accounts = res.data.data.accounts;
|
|
49
|
+
if (accounts.length === 0) {
|
|
50
|
+
outputSuccess({
|
|
51
|
+
action: 'sync',
|
|
52
|
+
found: 0,
|
|
53
|
+
message: `No account found for wallet "${wallet.label}" (${wallet.address}).`,
|
|
54
|
+
hint: `Ask your human to set up your account at:\n ${getSetupUrl(config, wallet.address)}`,
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Deterministic selection: sort by PDA so the same account is always picked
|
|
59
|
+
accounts.sort((a, b) => a.pda.localeCompare(b.pda));
|
|
60
|
+
const selected = accounts[0];
|
|
61
|
+
const slot = selected.operatorSlot;
|
|
62
|
+
const accountInfo = {
|
|
63
|
+
pda: selected.pda,
|
|
64
|
+
owner: selected.owner,
|
|
65
|
+
mint: selected.mint,
|
|
66
|
+
mintDecimals: selected.mintDecimals,
|
|
67
|
+
operatorIndex: slot.index,
|
|
68
|
+
perTxLimit: Number(slot.perTxLimit),
|
|
69
|
+
syncedAt: new Date().toISOString(),
|
|
70
|
+
};
|
|
71
|
+
config.account = accountInfo;
|
|
72
|
+
saveConfig(config);
|
|
73
|
+
const formatBalance = (bal, decimals) => decimals > 0 ? bal / 10 ** decimals : bal;
|
|
74
|
+
const formatLimit = (limit, decimals) => decimals > 0 ? Number(limit) / 10 ** decimals : Number(limit);
|
|
75
|
+
if (accounts.length === 1) {
|
|
76
|
+
outputSuccess({
|
|
77
|
+
action: 'sync',
|
|
78
|
+
pda: selected.pda,
|
|
79
|
+
owner: selected.owner,
|
|
80
|
+
balance: formatBalance(selected.balance, selected.mintDecimals),
|
|
81
|
+
perTxLimit: formatLimit(slot.perTxLimit, selected.mintDecimals),
|
|
82
|
+
mint: selected.mint,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
outputSuccess({
|
|
87
|
+
action: 'sync',
|
|
88
|
+
pda: selected.pda,
|
|
89
|
+
owner: selected.owner,
|
|
90
|
+
balance: formatBalance(selected.balance, selected.mintDecimals),
|
|
91
|
+
perTxLimit: formatLimit(slot.perTxLimit, selected.mintDecimals),
|
|
92
|
+
mint: selected.mint,
|
|
93
|
+
warning: `This wallet is operator on ${accounts.length} accounts. Using ${selected.pda}. The SDK currently supports one account at a time. To target a specific account: silky account sync --account <pda>`,
|
|
94
|
+
allAccounts: accounts.map((a) => ({
|
|
95
|
+
pda: a.pda,
|
|
96
|
+
owner: a.owner,
|
|
97
|
+
balance: formatBalance(a.balance, a.mintDecimals),
|
|
98
|
+
})),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function accountStatus(opts) {
|
|
103
|
+
const config = loadConfig();
|
|
104
|
+
getWallet(config, opts.wallet); // validate wallet exists
|
|
105
|
+
if (!config.account) {
|
|
106
|
+
throw new SdkError('NO_ACCOUNT', 'No account synced. Run: silky account sync');
|
|
107
|
+
}
|
|
108
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
109
|
+
const res = await client.get(`/api/account/${config.account.pda}`);
|
|
110
|
+
const acct = res.data.data;
|
|
111
|
+
const op = acct.operators.find((o) => o.index === config.account.operatorIndex);
|
|
112
|
+
const perTxLimit = op ? Number(op.perTxLimit) : config.account.perTxLimit;
|
|
113
|
+
const perTxLimitHuman = acct.mintDecimals > 0 ? perTxLimit / 10 ** acct.mintDecimals : perTxLimit;
|
|
114
|
+
const balanceHuman = acct.mintDecimals > 0 ? acct.balance / 10 ** acct.mintDecimals : acct.balance;
|
|
115
|
+
outputSuccess({
|
|
116
|
+
action: 'status',
|
|
117
|
+
pda: acct.pda,
|
|
118
|
+
owner: acct.owner,
|
|
119
|
+
balance: balanceHuman,
|
|
120
|
+
mint: acct.mint,
|
|
121
|
+
isPaused: acct.isPaused,
|
|
122
|
+
operatorIndex: config.account.operatorIndex,
|
|
123
|
+
perTxLimit: perTxLimitHuman,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
export async function accountEvents(opts) {
|
|
127
|
+
const config = loadConfig();
|
|
128
|
+
getWallet(config, opts.wallet); // validate wallet exists
|
|
129
|
+
if (!config.account) {
|
|
130
|
+
throw new SdkError('NO_ACCOUNT', 'No account synced. Run: silky account sync');
|
|
131
|
+
}
|
|
132
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
133
|
+
const params = opts.type ? `?eventType=${opts.type}` : '';
|
|
134
|
+
const res = await client.get(`/api/account/${config.account.pda}/events${params}`);
|
|
135
|
+
const events = res.data.data;
|
|
136
|
+
outputSuccess({ action: 'events', pda: config.account.pda, events });
|
|
137
|
+
}
|
|
138
|
+
export async function accountDeposit(amount, opts) {
|
|
139
|
+
const config = loadConfig();
|
|
140
|
+
const wallet = getWallet(config, opts.wallet);
|
|
141
|
+
if (!config.account) {
|
|
142
|
+
throw new SdkError('NO_ACCOUNT', 'No account synced. Run: silky account sync');
|
|
143
|
+
}
|
|
144
|
+
const amountNum = validateAmount(amount);
|
|
145
|
+
const amountRaw = Math.round(amountNum * 10 ** config.account.mintDecimals);
|
|
146
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
147
|
+
// 1. Build unsigned transaction
|
|
148
|
+
const buildRes = await client.post('/api/account/deposit', {
|
|
149
|
+
depositor: wallet.address,
|
|
150
|
+
accountPda: config.account.pda,
|
|
151
|
+
amount: amountRaw,
|
|
152
|
+
});
|
|
153
|
+
const { transaction: txBase64 } = buildRes.data.data;
|
|
154
|
+
// 2. Sign the transaction
|
|
155
|
+
const tx = Transaction.from(Buffer.from(txBase64, 'base64'));
|
|
156
|
+
const keypair = Keypair.fromSecretKey(bs58.decode(wallet.privateKey));
|
|
157
|
+
tx.sign(keypair);
|
|
158
|
+
// 3. Submit signed transaction
|
|
159
|
+
try {
|
|
160
|
+
const submitRes = await client.post('/api/tx/submit', {
|
|
161
|
+
signedTx: tx.serialize().toString('base64'),
|
|
162
|
+
});
|
|
163
|
+
const { txid } = submitRes.data.data;
|
|
164
|
+
outputSuccess({ action: 'deposit', txid, amount: amountNum });
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
throw toSilkysigError(err);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export async function accountWithdraw(amount, opts) {
|
|
171
|
+
const config = loadConfig();
|
|
172
|
+
const wallet = getWallet(config, opts.wallet);
|
|
173
|
+
if (!config.account) {
|
|
174
|
+
throw new SdkError('NO_ACCOUNT', 'No account synced. Run: silky account sync');
|
|
175
|
+
}
|
|
176
|
+
const amountNum = validateAmount(amount);
|
|
177
|
+
const amountRaw = Math.round(amountNum * 10 ** config.account.mintDecimals);
|
|
178
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
179
|
+
// 1. Build unsigned transaction (transfer back to own wallet)
|
|
180
|
+
const buildRes = await client.post('/api/account/transfer', {
|
|
181
|
+
signer: wallet.address,
|
|
182
|
+
accountPda: config.account.pda,
|
|
183
|
+
recipient: wallet.address,
|
|
184
|
+
amount: amountRaw,
|
|
185
|
+
});
|
|
186
|
+
const { transaction: txBase64 } = buildRes.data.data;
|
|
187
|
+
// 2. Sign the transaction
|
|
188
|
+
const tx = Transaction.from(Buffer.from(txBase64, 'base64'));
|
|
189
|
+
const keypair = Keypair.fromSecretKey(bs58.decode(wallet.privateKey));
|
|
190
|
+
tx.sign(keypair);
|
|
191
|
+
// 3. Submit signed transaction
|
|
192
|
+
try {
|
|
193
|
+
const submitRes = await client.post('/api/tx/submit', {
|
|
194
|
+
signedTx: tx.serialize().toString('base64'),
|
|
195
|
+
});
|
|
196
|
+
const { txid } = submitRes.data.data;
|
|
197
|
+
outputSuccess({ action: 'withdraw', txid, amount: amountNum });
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
throw toSilkysigError(err);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export async function accountSend(recipient, amount, opts) {
|
|
204
|
+
recipient = resolveRecipient(recipient);
|
|
205
|
+
const config = loadConfig();
|
|
206
|
+
const wallet = getWallet(config, opts.wallet);
|
|
207
|
+
if (!config.account) {
|
|
208
|
+
throw new SdkError('NO_ACCOUNT', 'No account synced. Run: silky account sync');
|
|
209
|
+
}
|
|
210
|
+
validateAddress(recipient, 'recipient');
|
|
211
|
+
const amountNum = validateAmount(amount);
|
|
212
|
+
// Convert to smallest units
|
|
213
|
+
const amountRaw = Math.round(amountNum * 10 ** config.account.mintDecimals);
|
|
214
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey: getApiKey(config) });
|
|
215
|
+
// 1. Build unsigned transaction
|
|
216
|
+
const buildRes = await client.post('/api/account/transfer', {
|
|
217
|
+
signer: wallet.address,
|
|
218
|
+
accountPda: config.account.pda,
|
|
219
|
+
recipient,
|
|
220
|
+
amount: amountRaw,
|
|
221
|
+
});
|
|
222
|
+
const { transaction: txBase64 } = buildRes.data.data;
|
|
223
|
+
// 2. Sign the transaction
|
|
224
|
+
const tx = Transaction.from(Buffer.from(txBase64, 'base64'));
|
|
225
|
+
const keypair = Keypair.fromSecretKey(bs58.decode(wallet.privateKey));
|
|
226
|
+
tx.sign(keypair);
|
|
227
|
+
// 3. Submit signed transaction
|
|
228
|
+
try {
|
|
229
|
+
const submitRes = await client.post('/api/tx/submit', {
|
|
230
|
+
signedTx: tx.serialize().toString('base64'),
|
|
231
|
+
});
|
|
232
|
+
const { txid } = submitRes.data.data;
|
|
233
|
+
outputSuccess({ action: 'send', txid, amount: amountNum, recipient });
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
throw toSilkysigError(err);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/commands/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAe,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA+BlD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAA2C;IAC3E,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAA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,QAAQ,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;IAErD,0BAA0B;IAC1B,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACtE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEjB,+BAA+B;IAC/B,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE;YACpD,QAAQ,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;SAC5C,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QACrC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Keypair } from '@solana/web3.js';
|
|
2
|
+
import bs58 from 'bs58';
|
|
3
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
4
|
+
import { loadConfig, saveConfig, getWallet, getApiUrl, getApiKey, clearApiKey } from '../config.js';
|
|
5
|
+
import { createHttpClient } from '../client.js';
|
|
6
|
+
import { outputSuccess } from '../output.js';
|
|
7
|
+
import { SdkError } from '../errors.js';
|
|
8
|
+
export async function authRegister(opts) {
|
|
9
|
+
const config = loadConfig();
|
|
10
|
+
const wallet = getWallet(config, opts.wallet);
|
|
11
|
+
const keypair = Keypair.fromSecretKey(bs58.decode(wallet.privateKey));
|
|
12
|
+
// Use unauthenticated client for challenge/register
|
|
13
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config) });
|
|
14
|
+
// 1. Get challenge nonce
|
|
15
|
+
const challengeRes = await client.get(`/api/auth/challenge?pubkey=${wallet.address}`);
|
|
16
|
+
const { nonce } = challengeRes.data.data;
|
|
17
|
+
// 2. Sign nonce (noble/curves expects 32-byte seed, not Solana's 64-byte combined format)
|
|
18
|
+
const signature = ed25519.sign(Buffer.from(nonce, 'utf-8'), keypair.secretKey.slice(0, 32));
|
|
19
|
+
const signatureBase64 = Buffer.from(signature).toString('base64');
|
|
20
|
+
// 3. Register and receive API key
|
|
21
|
+
const registerRes = await client.post('/api/auth/register', {
|
|
22
|
+
pubkey: wallet.address,
|
|
23
|
+
signature: signatureBase64,
|
|
24
|
+
});
|
|
25
|
+
const { apiKey } = registerRes.data.data;
|
|
26
|
+
config.apiKey = apiKey;
|
|
27
|
+
saveConfig(config);
|
|
28
|
+
outputSuccess({ action: 'auth_register', message: 'API key registered and saved.' });
|
|
29
|
+
}
|
|
30
|
+
export async function authStatus() {
|
|
31
|
+
const config = loadConfig();
|
|
32
|
+
const apiKey = getApiKey(config);
|
|
33
|
+
if (!apiKey) {
|
|
34
|
+
outputSuccess({
|
|
35
|
+
action: 'auth_status',
|
|
36
|
+
configured: false,
|
|
37
|
+
hint: 'Run `silky auth register` to get an API key.',
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const source = config.apiKey ? 'config' : 'SILKY_API_KEY env var';
|
|
42
|
+
const fingerprint = apiKey.slice(0, 9);
|
|
43
|
+
outputSuccess({
|
|
44
|
+
action: 'auth_status',
|
|
45
|
+
configured: true,
|
|
46
|
+
source,
|
|
47
|
+
fingerprint: `${fingerprint}...`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export async function authRevoke() {
|
|
51
|
+
const config = loadConfig();
|
|
52
|
+
const apiKey = getApiKey(config);
|
|
53
|
+
if (!apiKey) {
|
|
54
|
+
throw new SdkError('NO_API_KEY', 'No API key configured. Run `silky auth register` first.');
|
|
55
|
+
}
|
|
56
|
+
const client = createHttpClient({ baseUrl: getApiUrl(config), apiKey });
|
|
57
|
+
try {
|
|
58
|
+
await client.post('/api/auth/revoke', {});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err.code === 'UNAUTHORIZED') {
|
|
62
|
+
throw new SdkError('UNAUTHORIZED', 'API key is already invalid or expired.');
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
clearApiKey(config);
|
|
67
|
+
saveConfig(config);
|
|
68
|
+
outputSuccess({ action: 'auth_revoke', message: 'API key revoked and removed from config.' });
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=auth.js.map
|