@sequence0/sdk 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +10 -10
  2. package/dist/chains/casper.d.ts +74 -0
  3. package/dist/chains/casper.d.ts.map +1 -0
  4. package/dist/chains/casper.js +512 -0
  5. package/dist/chains/casper.js.map +1 -0
  6. package/dist/chains/cosmos.d.ts +22 -0
  7. package/dist/chains/cosmos.d.ts.map +1 -1
  8. package/dist/chains/cosmos.js +113 -12
  9. package/dist/chains/cosmos.js.map +1 -1
  10. package/dist/chains/ethereum.d.ts.map +1 -1
  11. package/dist/chains/ethereum.js +14 -2
  12. package/dist/chains/ethereum.js.map +1 -1
  13. package/dist/chains/flow.d.ts +57 -0
  14. package/dist/chains/flow.d.ts.map +1 -0
  15. package/dist/chains/flow.js +435 -0
  16. package/dist/chains/flow.js.map +1 -0
  17. package/dist/chains/icp.d.ts.map +1 -1
  18. package/dist/chains/icp.js +483 -67
  19. package/dist/chains/icp.js.map +1 -1
  20. package/dist/chains/iota.d.ts +80 -0
  21. package/dist/chains/iota.d.ts.map +1 -0
  22. package/dist/chains/iota.js +502 -0
  23. package/dist/chains/iota.js.map +1 -0
  24. package/dist/chains/kadena.d.ts +81 -0
  25. package/dist/chains/kadena.d.ts.map +1 -0
  26. package/dist/chains/kadena.js +356 -0
  27. package/dist/chains/kadena.js.map +1 -0
  28. package/dist/chains/near.d.ts +4 -1
  29. package/dist/chains/near.d.ts.map +1 -1
  30. package/dist/chains/near.js +58 -15
  31. package/dist/chains/near.js.map +1 -1
  32. package/dist/chains/nervos.d.ts +148 -0
  33. package/dist/chains/nervos.d.ts.map +1 -0
  34. package/dist/chains/nervos.js +913 -0
  35. package/dist/chains/nervos.js.map +1 -0
  36. package/dist/chains/radix.d.ts +81 -0
  37. package/dist/chains/radix.d.ts.map +1 -0
  38. package/dist/chains/radix.js +289 -0
  39. package/dist/chains/radix.js.map +1 -0
  40. package/dist/chains/solana.d.ts +4 -0
  41. package/dist/chains/solana.d.ts.map +1 -1
  42. package/dist/chains/solana.js +47 -13
  43. package/dist/chains/solana.js.map +1 -1
  44. package/dist/chains/stacks.d.ts +113 -0
  45. package/dist/chains/stacks.d.ts.map +1 -0
  46. package/dist/chains/stacks.js +576 -0
  47. package/dist/chains/stacks.js.map +1 -0
  48. package/dist/chains/sui.d.ts +11 -0
  49. package/dist/chains/sui.d.ts.map +1 -1
  50. package/dist/chains/sui.js +49 -8
  51. package/dist/chains/sui.js.map +1 -1
  52. package/dist/core/client.js +1 -1
  53. package/dist/core/client.js.map +1 -1
  54. package/dist/core/solvency.d.ts +1 -1
  55. package/dist/core/solvency.js +1 -1
  56. package/dist/core/types.d.ts +94 -2
  57. package/dist/core/types.d.ts.map +1 -1
  58. package/dist/core/universal-account.d.ts +1 -1
  59. package/dist/core/universal-account.js +1 -1
  60. package/dist/core/witness.d.ts +1 -1
  61. package/dist/core/witness.js +1 -1
  62. package/dist/settlement/settlement.d.ts +1 -1
  63. package/dist/settlement/settlement.js +1 -1
  64. package/dist/utils/discovery.d.ts.map +1 -1
  65. package/dist/utils/discovery.js +19 -2
  66. package/dist/utils/discovery.js.map +1 -1
  67. package/dist/utils/http.d.ts +1 -1
  68. package/dist/utils/http.js +1 -1
  69. package/dist/wallet/wallet.d.ts.map +1 -1
  70. package/dist/wallet/wallet.js +45 -0
  71. package/dist/wallet/wallet.js.map +1 -1
  72. package/package.json +1 -1
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Nervos CKB (Common Knowledge Base) Chain Adapter
3
+ *
4
+ * Builds CKB transactions using the Cell model, computes signing payloads
5
+ * with Blake2b-256 hashing, attaches secp256k1 ECDSA signatures from the
6
+ * FROST threshold signing network, and broadcasts via CKB JSON-RPC.
7
+ *
8
+ * Nervos CKB uses:
9
+ * - Cell model (generalized UTXO) instead of account-based state
10
+ * - Blake2b-256 for transaction hashing (with CKB-specific personalization)
11
+ * - secp256k1 ECDSA with 65-byte recoverable signatures (r + s + recovery_id)
12
+ * - Molecule binary serialization for on-chain data structures
13
+ *
14
+ * No external dependencies beyond @noble/hashes/blake2b (transitive dep).
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { NervosAdapter } from '@sequence0/sdk';
19
+ *
20
+ * const ckb = new NervosAdapter('mainnet');
21
+ *
22
+ * // Build a CKB transfer transaction
23
+ * const unsignedTx = await ckb.buildTransaction(
24
+ * { to: 'ckb1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq...', amount: '10000000000' },
25
+ * 'ckb1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq...'
26
+ * );
27
+ *
28
+ * // ... sign via FROST secp256k1 ...
29
+ * const signedTx = await ckb.attachSignature(unsignedTx, signatureHex);
30
+ * const txHash = await ckb.broadcast(signedTx);
31
+ * ```
32
+ */
33
+ import { ChainAdapter } from '../core/types';
34
+ /** Nervos CKB transaction parameters */
35
+ export interface NervosTransaction {
36
+ /** Recipient CKB address (full address format, ckb1... or ckt1...) */
37
+ to: string;
38
+ /** Amount in shannons (1 CKB = 1e8 shannons) */
39
+ amount: string;
40
+ }
41
+ export declare class NervosAdapter implements ChainAdapter {
42
+ private network;
43
+ private rpcUrl;
44
+ /**
45
+ * Create a Nervos CKB adapter.
46
+ *
47
+ * @param network - Network to connect to: 'mainnet' or 'testnet'
48
+ * @param rpcUrl - Custom RPC URL (overrides the default for the network)
49
+ */
50
+ constructor(network?: 'mainnet' | 'testnet', rpcUrl?: string);
51
+ getRpcUrl(): string;
52
+ /**
53
+ * Build an unsigned CKB transaction.
54
+ *
55
+ * Fetches live cells for the sender, selects inputs to cover the
56
+ * transfer amount plus minimum change cell capacity, constructs
57
+ * outputs (recipient cell + change cell), and includes the
58
+ * secp256k1_blake160 cell dep.
59
+ *
60
+ * The witness placeholder reserves 65 zero bytes in the lock field
61
+ * for the eventual secp256k1 ECDSA signature.
62
+ *
63
+ * @param tx - Transaction parameters (to address, amount in shannons)
64
+ * @param fromAddress - Sender CKB address (ckb1... or ckt1...)
65
+ * @returns Hex-encoded JSON payload with raw transaction and metadata
66
+ */
67
+ buildTransaction(tx: NervosTransaction, fromAddress: string): Promise<string>;
68
+ /**
69
+ * Extract the signing payload from the buildTransaction output.
70
+ *
71
+ * CKB signing payload is computed as:
72
+ * Blake2b-256(tx_hash || witness_length || first_witness || other_witnesses...)
73
+ *
74
+ * Where tx_hash is Blake2b-256 of the serialized RawTransaction (Molecule format),
75
+ * witness_length is the 8-byte LE length of the first witness with placeholder,
76
+ * and the first witness has a 65-byte zero lock field as placeholder.
77
+ *
78
+ * @param unsignedTx - Hex-encoded unsigned transaction from buildTransaction
79
+ * @returns 32-byte signing hash (hex-encoded, without 0x prefix)
80
+ */
81
+ getSigningPayload(unsignedTx: string): string;
82
+ /**
83
+ * Attach a secp256k1 ECDSA signature to the CKB transaction.
84
+ *
85
+ * CKB expects a 65-byte recoverable signature (r: 32 bytes + s: 32 bytes + recovery_id: 1 byte)
86
+ * placed in the lock field of the first WitnessArgs.
87
+ *
88
+ * @param unsignedTx - Hex-encoded unsigned transaction from buildTransaction
89
+ * @param signature - 65-byte secp256k1 signature (hex-encoded, r + s + recovery_id)
90
+ * @returns Hex-encoded signed transaction payload
91
+ */
92
+ attachSignature(unsignedTx: string, signature: string): Promise<string>;
93
+ /**
94
+ * Broadcast a signed CKB transaction.
95
+ *
96
+ * Calls the `send_transaction` JSON-RPC method on the CKB node.
97
+ *
98
+ * @param signedTx - Hex-encoded signed transaction from attachSignature
99
+ * @returns Transaction hash (0x-prefixed)
100
+ */
101
+ broadcast(signedTx: string): Promise<string>;
102
+ /**
103
+ * Get the CKB balance for an address.
104
+ *
105
+ * Returns balance in shannons (1 CKB = 1e8 shannons).
106
+ * Uses the `get_cells_capacity` indexer RPC method to sum
107
+ * all live cell capacities for the address lock script.
108
+ *
109
+ * @param address - CKB address (ckb1... or ckt1...)
110
+ * @returns Balance in shannons as a string
111
+ */
112
+ getBalance(address: string): Promise<string>;
113
+ /**
114
+ * Fetch live cells for a given lock script using the CKB indexer RPC.
115
+ *
116
+ * Uses the `get_cells` JSON-RPC method to query the indexer for
117
+ * live (unspent) cells matching the given lock script.
118
+ *
119
+ * @param lock - Lock script to search for
120
+ * @returns Array of live cells
121
+ */
122
+ private fetchLiveCells;
123
+ /**
124
+ * Derive a CKB address from a compressed secp256k1 public key.
125
+ *
126
+ * The default CKB lock script uses blake160 (first 20 bytes of Blake2b-256)
127
+ * of the public key as the args field.
128
+ *
129
+ * @param pubkeyHex - 33-byte compressed secp256k1 public key (hex-encoded)
130
+ * @returns CKB address (ckb1... for mainnet, ckt1... for testnet)
131
+ */
132
+ deriveAddress(pubkeyHex: string): string;
133
+ }
134
+ /**
135
+ * Create a Nervos CKB mainnet adapter.
136
+ *
137
+ * @param rpcUrl - Optional custom RPC URL
138
+ * @returns NervosAdapter configured for mainnet
139
+ */
140
+ export declare function createNervosAdapter(rpcUrl?: string): NervosAdapter;
141
+ /**
142
+ * Create a Nervos CKB testnet adapter.
143
+ *
144
+ * @param rpcUrl - Optional custom RPC URL
145
+ * @returns NervosAdapter configured for testnet
146
+ */
147
+ export declare function createNervosTestnetAdapter(rpcUrl?: string): NervosAdapter;
148
+ //# sourceMappingURL=nervos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nervos.d.ts","sourceRoot":"","sources":["../../src/chains/nervos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAsD7C,wCAAwC;AACxC,MAAM,WAAW,iBAAiB;IAC9B,sEAAsE;IACtE,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAClB;AAgeD,qBAAa,aAAc,YAAW,YAAY;IAC9C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;I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