@chainvue/verus-sdk 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/VerusSDK.d.ts +59 -0
- package/dist/VerusSDK.d.ts.map +1 -0
- package/dist/VerusSDK.js +170 -0
- package/dist/VerusSDK.js.map +1 -0
- package/dist/address/index.d.ts +16 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/address/index.js +33 -0
- package/dist/address/index.js.map +1 -0
- package/dist/bundle.js +34129 -0
- package/dist/constants/index.d.ts +51 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +53 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/currency/classify.d.ts +14 -0
- package/dist/currency/classify.d.ts.map +1 -0
- package/dist/currency/classify.js +32 -0
- package/dist/currency/classify.js.map +1 -0
- package/dist/currency/index.d.ts +22 -0
- package/dist/currency/index.d.ts.map +1 -0
- package/dist/currency/index.js +87 -0
- package/dist/currency/index.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +69 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity/index.d.ts +129 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +691 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/index.d.ts +48 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +169 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/message/index.d.ts +18 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/index.js +61 -0
- package/dist/message/index.js.map +1 -0
- package/dist/signing/index.d.ts +53 -0
- package/dist/signing/index.d.ts.map +1 -0
- package/dist/signing/index.js +100 -0
- package/dist/signing/index.js.map +1 -0
- package/dist/transfer/index.d.ts +37 -0
- package/dist/transfer/index.d.ts.map +1 -0
- package/dist/transfer/index.js +275 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/types/index.d.ts +359 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +48 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +141 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utxo/index.d.ts +21 -0
- package/dist/utxo/index.d.ts.map +1 -0
- package/dist/utxo/index.js +139 -0
- package/dist/utxo/index.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type definitions for @chainvue/verus-sdk
|
|
3
|
+
*/
|
|
4
|
+
import type { Network } from '../constants/index.js';
|
|
5
|
+
/** UTXO as provided by an external data source (getaddressutxos) */
|
|
6
|
+
export interface Utxo {
|
|
7
|
+
txid: string;
|
|
8
|
+
outputIndex: number;
|
|
9
|
+
satoshis: number;
|
|
10
|
+
script: string;
|
|
11
|
+
/** Height where this UTXO was created (0 = mempool) */
|
|
12
|
+
height?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Decoded currency values on a UTXO */
|
|
15
|
+
export interface DecodedUtxo extends Utxo {
|
|
16
|
+
/** Currency i-address → satoshi amount */
|
|
17
|
+
currencyValues: Map<string, number>;
|
|
18
|
+
}
|
|
19
|
+
/** Result of UTXO selection */
|
|
20
|
+
export interface SelectionResult {
|
|
21
|
+
/** Selected UTXOs */
|
|
22
|
+
selected: Utxo[];
|
|
23
|
+
/** Native (VRSC) change in satoshis */
|
|
24
|
+
nativeChange: number;
|
|
25
|
+
/** Currency changes: i-address → satoshi amount */
|
|
26
|
+
currencyChanges: Map<string, number>;
|
|
27
|
+
/** Estimated fee in satoshis */
|
|
28
|
+
fee: number;
|
|
29
|
+
}
|
|
30
|
+
/** SDK configuration */
|
|
31
|
+
export interface VerusSDKConfig {
|
|
32
|
+
network: Network;
|
|
33
|
+
}
|
|
34
|
+
/** Common result fields for signed transactions */
|
|
35
|
+
export interface SignedTxResult {
|
|
36
|
+
signedTx: string;
|
|
37
|
+
txid: string;
|
|
38
|
+
fee: number;
|
|
39
|
+
}
|
|
40
|
+
/** Transfer parameters */
|
|
41
|
+
export interface TransferParams {
|
|
42
|
+
wif: string;
|
|
43
|
+
/** Recipient address (R-address) */
|
|
44
|
+
to: string;
|
|
45
|
+
/** Amount in satoshis */
|
|
46
|
+
amount: number;
|
|
47
|
+
utxos: Utxo[];
|
|
48
|
+
changeAddress: string;
|
|
49
|
+
expiryHeight?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Token transfer parameters */
|
|
52
|
+
export interface TransferTokenParams {
|
|
53
|
+
wif: string;
|
|
54
|
+
/** Recipient address (R-address or i-address) */
|
|
55
|
+
to: string;
|
|
56
|
+
/** Amount in satoshis */
|
|
57
|
+
amount: number;
|
|
58
|
+
/** Currency i-address */
|
|
59
|
+
currency: string;
|
|
60
|
+
/** Address type: 'PKH' (R-address) or 'ID' (i-address) */
|
|
61
|
+
addressType?: 'PKH' | 'ID';
|
|
62
|
+
utxos: Utxo[];
|
|
63
|
+
changeAddress: string;
|
|
64
|
+
expiryHeight?: number;
|
|
65
|
+
}
|
|
66
|
+
/** Currency conversion parameters */
|
|
67
|
+
export interface ConvertParams {
|
|
68
|
+
wif: string;
|
|
69
|
+
/** Amount in satoshis */
|
|
70
|
+
amount: number;
|
|
71
|
+
/** Source currency i-address */
|
|
72
|
+
currency: string;
|
|
73
|
+
/** Target currency i-address */
|
|
74
|
+
convertTo: string;
|
|
75
|
+
/** Intermediary currency for reserve-to-reserve (optional) */
|
|
76
|
+
via?: string;
|
|
77
|
+
utxos: Utxo[];
|
|
78
|
+
changeAddress: string;
|
|
79
|
+
expiryHeight?: number;
|
|
80
|
+
}
|
|
81
|
+
/** Full send_currency output specification */
|
|
82
|
+
export interface CurrencyOutput {
|
|
83
|
+
/** Currency i-address (use system ID for native VRSC) */
|
|
84
|
+
currency: string;
|
|
85
|
+
/** Amount in satoshis (as string) */
|
|
86
|
+
satoshis: string;
|
|
87
|
+
/** Recipient address */
|
|
88
|
+
address: string;
|
|
89
|
+
/** Address type: 'PKH' (R-address), 'ID' (i-address), 'ETH' (Ethereum) */
|
|
90
|
+
addressType?: 'PKH' | 'ID' | 'ETH';
|
|
91
|
+
/** Currency i-address to convert to */
|
|
92
|
+
convertTo?: string;
|
|
93
|
+
/** System i-address to export to (cross-chain) */
|
|
94
|
+
exportTo?: string;
|
|
95
|
+
/** Intermediary currency for reserve-to-reserve */
|
|
96
|
+
via?: string;
|
|
97
|
+
/** Bridge currency ID */
|
|
98
|
+
bridgeId?: string;
|
|
99
|
+
/** Fee currency i-address */
|
|
100
|
+
feeCurrency?: string;
|
|
101
|
+
/** Fee amount in satoshis */
|
|
102
|
+
feeSatoshis?: string;
|
|
103
|
+
/** Pre-conversion flag */
|
|
104
|
+
preconvert?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/** Full send_currency parameters */
|
|
107
|
+
export interface SendCurrencyParams {
|
|
108
|
+
wif: string;
|
|
109
|
+
outputs: CurrencyOutput[];
|
|
110
|
+
utxos: Utxo[];
|
|
111
|
+
changeAddress: string;
|
|
112
|
+
expiryHeight?: number;
|
|
113
|
+
}
|
|
114
|
+
/** Send currency result */
|
|
115
|
+
export interface SendCurrencyResult extends SignedTxResult {
|
|
116
|
+
inputsUsed: number;
|
|
117
|
+
nativeChange: number;
|
|
118
|
+
}
|
|
119
|
+
/** Simple P2PKH build+sign parameters */
|
|
120
|
+
export interface BuildAndSignParams {
|
|
121
|
+
wif: string;
|
|
122
|
+
inputs: Array<{
|
|
123
|
+
txid: string;
|
|
124
|
+
vout: number;
|
|
125
|
+
scriptPubKey: string;
|
|
126
|
+
amount: number;
|
|
127
|
+
}>;
|
|
128
|
+
outputs: Array<{
|
|
129
|
+
address: string;
|
|
130
|
+
amount: number;
|
|
131
|
+
}>;
|
|
132
|
+
fee?: number;
|
|
133
|
+
expiryHeight?: number;
|
|
134
|
+
}
|
|
135
|
+
/** Commitment data returned from createCommitment */
|
|
136
|
+
export interface CommitmentData {
|
|
137
|
+
name: string;
|
|
138
|
+
salt: string;
|
|
139
|
+
referral: string | null;
|
|
140
|
+
parent: string | null;
|
|
141
|
+
namereservationHex: string;
|
|
142
|
+
commitmentHash: string;
|
|
143
|
+
}
|
|
144
|
+
/** Create commitment parameters */
|
|
145
|
+
export interface CreateCommitmentParams {
|
|
146
|
+
wif: string;
|
|
147
|
+
name: string;
|
|
148
|
+
utxos: Utxo[];
|
|
149
|
+
changeAddress: string;
|
|
150
|
+
referral?: string;
|
|
151
|
+
parent?: string;
|
|
152
|
+
expiryHeight?: number;
|
|
153
|
+
}
|
|
154
|
+
/** Create commitment result */
|
|
155
|
+
export interface CreateCommitmentResult extends SignedTxResult {
|
|
156
|
+
identityAddress: string;
|
|
157
|
+
commitmentData: CommitmentData;
|
|
158
|
+
}
|
|
159
|
+
/** Register identity parameters */
|
|
160
|
+
export interface RegisterIdentityParams {
|
|
161
|
+
wif: string;
|
|
162
|
+
commitmentUtxo: Utxo;
|
|
163
|
+
commitmentData: CommitmentData;
|
|
164
|
+
primaryAddresses: string[];
|
|
165
|
+
utxos: Utxo[];
|
|
166
|
+
changeAddress: string;
|
|
167
|
+
minSigs?: number;
|
|
168
|
+
revocationAuthority?: string;
|
|
169
|
+
recoveryAuthority?: string;
|
|
170
|
+
/** Referral chain: i-addresses tracing referral levels (up to 3) */
|
|
171
|
+
referralChain?: string[];
|
|
172
|
+
/** Registration fee in VRSC satoshis (default: 10000000000 = 100 VRSC) */
|
|
173
|
+
registrationFee?: number;
|
|
174
|
+
/** Registration fee in parent currency satoshis (for sub-IDs) */
|
|
175
|
+
registrationFeeAmount?: number;
|
|
176
|
+
/** Native import fee in VRSC satoshis (for sub-IDs on fractional currencies) */
|
|
177
|
+
nativeImportFee?: number;
|
|
178
|
+
/** Number of referral levels (default: 3) */
|
|
179
|
+
referralLevels?: number;
|
|
180
|
+
expiryHeight?: number;
|
|
181
|
+
}
|
|
182
|
+
/** Register identity result */
|
|
183
|
+
export interface RegisterIdentityResult extends SignedTxResult {
|
|
184
|
+
identityAddress: string;
|
|
185
|
+
registrationFee: number;
|
|
186
|
+
referralPayments: number;
|
|
187
|
+
referralAmountEach: number;
|
|
188
|
+
inputsUsed: number;
|
|
189
|
+
nativeChange: number;
|
|
190
|
+
}
|
|
191
|
+
/** Update identity parameters */
|
|
192
|
+
export interface UpdateIdentityParams {
|
|
193
|
+
wif: string;
|
|
194
|
+
identityHex: string;
|
|
195
|
+
identityUtxo: Utxo;
|
|
196
|
+
utxos: Utxo[];
|
|
197
|
+
changeAddress: string;
|
|
198
|
+
primaryAddresses?: string[];
|
|
199
|
+
minSigs?: number;
|
|
200
|
+
revocationAuthority?: string;
|
|
201
|
+
recoveryAuthority?: string;
|
|
202
|
+
contentMap?: Record<string, string>;
|
|
203
|
+
contentMultimap?: Record<string, string | string[]>;
|
|
204
|
+
expiryHeight?: number;
|
|
205
|
+
}
|
|
206
|
+
/** Update identity result */
|
|
207
|
+
export interface UpdateIdentityResult extends SignedTxResult {
|
|
208
|
+
identityAddress: string;
|
|
209
|
+
operation: string;
|
|
210
|
+
inputsUsed: number;
|
|
211
|
+
nativeChange: number;
|
|
212
|
+
}
|
|
213
|
+
/** Lock identity parameters */
|
|
214
|
+
export interface LockIdentityParams {
|
|
215
|
+
wif: string;
|
|
216
|
+
identityHex: string;
|
|
217
|
+
identityUtxo: Utxo;
|
|
218
|
+
unlockAfter: number;
|
|
219
|
+
utxos: Utxo[];
|
|
220
|
+
changeAddress: string;
|
|
221
|
+
expiryHeight?: number;
|
|
222
|
+
}
|
|
223
|
+
/** Unlock identity parameters */
|
|
224
|
+
export interface UnlockIdentityParams {
|
|
225
|
+
wif: string;
|
|
226
|
+
identityHex: string;
|
|
227
|
+
identityUtxo: Utxo;
|
|
228
|
+
utxos: Utxo[];
|
|
229
|
+
changeAddress: string;
|
|
230
|
+
expiryHeight?: number;
|
|
231
|
+
}
|
|
232
|
+
/** Revoke identity parameters */
|
|
233
|
+
export interface RevokeIdentityParams {
|
|
234
|
+
wif: string;
|
|
235
|
+
identityHex: string;
|
|
236
|
+
identityUtxo: Utxo;
|
|
237
|
+
utxos: Utxo[];
|
|
238
|
+
changeAddress: string;
|
|
239
|
+
expiryHeight?: number;
|
|
240
|
+
}
|
|
241
|
+
/** Recover identity parameters */
|
|
242
|
+
export interface RecoverIdentityParams {
|
|
243
|
+
wif: string;
|
|
244
|
+
identityHex: string;
|
|
245
|
+
identityUtxo: Utxo;
|
|
246
|
+
utxos: Utxo[];
|
|
247
|
+
changeAddress: string;
|
|
248
|
+
primaryAddresses?: string[];
|
|
249
|
+
revocationAuthority?: string;
|
|
250
|
+
recoveryAuthority?: string;
|
|
251
|
+
expiryHeight?: number;
|
|
252
|
+
}
|
|
253
|
+
/** Define currency parameters (manual mode only) */
|
|
254
|
+
export interface DefineCurrencyParams {
|
|
255
|
+
wif: string;
|
|
256
|
+
identityHex: string;
|
|
257
|
+
identityUtxo: Utxo;
|
|
258
|
+
currencyDefScript: string;
|
|
259
|
+
currencyDefValue?: number;
|
|
260
|
+
utxos: Utxo[];
|
|
261
|
+
changeAddress: string;
|
|
262
|
+
expiryHeight?: number;
|
|
263
|
+
}
|
|
264
|
+
/** Define currency result */
|
|
265
|
+
export interface DefineCurrencyResult extends SignedTxResult {
|
|
266
|
+
identityAddress: string;
|
|
267
|
+
inputsUsed: number;
|
|
268
|
+
nativeChange: number;
|
|
269
|
+
}
|
|
270
|
+
/** Sign message parameters */
|
|
271
|
+
export interface SignMessageParams {
|
|
272
|
+
wif: string;
|
|
273
|
+
message: string;
|
|
274
|
+
identityAddress: string;
|
|
275
|
+
chainId?: string;
|
|
276
|
+
blockHeight?: number;
|
|
277
|
+
version?: 1 | 2;
|
|
278
|
+
}
|
|
279
|
+
/** Sign message result */
|
|
280
|
+
export interface SignMessageResult {
|
|
281
|
+
signature: string;
|
|
282
|
+
identitySignatureHex: string;
|
|
283
|
+
message: string;
|
|
284
|
+
identityAddress: string;
|
|
285
|
+
chainId: string;
|
|
286
|
+
blockHeight: number;
|
|
287
|
+
version: number;
|
|
288
|
+
signingAddress: string;
|
|
289
|
+
}
|
|
290
|
+
/** Verify message parameters */
|
|
291
|
+
export interface VerifyMessageParams {
|
|
292
|
+
message: string;
|
|
293
|
+
signature: string;
|
|
294
|
+
signingAddress: string;
|
|
295
|
+
identityAddress: string;
|
|
296
|
+
chainId?: string;
|
|
297
|
+
blockHeight?: number;
|
|
298
|
+
version?: 1 | 2;
|
|
299
|
+
}
|
|
300
|
+
/** Verify message result */
|
|
301
|
+
export interface VerifyMessageResult {
|
|
302
|
+
valid: boolean;
|
|
303
|
+
message: string;
|
|
304
|
+
identityAddress: string;
|
|
305
|
+
signingAddress: string;
|
|
306
|
+
chainId: string;
|
|
307
|
+
blockHeight: number;
|
|
308
|
+
version: number;
|
|
309
|
+
}
|
|
310
|
+
/** Re-export CurrencyType from currency/classify */
|
|
311
|
+
export type { CurrencyType } from '../currency/classify.js';
|
|
312
|
+
/** Balance for a single currency on an address */
|
|
313
|
+
export interface CurrencyBalance {
|
|
314
|
+
currencyId: string;
|
|
315
|
+
currencyName: string;
|
|
316
|
+
ticker: string;
|
|
317
|
+
confirmed: number;
|
|
318
|
+
unconfirmed: number;
|
|
319
|
+
total: number;
|
|
320
|
+
type: import('../currency/classify.js').CurrencyType;
|
|
321
|
+
}
|
|
322
|
+
/** Direction of a transaction relative to the queried address */
|
|
323
|
+
export type TransactionDirection = 'received' | 'sent';
|
|
324
|
+
/** A single transaction in history */
|
|
325
|
+
export interface Transaction {
|
|
326
|
+
txid: string;
|
|
327
|
+
direction: TransactionDirection;
|
|
328
|
+
/** Amount in coin units (not satoshis) */
|
|
329
|
+
amount: number;
|
|
330
|
+
confirmations: number;
|
|
331
|
+
/** Unix timestamp in seconds */
|
|
332
|
+
timestamp: number;
|
|
333
|
+
blockHeight: number;
|
|
334
|
+
}
|
|
335
|
+
/** Parsed VerusID identity */
|
|
336
|
+
export interface VerusIdentity {
|
|
337
|
+
/** i-address */
|
|
338
|
+
id: string;
|
|
339
|
+
name: string;
|
|
340
|
+
fullyQualifiedName: string;
|
|
341
|
+
primaryAddresses: string[];
|
|
342
|
+
minSignatures: number;
|
|
343
|
+
revocationAuthority: string;
|
|
344
|
+
recoveryAuthority: string;
|
|
345
|
+
status: 'active' | 'revoked' | 'locked' | 'pending';
|
|
346
|
+
contentMap: Record<string, string>;
|
|
347
|
+
blockHeight: number;
|
|
348
|
+
}
|
|
349
|
+
/** Conversion estimate result */
|
|
350
|
+
export interface ConversionQuote {
|
|
351
|
+
fromCurrency: string;
|
|
352
|
+
toCurrency: string;
|
|
353
|
+
fromAmount: number;
|
|
354
|
+
toAmount: number;
|
|
355
|
+
estimatedOutput: number;
|
|
356
|
+
fee: number;
|
|
357
|
+
via?: string;
|
|
358
|
+
}
|
|
359
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,oEAAoE;AACpE,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wCAAwC;AACxC,MAAM,WAAW,WAAY,SAAQ,IAAI;IACvC,0CAA0C;IAC1C,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,+BAA+B;AAC/B,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,QAAQ,EAAE,IAAI,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AAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IACpD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,iCAAiC;AACjC,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* SHA256d (double SHA-256) of one or more buffers
|
|
6
|
+
*/
|
|
7
|
+
export declare function sha256d(...buffers: Buffer[]): Buffer;
|
|
8
|
+
/**
|
|
9
|
+
* Write a Bitcoin-style compactsize integer to a buffer
|
|
10
|
+
*/
|
|
11
|
+
export declare function writeCompactSize(value: number): Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Decode an i-address to its 20-byte hash
|
|
14
|
+
*/
|
|
15
|
+
export declare function iAddressToHash(iAddress: string): Buffer;
|
|
16
|
+
/** Convert coin units to satoshis */
|
|
17
|
+
export declare function toSatoshis(coins: number): number;
|
|
18
|
+
/** Convert satoshis to coin units */
|
|
19
|
+
export declare function toCoins(satoshis: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Convert an R-address or P2SH address to a scriptPubKey Buffer
|
|
22
|
+
*/
|
|
23
|
+
export declare function addressToScriptPubKey(address: string): Buffer;
|
|
24
|
+
/** One consumed input of a signed transaction, in `txid`/`vout` form. */
|
|
25
|
+
export interface DecodedInput {
|
|
26
|
+
txid: string;
|
|
27
|
+
vout: number;
|
|
28
|
+
}
|
|
29
|
+
/** One output of a signed transaction. `address` is null for smart outputs. */
|
|
30
|
+
export interface DecodedOutput {
|
|
31
|
+
valueSat: number;
|
|
32
|
+
scriptHex: string;
|
|
33
|
+
/** Base58 address when the script is plain P2PKH/P2SH, else null. */
|
|
34
|
+
address: string | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decode a signed transaction hex into the facts a wallet ledger needs:
|
|
38
|
+
* txid, the exact outpoints consumed, and the outputs (with addresses where
|
|
39
|
+
* the script is plain P2PKH/P2SH). Wallets use this to record spent
|
|
40
|
+
* outpoints and locate their own change output without re-implementing
|
|
41
|
+
* transaction parsing.
|
|
42
|
+
*/
|
|
43
|
+
export declare function summarizeSignedTransaction(hex: string, network: 'mainnet' | 'testnet'): {
|
|
44
|
+
txid: string;
|
|
45
|
+
inputs: DecodedInput[];
|
|
46
|
+
outputs: DecodedOutput[];
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,qCAAqC;AACrC,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,qCAAqC;AACrC,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAwB7D;AAID,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,GAAG,SAAS,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,YAAY,EAAE,CAAC;IAAC,OAAO,EAAE,aAAa,EAAE,CAAA;CAAE,CAqCpE"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared utility functions
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sha256d = sha256d;
|
|
10
|
+
exports.writeCompactSize = writeCompactSize;
|
|
11
|
+
exports.iAddressToHash = iAddressToHash;
|
|
12
|
+
exports.toSatoshis = toSatoshis;
|
|
13
|
+
exports.toCoins = toCoins;
|
|
14
|
+
exports.addressToScriptPubKey = addressToScriptPubKey;
|
|
15
|
+
exports.summarizeSignedTransaction = summarizeSignedTransaction;
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
const bs58check_1 = __importDefault(require("bs58check"));
|
|
18
|
+
const verus_typescript_primitives_1 = require("verus-typescript-primitives");
|
|
19
|
+
const index_js_1 = require("../constants/index.js");
|
|
20
|
+
/**
|
|
21
|
+
* SHA256d (double SHA-256) of one or more buffers
|
|
22
|
+
*/
|
|
23
|
+
function sha256d(...buffers) {
|
|
24
|
+
const first = (0, crypto_1.createHash)('sha256');
|
|
25
|
+
for (const buf of buffers) {
|
|
26
|
+
first.update(buf);
|
|
27
|
+
}
|
|
28
|
+
return (0, crypto_1.createHash)('sha256').update(first.digest()).digest();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Write a Bitcoin-style compactsize integer to a buffer
|
|
32
|
+
*/
|
|
33
|
+
function writeCompactSize(value) {
|
|
34
|
+
if (value < 253) {
|
|
35
|
+
const buf = Buffer.alloc(1);
|
|
36
|
+
buf.writeUInt8(value, 0);
|
|
37
|
+
return buf;
|
|
38
|
+
}
|
|
39
|
+
else if (value <= 0xffff) {
|
|
40
|
+
const buf = Buffer.alloc(3);
|
|
41
|
+
buf.writeUInt8(253, 0);
|
|
42
|
+
buf.writeUInt16LE(value, 1);
|
|
43
|
+
return buf;
|
|
44
|
+
}
|
|
45
|
+
else if (value <= 0xffffffff) {
|
|
46
|
+
const buf = Buffer.alloc(5);
|
|
47
|
+
buf.writeUInt8(254, 0);
|
|
48
|
+
buf.writeUInt32LE(value, 1);
|
|
49
|
+
return buf;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('CompactSize value too large');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Decode an i-address to its 20-byte hash
|
|
57
|
+
*/
|
|
58
|
+
function iAddressToHash(iAddress) {
|
|
59
|
+
const { hash } = (0, verus_typescript_primitives_1.fromBase58Check)(iAddress);
|
|
60
|
+
return Buffer.from(hash);
|
|
61
|
+
}
|
|
62
|
+
/** Convert coin units to satoshis */
|
|
63
|
+
function toSatoshis(coins) {
|
|
64
|
+
return Math.round(coins * 1e8);
|
|
65
|
+
}
|
|
66
|
+
/** Convert satoshis to coin units */
|
|
67
|
+
function toCoins(satoshis) {
|
|
68
|
+
return satoshis / 1e8;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Convert an R-address or P2SH address to a scriptPubKey Buffer
|
|
72
|
+
*/
|
|
73
|
+
function addressToScriptPubKey(address) {
|
|
74
|
+
const decoded = bs58check_1.default.decode(address);
|
|
75
|
+
const prefix = decoded[0];
|
|
76
|
+
const hash = decoded.slice(1);
|
|
77
|
+
if (prefix === 0x3c) {
|
|
78
|
+
// P2PKH (R-address)
|
|
79
|
+
return Buffer.concat([
|
|
80
|
+
Buffer.from([0x76, 0xa9, 0x14]), // OP_DUP OP_HASH160 PUSH20
|
|
81
|
+
hash,
|
|
82
|
+
Buffer.from([0x88, 0xac]), // OP_EQUALVERIFY OP_CHECKSIG
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
else if (prefix === 0x55) {
|
|
86
|
+
// P2SH
|
|
87
|
+
return Buffer.concat([
|
|
88
|
+
Buffer.from([0xa9, 0x14]), // OP_HASH160 PUSH20
|
|
89
|
+
hash,
|
|
90
|
+
Buffer.from([0x87]), // OP_EQUAL
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error(`Unsupported address prefix: 0x${prefix.toString(16)}. Use sendCurrency for i-address destinations.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decode a signed transaction hex into the facts a wallet ledger needs:
|
|
99
|
+
* txid, the exact outpoints consumed, and the outputs (with addresses where
|
|
100
|
+
* the script is plain P2PKH/P2SH). Wallets use this to record spent
|
|
101
|
+
* outpoints and locate their own change output without re-implementing
|
|
102
|
+
* transaction parsing.
|
|
103
|
+
*/
|
|
104
|
+
function summarizeSignedTransaction(hex, network) {
|
|
105
|
+
// Lazy require keeps utils' import graph light for non-tx consumers.
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
107
|
+
const { Transaction, address: addressLib, networks, smarttxs } = require('@bitgo/utxo-lib');
|
|
108
|
+
const net = network === 'testnet' ? networks.verustest : networks.verus;
|
|
109
|
+
const chainId = network === 'testnet' ? index_js_1.NETWORK_CONFIG.testnet.chainId : index_js_1.NETWORK_CONFIG.mainnet.chainId;
|
|
110
|
+
const tx = Transaction.fromHex(hex, net);
|
|
111
|
+
const inputs = tx.ins.map((input) => ({
|
|
112
|
+
txid: Buffer.from(input.hash).reverse().toString('hex'),
|
|
113
|
+
vout: input.index,
|
|
114
|
+
}));
|
|
115
|
+
const outputs = tx.outs.map((out) => {
|
|
116
|
+
let addr = null;
|
|
117
|
+
try {
|
|
118
|
+
addr = addressLib.fromOutputScript(out.script, net);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Smart CC output. Recover the address ONLY for pure payment outputs
|
|
122
|
+
// (all OptCCParams are EVAL_NONE, exactly one destination — e.g. P2ID
|
|
123
|
+
// change back to an identity). Structural outputs (name commitments,
|
|
124
|
+
// identity definitions, reservations) deliberately stay null: callers
|
|
125
|
+
// like the registration flow LOCATE them by address === null.
|
|
126
|
+
try {
|
|
127
|
+
const unpacked = smarttxs.unpackOutput({ script: out.script, value: out.value }, chainId);
|
|
128
|
+
const evalCodes = (unpacked.params ?? []).map((p) => p.eval);
|
|
129
|
+
if (unpacked.destinations.length === 1 && evalCodes.every((code) => code === 0)) {
|
|
130
|
+
addr = unpacked.destinations[0];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
addr = null; // exotic CC output — no address form
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { valueSat: out.value, scriptHex: out.script.toString('hex'), address: addr };
|
|
138
|
+
});
|
|
139
|
+
return { txid: tx.getId(), inputs, outputs };
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAUH,0BAMC;AAKD,4CAkBC;A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
|
|
5
|
+
* calculates fees, and determines change outputs.
|
|
6
|
+
*/
|
|
7
|
+
import type { Utxo, DecodedUtxo, SelectionResult } from '../types/index.js';
|
|
8
|
+
export type { Utxo, DecodedUtxo, SelectionResult };
|
|
9
|
+
/**
|
|
10
|
+
* Decode a UTXO's script to extract currency values
|
|
11
|
+
*/
|
|
12
|
+
export declare function decodeUtxo(utxo: Utxo, systemId: string): DecodedUtxo;
|
|
13
|
+
/**
|
|
14
|
+
* Estimate transaction fee based on input/output counts
|
|
15
|
+
*/
|
|
16
|
+
export declare function estimateFee(numInputs: number, numOutputs: number, feePerKb?: number, hasSmartOutputs?: boolean): number;
|
|
17
|
+
/**
|
|
18
|
+
* Select UTXOs to cover required amounts
|
|
19
|
+
*/
|
|
20
|
+
export declare function selectUtxos(utxos: Utxo[], requiredNative: number, requiredCurrencies?: Map<string, number>, numOutputs?: number, systemId?: string, feePerKb?: number, hasSmartOutputs?: boolean): SelectionResult;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utxo/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAK5E,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;AAQnD;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAwBpE;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,MAA2B,EACrC,eAAe,GAAE,OAAe,GAC/B,MAAM,CAKR;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,EAAE,MAAM,EACtB,kBAAkB,GAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAa,EACnD,UAAU,GAAE,MAAU,EACtB,QAAQ,GAAE,MAAuC,EACjD,QAAQ,GAAE,MAA2B,EACrC,eAAe,GAAE,OAAe,GAC/B,eAAe,CA4GjB"}
|