@vbyte/btc-dev 1.0.15 → 1.1.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.
Files changed (48) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/lib/meta/locktime.d.ts +1 -1
  4. package/dist/lib/meta/locktime.js +5 -5
  5. package/dist/lib/meta/ref.d.ts +1 -1
  6. package/dist/lib/meta/ref.js +6 -6
  7. package/dist/lib/meta/scribe.d.ts +5 -3
  8. package/dist/lib/meta/scribe.js +21 -18
  9. package/dist/lib/meta/sequence.d.ts +1 -1
  10. package/dist/lib/meta/sequence.js +5 -5
  11. package/dist/lib/script/decode.d.ts +2 -1
  12. package/dist/lib/script/encode.d.ts +1 -1
  13. package/dist/lib/script/encode.js +3 -3
  14. package/dist/lib/taproot/cblock.js +1 -0
  15. package/dist/main.cjs +100 -4036
  16. package/dist/main.cjs.map +1 -1
  17. package/dist/module.mjs +99 -4034
  18. package/dist/module.mjs.map +1 -1
  19. package/dist/package.json +5 -9
  20. package/dist/schema/tx.d.ts +12 -12
  21. package/dist/script.js +8 -8
  22. package/dist/script.js.map +1 -1
  23. package/dist/types/taproot.d.ts +1 -0
  24. package/package.json +5 -9
  25. package/src/index.ts +0 -1
  26. package/src/lib/meta/locktime.ts +1 -1
  27. package/src/lib/meta/ref.ts +1 -1
  28. package/src/lib/meta/scribe.ts +29 -24
  29. package/src/lib/meta/sequence.ts +1 -1
  30. package/src/lib/script/decode.ts +2 -2
  31. package/src/lib/script/encode.ts +4 -5
  32. package/src/lib/taproot/cblock.ts +1 -0
  33. package/src/types/taproot.ts +1 -0
  34. package/dist/lib/psbt/encoder.d.ts +0 -5
  35. package/dist/lib/psbt/encoder.js +0 -21
  36. package/dist/lib/psbt/index.d.ts +0 -4
  37. package/dist/lib/psbt/index.js +0 -4
  38. package/dist/lib/psbt/meta.d.ts +0 -3
  39. package/dist/lib/psbt/meta.js +0 -11
  40. package/dist/lib/psbt/util.d.ts +0 -5
  41. package/dist/lib/psbt/util.js +0 -44
  42. package/dist/lib/psbt/validate.d.ts +0 -2
  43. package/dist/lib/psbt/validate.js +0 -11
  44. package/src/lib/psbt/encoder.ts +0 -24
  45. package/src/lib/psbt/index.ts +0 -4
  46. package/src/lib/psbt/meta.ts +0 -15
  47. package/src/lib/psbt/util.ts +0 -62
  48. package/src/lib/psbt/validate.ts +0 -18
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * as ADDRESS from './lib/address/index.js';
2
2
  export * as META from './lib/meta/index.js';
3
- export * as PSBT from './lib/psbt/index.js';
4
3
  export * as SCRIPT from './lib/script/index.js';
5
4
  export * as SIGHASH from './lib/sighash/index.js';
6
5
  export * as SIGNER from './lib/signer/index.js';
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * as ADDRESS from './lib/address/index.js';
2
2
  export * as META from './lib/meta/index.js';
3
- export * as PSBT from './lib/psbt/index.js';
4
3
  export * as SCRIPT from './lib/script/index.js';
5
4
  export * as SIGHASH from './lib/sighash/index.js';
6
5
  export * as SIGNER from './lib/signer/index.js';
@@ -1,5 +1,5 @@
1
1
  import type { LocktimeData } from '../../types/index.js';
