ecash-lib 0.1.0-rc2 → 0.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 (91) hide show
  1. package/README.md +73 -15
  2. package/dist/ecc.d.ts +6 -2
  3. package/dist/ecc.d.ts.map +1 -1
  4. package/dist/ecc.js +9 -6
  5. package/dist/ecc.js.map +1 -1
  6. package/dist/ffi/ecash_lib_wasm_bg.wasm +0 -0
  7. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm +0 -0
  8. package/dist/ffi/ecash_lib_wasm_bg_browser.wasm.d.ts +16 -0
  9. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm +0 -0
  10. package/dist/ffi/ecash_lib_wasm_bg_nodejs.wasm.d.ts +16 -0
  11. package/dist/ffi/ecash_lib_wasm_browser.d.ts +90 -0
  12. package/dist/ffi/ecash_lib_wasm_browser.js +340 -0
  13. package/dist/ffi/ecash_lib_wasm_nodejs.d.ts +50 -0
  14. package/dist/ffi/ecash_lib_wasm_nodejs.js +265 -0
  15. package/dist/hash.d.ts +10 -4
  16. package/dist/hash.d.ts.map +1 -1
  17. package/dist/hash.js +20 -4
  18. package/dist/hash.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +37 -21
  22. package/dist/index.js.map +1 -1
  23. package/dist/indexBrowser.d.ts +3 -0
  24. package/dist/indexBrowser.d.ts.map +1 -0
  25. package/dist/indexBrowser.js +22 -0
  26. package/dist/indexBrowser.js.map +1 -0
  27. package/dist/indexNodeJs.d.ts +3 -0
  28. package/dist/indexNodeJs.d.ts.map +1 -0
  29. package/dist/indexNodeJs.js +22 -0
  30. package/dist/indexNodeJs.js.map +1 -0
  31. package/dist/initBrowser.d.ts +3 -0
  32. package/dist/initBrowser.d.ts.map +1 -0
  33. package/dist/initBrowser.js +44 -0
  34. package/dist/initBrowser.js.map +1 -0
  35. package/dist/initNodeJs.d.ts +3 -0
  36. package/dist/initNodeJs.d.ts.map +1 -0
  37. package/dist/initNodeJs.js +43 -0
  38. package/dist/initNodeJs.js.map +1 -0
  39. package/dist/io/bytes.js +5 -1
  40. package/dist/io/bytes.js.map +1 -1
  41. package/dist/io/hex.js +11 -4
  42. package/dist/io/hex.js.map +1 -1
  43. package/dist/io/int.js +2 -1
  44. package/dist/io/int.js.map +1 -1
  45. package/dist/io/str.d.ts +2 -0
  46. package/dist/io/str.d.ts.map +1 -1
  47. package/dist/io/str.js +11 -1
  48. package/dist/io/str.js.map +1 -1
  49. package/dist/io/varsize.js +7 -2
  50. package/dist/io/varsize.js.map +1 -1
  51. package/dist/io/writer.js +2 -1
  52. package/dist/io/writer.js.map +1 -1
  53. package/dist/io/writerbytes.js +5 -1
  54. package/dist/io/writerbytes.js.map +1 -1
  55. package/dist/io/writerlength.js +5 -1
  56. package/dist/io/writerlength.js.map +1 -1
  57. package/dist/op.js +23 -16
  58. package/dist/op.js.map +1 -1
  59. package/dist/opcode.js +126 -121
  60. package/dist/opcode.js.map +1 -1
  61. package/dist/script.d.ts +1 -0
  62. package/dist/script.d.ts.map +1 -1
  63. package/dist/script.js +34 -25
  64. package/dist/script.js.map +1 -1
  65. package/dist/sigHashType.js +23 -19
  66. package/dist/sigHashType.js.map +1 -1
  67. package/dist/test/testRunner.d.ts +1 -1
  68. package/dist/test/testRunner.d.ts.map +1 -1
  69. package/dist/test/testRunner.js +51 -26
  70. package/dist/test/testRunner.js.map +1 -1
  71. package/dist/token/alp.js +43 -36
  72. package/dist/token/alp.js.map +1 -1
  73. package/dist/token/common.js +8 -5
  74. package/dist/token/common.js.map +1 -1
  75. package/dist/token/empp.js +13 -9
  76. package/dist/token/empp.js.map +1 -1
  77. package/dist/token/slp.js +61 -53
  78. package/dist/token/slp.js.map +1 -1
  79. package/dist/tx.d.ts +2 -0
  80. package/dist/tx.d.ts.map +1 -1
  81. package/dist/tx.js +39 -21
  82. package/dist/tx.js.map +1 -1
  83. package/dist/txBuilder.js +33 -25
  84. package/dist/txBuilder.js.map +1 -1
  85. package/dist/unsignedTx.js +34 -29
  86. package/dist/unsignedTx.js.map +1 -1
  87. package/package.json +3 -3
  88. package/tsconfig.json +1 -2
  89. package/tests/alp.test.ts +0 -383
  90. package/tests/slp.test.ts +0 -1124
  91. package/tests/txBuilder.test.ts +0 -562