2
- export declare namespace LocktimeUtil {
2
+ export declare namespace LocktimeField {
3
3
  const encode: typeof encode_locktime;
4
4
  const decode: typeof decode_locktime;
5
5
  }
@@ -1,10 +1,10 @@
1
1
  import { Assert } from '@vbyte/micro-lib';
2
2
  const LOCKTIME_THRESHOLD = 500000000;
3
- export var LocktimeUtil;
4
- (function (LocktimeUtil) {
5
- LocktimeUtil.encode = encode_locktime;
6
- LocktimeUtil.decode = decode_locktime;
7
- })(LocktimeUtil || (LocktimeUtil = {}));
3
+ export var LocktimeField;
4
+ (function (LocktimeField) {
5
+ LocktimeField.encode = encode_locktime;
6
+ LocktimeField.decode = decode_locktime;
7
+ })(LocktimeField || (LocktimeField = {}));
8
8
  export function encode_locktime(locktime) {
9
9
  switch (locktime.type) {
10
10
  case 'timelock':
@@ -1,4 +1,4 @@
1
- export declare namespace RefEncoder {
1
+ export declare namespace RefPointer {
2
2
  const outpoint: {
3
3
  encode: typeof encode_outpoint;
4
4
  decode: typeof decode_outpoint;
@@ -1,24 +1,24 @@
1
- export var RefEncoder;
2
- (function (RefEncoder) {
3
- RefEncoder.outpoint = {
1
+ export var RefPointer;
2
+ (function (RefPointer) {
3
+ RefPointer.outpoint = {
4
4
  encode: encode_outpoint,
5
5
  decode: decode_outpoint,
6
6
  verify: verify_outpoint,
7
7
  assert: assert_outpoint,
8
8
  };
9
- RefEncoder.record_id = {
9
+ RefPointer.record_id = {
10
10
  encode: encode_inscription_id,
11
11
  decode: decode_inscription_id,
12
12
  verify: verify_inscription_id,
13
13
  assert: assert_inscription_id,
14
14
  };
15
- RefEncoder.rune_id = {
15
+ RefPointer.rune_id = {
16
16
  encode: encode_rune_id,
17
17
  decode: decode_rune_id,
18
18
  verify: verify_rune_id,
19
19
  assert: assert_rune_id,
20
20
  };
21
- })(RefEncoder || (RefEncoder = {}));
21
+ })(RefPointer || (RefPointer = {}));
22
22
  function encode_inscription_id(txid, order = 0) {
23
23
  return `${txid}i${order}`;
24
24
  }
@@ -1,7 +1,9 @@
1
+ import { Buff, Bytes } from '@vbyte/buff';
1
2
  import type { InscriptionData } from '../../types/index.js';
2
- export declare namespace ScribeEncoder {
3
+ export declare namespace InscriptionUtil {
4
+ type Type = InscriptionData;
3
5
  const encode: typeof encode_inscription;
4
6
  const decode: typeof decode_inscription;
5
7
  }
6
- export declare function decode_inscription(script: string): InscriptionData[];
7
- export declare function encode_inscription(data: InscriptionData[]): string;
8
+ export declare function decode_inscription(script: Bytes): InscriptionData[];
9
+ export declare function encode_inscription(data: InscriptionData[]): Buff;
@@ -5,17 +5,17 @@ import { decode_script } from '../../lib/script/decode.js';
5
5
  const _0n = BigInt(0);
6
6
  const _1n = BigInt(1);
7
7
  const _26n = BigInt(26);
8
- export var ScribeEncoder;
9
- (function (ScribeEncoder) {
10
- ScribeEncoder.encode = encode_inscription;
11
- ScribeEncoder.decode = decode_inscription;
12
- })(ScribeEncoder || (ScribeEncoder = {}));
8
+ export var InscriptionUtil;
9
+ (function (InscriptionUtil) {
10
+ InscriptionUtil.encode = encode_inscription;
11
+ InscriptionUtil.decode = decode_inscription;
12
+ })(InscriptionUtil || (InscriptionUtil = {}));
13
13
  export function decode_inscription(script) {
14
14
  const envelopes = parse_envelopes(script);
15
15
  return envelopes.map(parse_record);
16
16
  }
17
17
  export function encode_inscription(data) {
18
- return data.map(create_envelope).join('');
18
+ return Buff.join(data.map(create_envelope));
19
19
  }
20
20
  function create_envelope(data) {
21
21
  let asm = ['OP_0', 'OP_IF', '6f7264'];
@@ -94,7 +94,7 @@ function parse_record(envelope) {
94
94
  i += 1;
95
95
  break;
96
96
  case 'OP_WITHIN':
97
- record.ref = envelope[i + 1];
97
+ record.ref = decode_bytes(envelope[i + 1]);
98
98
  i += 1;
99
99
  break;
100
100
  case 'OP_NOP':
@@ -108,6 +108,9 @@ function parse_record(envelope) {
108
108
  }
109
109
  return record;
110
110
  }
111
+ function decode_bytes(bytes) {
112
+ return Buff.bytes(bytes).hex;
113
+ }
111
114
  function encode_id(identifier) {
112
115
  Assert.ok(identifier.includes('i'), 'identifier must include an index');
113
116
  const parts = identifier.split('i');
@@ -116,8 +119,8 @@ function encode_id(identifier) {
116
119
  const txid = bytes.reverse().hex;
117
120
  return (idx !== 0) ? txid + Buff.num(idx).hex : txid;
118
121
  }
119
- function decode_id(hexstr) {
120
- const bytes = Buff.hex(hexstr);
122
+ function decode_id(identifier) {
123
+ const bytes = Buff.bytes(identifier);
121
124
  const idx = bytes.at(-1) ?? 0;
122
125
  const txid = bytes.slice(0, -1).reverse().hex;
123
126
  return txid + 'i' + String(idx);
@@ -125,14 +128,14 @@ function decode_id(hexstr) {
125
128
  function encode_pointer(pointer) {
126
129
  return Buff.num(pointer).reverse().hex;
127
130
  }
128
- function decode_pointer(hexstr) {
129
- return Buff.hex(hexstr).reverse().num;
131
+ function decode_pointer(bytes) {
132
+ return Buff.bytes(bytes).reverse().num;
130
133
  }
131
134
  function encode_label(label) {
132
135
  return Buff.str(label).hex;
133
136
  }
134
- function decode_label(hexstr) {
135
- return Buff.hex(hexstr).str;
137
+ function decode_label(label) {
138
+ return Buff.bytes(label).str;
136
139
  }
137
140
  function encode_content(content) {
138
141
  const bytes = Buff.is_hex(content)
@@ -152,9 +155,9 @@ function encode_content(content) {
152
155
  }
153
156
  return chunks;
154
157
  }
155
- function decode_content(hexstrs, type = 'hex') {
156
- const data = Buff.join(hexstrs);
157
- return (type === 'hex')
158
+ function decode_content(chunks, format = 'hex') {
159
+ const data = Buff.join(chunks);
160
+ return (format === 'hex')
158
161
  ? data.hex
159
162
  : data.str;
160
163
  }
@@ -172,8 +175,8 @@ function encode_rune_label(label) {
172
175
  big = big - _1n;
173
176
  return Buff.big(big).reverse().hex;
174
177
  }
175
- function decode_rune_label(hex) {
176
- let big = Buff.hex(hex).reverse().big;
178
+ function decode_rune_label(label) {
179
+ let big = Buff.bytes(label).reverse().big;
177
180
  big = big + _1n;
178
181
  let result = '';
179
182
  while (big > _0n) {
@@ -1,5 +1,5 @@
1
1
  import type { SequenceConfig, SequenceData } from '../../types/index.js';
2
- export declare namespace SequenceUtil {
2
+ export declare namespace SequenceField {
3
3
  const encode: typeof encode_sequence;
4
4
  const decode: typeof decode_sequence;
5
5
  }
@@ -3,11 +3,11 @@ const TIMELOCK_TYPE = 0x00400000;
3
3
  const TIMELOCK_VALUE_MASK = 0x0000FFFF;
4
4
  const TIMELOCK_VALUE_MAX = 0xFFFF;
5
5
  const TIMELOCK_GRANULARITY = 512;
6
- export var SequenceUtil;
7
- (function (SequenceUtil) {
8
- SequenceUtil.encode = encode_sequence;
9
- SequenceUtil.decode = decode_sequence;
10
- })(SequenceUtil || (SequenceUtil = {}));
6
+ export var SequenceField;
7
+ (function (SequenceField) {
8
+ SequenceField.encode = encode_sequence;
9
+ SequenceField.decode = decode_sequence;
10
+ })(SequenceField || (SequenceField = {}));
11
11
  export function encode_sequence(data) {
12
12
  if (data.mode === 'height') {
13
13
  const height = parse_height(data.height);
@@ -1,2 +1,3 @@
1
- export declare function decode_script(script: string | Uint8Array): string[];
1
+ import { Bytes } from '@vbyte/buff';
2
+ export declare function decode_script(script: Bytes): string[];
2
3
  export declare function is_valid_script(script: string | Uint8Array): boolean;
@@ -1,5 +1,5 @@
1
1
  import { Buff } from '@vbyte/buff';
2
- export declare function encode_script(words: (string | number | Uint8Array)[], varint?: boolean): string;
2
+ export declare function encode_script(words: (string | number | Uint8Array)[], varint?: boolean): Buff;
3
3
  export declare function encode_script_word(word: string | number | Uint8Array): Uint8Array;
4
4
  export declare function split_script_word(word: Uint8Array): Buff[];
5
5
  export declare function prefix_word_size(word: Uint8Array): Buff;
@@ -3,15 +3,15 @@ import { get_asm_code, } from './words.js';
3
3
  const MAX_WORD_SIZE = 520;
4
4
  export function encode_script(words, varint = false) {
5
5
  if (words.length === 0)
6
- return '00';
6
+ return Buff.num(0, 1);
7
7
  const bytes = [];
8
8
  for (const word of words) {
9
9
  bytes.push(encode_script_word(word));
10
10
  }
11
11
  const buffer = Buff.join(bytes);
12
12
  return (varint)
13
- ? buffer.prepend(Buff.varint(buffer.length, 'le')).hex
14
- : buffer.hex;
13
+ ? buffer.prepend(Buff.varint(buffer.length, 'le'))
14
+ : buffer;
15
15
  }
16
16
  export function encode_script_word(word) {
17
17
  let buff;
@@ -34,6 +34,7 @@ export function create_taproot(config) {
34
34
  const cblock = Buff.join(block);
35
35
  return {
36
36
  int_key: Buff.bytes(pubkey).hex,
37
+ path,
37
38
  parity,
38
39
  taproot: taproot ?? null,
39
40
  cblock: cblock.hex,