package/tests/alp.test.ts DELETED
@@ -1,383 +0,0 @@
1
- // Copyright (c) 2024 The Bitcoin developers
2
- // Distributed under the MIT software license, see the accompanying
3
- // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
-
5
- import { expect } from 'chai';
6
-
7
- import { ChronikClientNode } from 'chronik-client';
8
-
9
- import {
10
- ALL_BIP143,
11
- Ecc,
12
- P2PKHSignatory,
13
- Script,
14
- TxBuilder,
15
- fromHex,
16
- initWasm,
17
- shaRmd160,
18
- toHex,
19
- } from '../src/index.js';
20
- import { TestRunner } from '../src/test/testRunner.js';
21
- import {
22
- ALP_STANDARD,
23
- alpGenesis,
24
- alpMint,
25
- alpSend,
26
- } from '../src/token/alp.js';
27
- import { emppScript } from '../src/token/empp.js';
28
-
29
- const NUM_COINS = 500;
30
- const COIN_VALUE = 100000;
31
-
32
- const ALP_TOKEN_TYPE_STANDARD = {
33
- number: 0,
34
- protocol: 'ALP',
35
- type: 'ALP_TOKEN_TYPE_STANDARD',
36
- };
37
-
38
- describe('ALP', () => {
39
- let runner: TestRunner;
40
- let chronik: ChronikClientNode;
41
- let ecc: Ecc;
42
-
43
- before(async () => {
44
- runner = await TestRunner.setup();
45
- chronik = runner.chronik;
46
- ecc = runner.ecc;
47
- await initWasm();
48
- await runner.setupCoins(NUM_COINS, COIN_VALUE);
49
- });
50
-
51
- after(() => {
52
- runner.stop();
53
- });
54
-
55
- it('TxBuilder P2PKH ALP', async () => {
56
- const sk1 = fromHex('11'.repeat(32));
57
- const pk1 = ecc.derivePubkey(sk1);
58
- const pkh1 = shaRmd160(pk1);
59
- const p2pkh1 = Script.p2pkh(pkh1);
60
-
61
- const sk2 = fromHex('22'.repeat(32));
62
- const pk2 = ecc.derivePubkey(sk2);
63
- const pkh2 = shaRmd160(pk2);
64
- const p2pkh2 = Script.p2pkh(pkh2);
65
-
66
- const sk3 = fromHex('33'.repeat(32));
67
- const pk3 = ecc.derivePubkey(sk3);
68
- const pkh3 = shaRmd160(pk3);
69
- const p2pkh3 = Script.p2pkh(pkh3);
70
-
71
- const sk4 = fromHex('44'.repeat(32));
72
- const pk4 = ecc.derivePubkey(sk4);
73
- const pkh4 = shaRmd160(pk4);
74
- const p2pkh4 = Script.p2pkh(pkh4);
75
-
76
- await runner.sendToScript(50000, p2pkh1);
77
-
78
- const utxos = await chronik.script('p2pkh', toHex(pkh1)).utxos();
79
- expect(utxos.utxos.length).to.equal(1);
80
- const utxo = utxos.utxos[0];
81
-
82
- const txBuildGenesis = new TxBuilder({
83
- inputs: [
84
- {
85
- input: {
86
- prevOut: utxo.outpoint,
87
- signData: {
88
- value: utxo.value,
89
- outputScript: p2pkh1,
90
- },
91
- },
92
- signatory: P2PKHSignatory(sk1, pk1, ALL_BIP143),
93
- },
94
- ],
95
- outputs: [
96
- {
97
- value: 0,
98
- script: emppScript([
99
- alpGenesis(
100
- ALP_STANDARD,
101
- {
102
- tokenTicker: 'ALP TOKEN',
103
- tokenName: 'ALP Token Name',
104
- url: 'https://example.com',
105
- data: fromHex('01020304'),
106
- authPubkey: '03040506',
107
- decimals: 4,
108
- },
109
- {
110
- amounts: [2000, 2],
111
- numBatons: 1,
112
- },
113
- ),
114
- ]),
115
- },
116
- { value: 10000, script: p2pkh2 },
117
- { value: 10000, script: p2pkh1 },
118
- { value: 10000, script: p2pkh1 },
119
- ],
120
- });
121
- const genesisTx = txBuildGenesis.sign(ecc);
122
- const genesisTxid = (await chronik.broadcastTx(genesisTx.ser())).txid;
123
- const tokenId = genesisTxid;
124
-
125
- expect(await chronik.token(genesisTxid)).to.deep.equal({
126
- tokenId,
127
- tokenType: ALP_TOKEN_TYPE_STANDARD,
128
- genesisInfo: {
129
- tokenTicker: 'ALP TOKEN',
130
- tokenName: 'ALP Token Name',
131
- url: 'https://example.com',
132
- data: fromHex('01020304'),
133
- authPubkey: '03040506',
134
- decimals: 4,
135
- },
136
- timeFirstSeen: 1300000000,
137
- });
138
-
139
- const utxos2 = await chronik.script('p2pkh', toHex(pkh2)).utxos();
140
- expect(utxos2.utxos).to.deep.equal([
141
- {
142
- outpoint: {
143
- txid: genesisTxid,
144
- outIdx: 1,
145
- },
146
- blockHeight: -1,
147
- isCoinbase: false,
148
- value: 10000,
149
- isFinal: false,
150
- token: {
151
- amount: '2000',
152
- isMintBaton: false,
153
- tokenId: tokenId,
154
- tokenType: ALP_TOKEN_TYPE_STANDARD,
155
- },
156
- },
157
- ]);
158
-
159
- const txBuildMint = new TxBuilder({
160
- inputs: [
161
- {
162
- input: {
163
- prevOut: {
164
- txid: genesisTxid,
165
- outIdx: 3,
166
- },
167
- signData: {
168
- value: 10000,
169
- outputScript: p2pkh1,
170
- },
171
- },
172
- signatory: P2PKHSignatory(sk1, pk1, ALL_BIP143),
173
- },
174
- ],
175
- outputs: [
176
- {
177
- value: 0,
178
- script: emppScript([
179
- alpMint(tokenId, ALP_STANDARD, {
180
- amounts: [500],
181
- numBatons: 1,
182
- }),
183
- ]),
184
- },
185
- { value: 546, script: p2pkh1 },
186
- { value: 546, script: p2pkh3 },
187
- ],
188
- });
189
- const mintTx = txBuildMint.sign(ecc);
190
- const mintTxid = (await chronik.broadcastTx(mintTx.ser())).txid;
191
-
192
- const utxos3 = await chronik.script('p2pkh', toHex(pkh3)).utxos();
193
- expect(utxos3.utxos).to.deep.equal([
194
- {
195
- outpoint: {
196
- txid: mintTxid,
197
- outIdx: 2,
198
- },
199
- blockHeight: -1,
200
- isCoinbase: false,
201
- value: 546,
202
- isFinal: false,
203
- token: {
204
- amount: '0',
205
- isMintBaton: true,
206
- tokenId: tokenId,
207
- tokenType: ALP_TOKEN_TYPE_STANDARD,
208
- },
209
- },
210
- ]);
211
-
212
- const txBuildMulti = new TxBuilder({
213
- inputs: [
214
- {
215
- input: {
216
- prevOut: {
217
- txid: mintTxid,
218
- outIdx: 1,
219
- },
220
- signData: {
221
- value: 546,
222
- outputScript: p2pkh1,
223
- },
224
- },
225
- signatory: P2PKHSignatory(sk1, pk1, ALL_BIP143),
226
- },
227
- {
228
- input: {
229
- prevOut: {
230
- txid: genesisTxid,
231
- outIdx: 1,
232
- },
233
- signData: {
234
- value: 10000,
235
- outputScript: p2pkh2,
236
- },
237
- },
238
- signatory: P2PKHSignatory(sk2, pk2, ALL_BIP143),
239
- },
240
- ],
241
- outputs: [
242
- {
243
- value: 0,
244
- script: emppScript([
245
- alpGenesis(
246
- ALP_STANDARD,
247
- {},
248
- {
249
- amounts: [100, 0],
250
- numBatons: 1,
251
- },
252
- ),
253
- // OK to push 01 (not encoded as OP_1)
254
- fromHex('01'),
255
- alpSend(tokenId, ALP_STANDARD, [0, 1000, 0, 1500]),
256
- ]),
257
- },
258
- { value: 546, script: p2pkh1 },
259
- { value: 546, script: p2pkh2 },
260
- { value: 546, script: p2pkh3 },
261
- { value: 546, script: p2pkh4 },
262
- ],
263
- });
264
- const multiTx = txBuildMulti.sign(ecc);
265
- const multiTxid = (await chronik.broadcastTx(multiTx.ser())).txid;
266
-
267
- const multiProtoTx = await chronik.tx(multiTxid);
268
- expect(multiProtoTx).to.deep.equal({
269
- txid: multiTxid,
270
- version: 2,
271
- inputs: [
272
- {
273
- inputScript: toHex(multiTx.inputs[0].script!.bytecode),
274
- outputScript: toHex(p2pkh1.bytecode),
275
- prevOut: multiTx.inputs[0].prevOut,
276
- sequenceNo: 0xffffffff,
277
- token: {
278
- amount: '500',
279
- entryIdx: 1,
280
- isMintBaton: false,
281
- tokenId: tokenId,
282
- tokenType: ALP_TOKEN_TYPE_STANDARD,
283
- },
284
- value: 546,
285
- },
286
- {
287
- inputScript: toHex(multiTx.inputs[1].script!.bytecode),
288
- outputScript: toHex(p2pkh2.bytecode),
289
- prevOut: multiTx.inputs[1].prevOut,
290
- sequenceNo: 0xffffffff,
291
- token: {
292
- amount: '2000',
293
- entryIdx: 1,
294
- isMintBaton: false,
295
- tokenId: tokenId,
296
- tokenType: ALP_TOKEN_TYPE_STANDARD,
297
- },
298
- value: 10000,
299
- },
300
- ],
301
- outputs: [
302
- {
303
- value: 0,
304
- outputScript: toHex(multiTx.outputs[0].script.bytecode),
305
- },
306
- {
307
- outputScript: toHex(p2pkh1.bytecode),
308
- token: {
309
- amount: '100',
310
- entryIdx: 0,
311
- isMintBaton: false,
312
- tokenId: multiTxid,
313
- tokenType: ALP_TOKEN_TYPE_STANDARD,
314
- },
315
- value: 546,
316
- },
317
- {
318
- outputScript: toHex(p2pkh2.bytecode),
319
- token: {
320
- amount: '1000',
321
- entryIdx: 1,
322
- isMintBaton: false,
323
- tokenId: tokenId,
324
- tokenType: ALP_TOKEN_TYPE_STANDARD,
325
- },
326
- value: 546,
327
- },
328
- {
329
- outputScript: toHex(p2pkh3.bytecode),
330
- token: {
331
- amount: '0',
332
- entryIdx: 0,
333
- isMintBaton: true,
334
- tokenId: multiTxid,
335
- tokenType: ALP_TOKEN_TYPE_STANDARD,
336
- },
337
- value: 546,
338
- },
339
- {
340
- outputScript: toHex(p2pkh4.bytecode),
341
- token: {
342
- amount: '1500',
343
- entryIdx: 1,
344
- isMintBaton: false,
345
- tokenId: tokenId,
346
- tokenType: ALP_TOKEN_TYPE_STANDARD,
347
- },
348
- value: 546,
349
- },
350
- ],
351
- lockTime: 0,
352
- timeFirstSeen: 1300000000,
353
- size: multiTx.serSize(),
354
- isCoinbase: false,
355
- tokenEntries: [
356
- {
357
- actualBurnAmount: '0',
358
- burnSummary: '',
359
- burnsMintBatons: false,
360
- failedColorings: [],
361
- intentionalBurn: '0',
362
- isInvalid: false,
363
- tokenId: multiTxid,
364
- tokenType: ALP_TOKEN_TYPE_STANDARD,
365
- txType: 'GENESIS',
366
- },
367
- {
368
- actualBurnAmount: '0',
369
- burnSummary: '',
370
- burnsMintBatons: false,
371
- failedColorings: [],
372
- intentionalBurn: '0',
373
- isInvalid: false,
374
- tokenId: tokenId,
375
- tokenType: ALP_TOKEN_TYPE_STANDARD,
376
- txType: 'SEND',
377
- },
378
- ],
379
- tokenFailedParsings: [],
380
- tokenStatus: 'TOKEN_STATUS_NORMAL',
381
- });
382
- });
383
- });