@btc-vision/transaction 1.0.113 → 1.0.114
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/browser/_version.d.ts +1 -1
- package/browser/abi/ABICoder.d.ts +31 -0
- package/browser/buffer/BinaryReader.d.ts +37 -0
- package/browser/buffer/BinaryWriter.d.ts +46 -0
- package/browser/deterministic/AddressMap.d.ts +10 -0
- package/browser/deterministic/AddressSet.d.ts +13 -0
- package/browser/deterministic/DeterministicMap.d.ts +17 -0
- package/browser/deterministic/DeterministicSet.d.ts +13 -0
- package/browser/deterministic/Map.d.ts +14 -0
- package/browser/event/NetEvent.d.ts +5 -0
- package/browser/generators/AddressGenerator.d.ts +3 -0
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +23 -0
- package/browser/keypair/AddressVerificator.d.ts +1 -2
- package/browser/keypair/EcKeyPair.d.ts +9 -9
- package/browser/keypair/Wallet.d.ts +11 -5
- package/browser/metadata/ContractBaseMetadata.d.ts +3 -4
- package/browser/metadata/contracts/wBTC.d.ts +2 -3
- package/browser/metadata/tokens.d.ts +1 -1
- package/browser/opnet.d.ts +11 -0
- package/browser/transaction/TransactionFactory.d.ts +6 -6
- package/browser/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/browser/transaction/browser/types/Unisat.d.ts +2 -3
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/browser/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/browser/transaction/builders/MultiSignTransaction.d.ts +4 -5
- package/browser/transaction/builders/TransactionBuilder.d.ts +5 -6
- package/browser/transaction/builders/WrapTransaction.d.ts +2 -2
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/browser/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -2
- package/browser/utils/BufferHelper.d.ts +11 -0
- package/browser/utils/types.d.ts +12 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +31 -0
- package/build/abi/ABICoder.js +137 -0
- package/build/buffer/BinaryReader.d.ts +37 -0
- package/build/buffer/BinaryReader.js +192 -0
- package/build/buffer/BinaryWriter.d.ts +46 -0
- package/build/buffer/BinaryWriter.js +258 -0
- package/build/deterministic/AddressMap.d.ts +10 -0
- package/build/deterministic/AddressMap.js +46 -0
- package/build/deterministic/AddressSet.d.ts +13 -0
- package/build/deterministic/AddressSet.js +44 -0
- package/build/deterministic/DeterministicMap.d.ts +17 -0
- package/build/deterministic/DeterministicMap.js +83 -0
- package/build/deterministic/DeterministicSet.d.ts +13 -0
- package/build/deterministic/DeterministicSet.js +46 -0
- package/build/deterministic/Map.d.ts +14 -0
- package/build/deterministic/Map.js +56 -0
- package/build/event/NetEvent.d.ts +5 -0
- package/build/event/NetEvent.js +6 -0
- package/build/generators/AddressGenerator.d.ts +3 -0
- package/build/generators/AddressGenerator.js +8 -1
- package/build/keypair/Address.d.ts +23 -0
- package/build/keypair/Address.js +129 -0
- package/build/keypair/AddressVerificator.d.ts +1 -2
- package/build/keypair/AddressVerificator.js +7 -2
- package/build/keypair/EcKeyPair.d.ts +9 -9
- package/build/keypair/EcKeyPair.js +9 -2
- package/build/keypair/Wallet.d.ts +11 -5
- package/build/keypair/Wallet.js +14 -1
- package/build/metadata/ContractBaseMetadata.d.ts +3 -4
- package/build/metadata/contracts/wBTC.d.ts +2 -3
- package/build/metadata/contracts/wBTC.js +4 -6
- package/build/metadata/tokens.d.ts +1 -1
- package/build/metadata/tokens.js +19 -15
- package/build/opnet.d.ts +11 -0
- package/build/opnet.js +11 -0
- package/build/transaction/TransactionFactory.d.ts +6 -6
- package/build/transaction/TransactionFactory.js +3 -2
- package/build/transaction/browser/BrowserSignerBase.d.ts +3 -4
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
- package/build/transaction/browser/types/Unisat.d.ts +2 -3
- package/build/transaction/builders/CustomScriptTransaction.d.ts +4 -5
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +6 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +4 -5
- package/build/transaction/builders/TransactionBuilder.d.ts +5 -6
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +2 -1
- package/build/transaction/builders/WrapTransaction.d.ts +2 -2
- package/build/transaction/builders/WrapTransaction.js +5 -6
- package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
- package/build/transaction/processor/PsbtTransaction.d.ts +3 -4
- package/build/transaction/shared/P2TR_MS.d.ts +1 -2
- package/build/utils/BufferHelper.d.ts +11 -0
- package/build/utils/BufferHelper.js +50 -0
- package/build/utils/types.d.ts +12 -0
- package/build/utils/types.js +1 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -2
- package/build/utxo/OPNetLimitedProvider.js +1 -1
- package/build/verification/TapscriptVerificator.js +3 -2
- package/package.json +3 -2
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +158 -0
- package/src/buffer/BinaryReader.ts +260 -0
- package/src/buffer/BinaryWriter.ts +331 -0
- package/src/deterministic/AddressMap.ts +57 -0
- package/src/deterministic/AddressSet.ts +62 -0
- package/src/deterministic/DeterministicMap.ts +88 -0
- package/src/deterministic/DeterministicSet.ts +56 -0
- package/src/deterministic/Map.ts +66 -0
- package/src/event/NetEvent.ts +6 -0
- package/src/generators/AddressGenerator.ts +15 -1
- package/src/keypair/Address.ts +235 -0
- package/src/keypair/AddressVerificator.ts +9 -5
- package/src/keypair/EcKeyPair.ts +39 -37
- package/src/keypair/Wallet.ts +61 -12
- package/src/metadata/ContractBaseMetadata.ts +3 -4
- package/src/metadata/contracts/wBTC.ts +8 -9
- package/src/metadata/tokens.ts +21 -16
- package/src/opnet.ts +13 -0
- package/src/transaction/TransactionFactory.ts +11 -10
- package/src/transaction/browser/BrowserSignerBase.ts +3 -4
- package/src/transaction/browser/extensions/UnisatSigner.ts +6 -7
- package/src/transaction/browser/types/Unisat.ts +2 -3
- package/src/transaction/builders/CustomScriptTransaction.ts +4 -5
- package/src/transaction/builders/DeploymentTransaction.ts +17 -4
- package/src/transaction/builders/MultiSignTransaction.ts +4 -5
- package/src/transaction/builders/TransactionBuilder.ts +8 -9
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +3 -1
- package/src/transaction/builders/UnwrapTransaction.ts +3 -17
- package/src/transaction/builders/WrapTransaction.ts +7 -8
- package/src/transaction/interfaces/ITransactionParameters.ts +7 -6
- package/src/transaction/processor/PsbtTransaction.ts +3 -4
- package/src/transaction/shared/P2TR_MS.ts +2 -3
- package/src/utils/BufferHelper.ts +71 -0
- package/src/utils/types.ts +19 -0
- package/src/utxo/OPNetLimitedProvider.ts +3 -8
- package/src/verification/TapscriptVerificator.ts +4 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Map } from './Map.js';
|
|
2
|
+
export class AddressMap extends Map {
|
|
3
|
+
set(key, value) {
|
|
4
|
+
const index = this._keys.indexOf(key);
|
|
5
|
+
if (index == -1) {
|
|
6
|
+
this._keys.push(key);
|
|
7
|
+
this._values.push(value);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this._values[index] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
indexOf(address) {
|
|
14
|
+
for (let i = 0; i < this._keys.length; i++) {
|
|
15
|
+
const key = this._keys[i];
|
|
16
|
+
if (address.equals(key)) {
|
|
17
|
+
return i;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return -1;
|
|
21
|
+
}
|
|
22
|
+
has(key) {
|
|
23
|
+
for (let i = 0; i < this._keys.length; i++) {
|
|
24
|
+
if (key.equals(this._keys[i])) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
get(key) {
|
|
31
|
+
const index = this.indexOf(key);
|
|
32
|
+
if (index == -1) {
|
|
33
|
+
throw new Error('Key not found in map');
|
|
34
|
+
}
|
|
35
|
+
return this._values[index];
|
|
36
|
+
}
|
|
37
|
+
delete(key) {
|
|
38
|
+
const index = this.indexOf(key);
|
|
39
|
+
if (index == -1) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
this._keys.splice(index, 1);
|
|
43
|
+
this._values.splice(index, 1);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i32 } from '../utils/types.js';
|
|
2
|
+
import { Address } from '../keypair/Address.js';
|
|
3
|
+
export declare class AddressSet {
|
|
4
|
+
private keys;
|
|
5
|
+
constructor(keys?: Address[]);
|
|
6
|
+
add(address: Address): void;
|
|
7
|
+
contains(address: Address): boolean;
|
|
8
|
+
remove(address: Address): void;
|
|
9
|
+
size(): i32;
|
|
10
|
+
clone(): AddressSet;
|
|
11
|
+
clear(): void;
|
|
12
|
+
combine(set: AddressSet): AddressSet;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class AddressSet {
|
|
2
|
+
constructor(keys = []) {
|
|
3
|
+
this.keys = keys;
|
|
4
|
+
}
|
|
5
|
+
add(address) {
|
|
6
|
+
if (!this.contains(address)) {
|
|
7
|
+
this.keys.push(address);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
contains(address) {
|
|
11
|
+
for (let i = 0; i < this.keys.length; i++) {
|
|
12
|
+
if (this.keys[i].equals(address)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
remove(address) {
|
|
19
|
+
const index = this.keys.findIndex((key) => key.equals(address));
|
|
20
|
+
if (index !== -1) {
|
|
21
|
+
this.keys.splice(index, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
size() {
|
|
25
|
+
return this.keys.length;
|
|
26
|
+
}
|
|
27
|
+
clone() {
|
|
28
|
+
const clone = new AddressSet();
|
|
29
|
+
for (let i = 0; i < this.keys.length; i++) {
|
|
30
|
+
clone.add(this.keys[i]);
|
|
31
|
+
}
|
|
32
|
+
return clone;
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
|
+
this.keys = [];
|
|
36
|
+
}
|
|
37
|
+
combine(set) {
|
|
38
|
+
const clone = this.clone();
|
|
39
|
+
for (let i = 0; i < set.keys.length; i++) {
|
|
40
|
+
clone.add(set.keys[i]);
|
|
41
|
+
}
|
|
42
|
+
return clone;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class DeterministicMap<K, V> {
|
|
2
|
+
#private;
|
|
3
|
+
private compareFn;
|
|
4
|
+
private map;
|
|
5
|
+
constructor(compareFn: (a: K, b: K) => number);
|
|
6
|
+
get size(): number;
|
|
7
|
+
static fromMap<K, V>(map: Map<K, V>, compareFn: (a: K, b: K) => number): DeterministicMap<K, V>;
|
|
8
|
+
set(key: K, value: V): void;
|
|
9
|
+
get(key: K): V | undefined;
|
|
10
|
+
keys(): IterableIterator<K>;
|
|
11
|
+
values(): IterableIterator<V>;
|
|
12
|
+
has(key: K): boolean;
|
|
13
|
+
delete(key: K): boolean;
|
|
14
|
+
clear(): void;
|
|
15
|
+
forEach(callback: (value: V, key: K, map: DeterministicMap<K, V>) => void): void;
|
|
16
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DeterministicMap_keys;
|
|
13
|
+
export class DeterministicMap {
|
|
14
|
+
constructor(compareFn) {
|
|
15
|
+
this.compareFn = compareFn;
|
|
16
|
+
_DeterministicMap_keys.set(this, void 0);
|
|
17
|
+
this.map = new Map();
|
|
18
|
+
__classPrivateFieldSet(this, _DeterministicMap_keys, [], "f");
|
|
19
|
+
}
|
|
20
|
+
get size() {
|
|
21
|
+
return this.map.size;
|
|
22
|
+
}
|
|
23
|
+
static fromMap(map, compareFn) {
|
|
24
|
+
const deterministicMap = new DeterministicMap(compareFn);
|
|
25
|
+
for (const [key, value] of map) {
|
|
26
|
+
deterministicMap.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
return deterministicMap;
|
|
29
|
+
}
|
|
30
|
+
set(key, value) {
|
|
31
|
+
if (!this.map.has(key)) {
|
|
32
|
+
__classPrivateFieldGet(this, _DeterministicMap_keys, "f").push(key);
|
|
33
|
+
__classPrivateFieldGet(this, _DeterministicMap_keys, "f").sort(this.compareFn);
|
|
34
|
+
}
|
|
35
|
+
this.map.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
get(key) {
|
|
38
|
+
return this.map.get(key);
|
|
39
|
+
}
|
|
40
|
+
keys() {
|
|
41
|
+
return __classPrivateFieldGet(this, _DeterministicMap_keys, "f").values();
|
|
42
|
+
}
|
|
43
|
+
values() {
|
|
44
|
+
const values = [];
|
|
45
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _DeterministicMap_keys, "f").length; i++) {
|
|
46
|
+
const key = __classPrivateFieldGet(this, _DeterministicMap_keys, "f")[i];
|
|
47
|
+
const value = this.map.get(key);
|
|
48
|
+
if (value) {
|
|
49
|
+
values.push(value);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('Value not found');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return values.values();
|
|
56
|
+
}
|
|
57
|
+
has(key) {
|
|
58
|
+
return this.map.has(key);
|
|
59
|
+
}
|
|
60
|
+
delete(key) {
|
|
61
|
+
if (this.map.has(key)) {
|
|
62
|
+
this.map.delete(key);
|
|
63
|
+
__classPrivateFieldSet(this, _DeterministicMap_keys, __classPrivateFieldGet(this, _DeterministicMap_keys, "f").filter((k) => k !== key), "f");
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
clear() {
|
|
69
|
+
this.map.clear();
|
|
70
|
+
__classPrivateFieldSet(this, _DeterministicMap_keys, [], "f");
|
|
71
|
+
}
|
|
72
|
+
forEach(callback) {
|
|
73
|
+
for (const key of __classPrivateFieldGet(this, _DeterministicMap_keys, "f")) {
|
|
74
|
+
const value = this.map.get(key);
|
|
75
|
+
callback(value, key, this);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
*[(_DeterministicMap_keys = new WeakMap(), Symbol.iterator)]() {
|
|
79
|
+
for (const key of __classPrivateFieldGet(this, _DeterministicMap_keys, "f")) {
|
|
80
|
+
yield [key, this.map.get(key)];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class DeterministicSet<T> {
|
|
2
|
+
private compareFn;
|
|
3
|
+
private elements;
|
|
4
|
+
constructor(compareFn: (a: T, b: T) => number);
|
|
5
|
+
add(value: T): void;
|
|
6
|
+
delete(value: T): boolean;
|
|
7
|
+
has(value: T): boolean;
|
|
8
|
+
clear(): void;
|
|
9
|
+
forEach(callback: (value: T, set: DeterministicSet<T>) => void): void;
|
|
10
|
+
static fromSet<T>(set: Set<T>, compareFn: (a: T, b: T) => number): DeterministicSet<T>;
|
|
11
|
+
get size(): number;
|
|
12
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class DeterministicSet {
|
|
2
|
+
constructor(compareFn) {
|
|
3
|
+
this.compareFn = compareFn;
|
|
4
|
+
this.elements = [];
|
|
5
|
+
}
|
|
6
|
+
add(value) {
|
|
7
|
+
if (!this.elements.includes(value)) {
|
|
8
|
+
this.elements.push(value);
|
|
9
|
+
this.elements.sort(this.compareFn);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
delete(value) {
|
|
13
|
+
const index = this.elements.indexOf(value);
|
|
14
|
+
if (index === -1) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
this.elements.splice(index, 1);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
has(value) {
|
|
21
|
+
return this.elements.includes(value);
|
|
22
|
+
}
|
|
23
|
+
clear() {
|
|
24
|
+
this.elements = [];
|
|
25
|
+
}
|
|
26
|
+
forEach(callback) {
|
|
27
|
+
for (const value of this.elements) {
|
|
28
|
+
callback(value, this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static fromSet(set, compareFn) {
|
|
32
|
+
const deterministicSet = new DeterministicSet(compareFn);
|
|
33
|
+
for (const value of set) {
|
|
34
|
+
deterministicSet.add(value);
|
|
35
|
+
}
|
|
36
|
+
return deterministicSet;
|
|
37
|
+
}
|
|
38
|
+
get size() {
|
|
39
|
+
return this.elements.length;
|
|
40
|
+
}
|
|
41
|
+
*[Symbol.iterator]() {
|
|
42
|
+
for (const value of this.elements) {
|
|
43
|
+
yield value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i32 } from '../utils/types.js';
|
|
2
|
+
export declare class Map<K, V> {
|
|
3
|
+
protected _keys: K[];
|
|
4
|
+
protected _values: V[];
|
|
5
|
+
get size(): i32;
|
|
6
|
+
keys(): K[];
|
|
7
|
+
values(): V[];
|
|
8
|
+
set(key: K, value: V): void;
|
|
9
|
+
indexOf(key: K): i32;
|
|
10
|
+
get(key: K): V;
|
|
11
|
+
has(key: K): boolean;
|
|
12
|
+
delete(key: K): boolean;
|
|
13
|
+
clear(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class Map {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._keys = [];
|
|
4
|
+
this._values = [];
|
|
5
|
+
}
|
|
6
|
+
get size() {
|
|
7
|
+
return this._keys.length;
|
|
8
|
+
}
|
|
9
|
+
keys() {
|
|
10
|
+
return this._keys;
|
|
11
|
+
}
|
|
12
|
+
values() {
|
|
13
|
+
return this._values;
|
|
14
|
+
}
|
|
15
|
+
set(key, value) {
|
|
16
|
+
const index = this.indexOf(key);
|
|
17
|
+
if (index == -1) {
|
|
18
|
+
this._keys.push(key);
|
|
19
|
+
this._values.push(value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this._values[index] = value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
indexOf(key) {
|
|
26
|
+
for (let i = 0; i < this._keys.length; i++) {
|
|
27
|
+
if (this._keys[i] == key) {
|
|
28
|
+
return i;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
const index = this.indexOf(key);
|
|
35
|
+
if (index == -1) {
|
|
36
|
+
throw new Error('Key not found in map');
|
|
37
|
+
}
|
|
38
|
+
return this._values[index];
|
|
39
|
+
}
|
|
40
|
+
has(key) {
|
|
41
|
+
return this.indexOf(key) != -1;
|
|
42
|
+
}
|
|
43
|
+
delete(key) {
|
|
44
|
+
const index = this.indexOf(key);
|
|
45
|
+
if (index == -1) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
this._keys.splice(index, 1);
|
|
49
|
+
this._values.splice(index, 1);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
clear() {
|
|
53
|
+
this._keys = [];
|
|
54
|
+
this._values = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Network } from 'bitcoinjs-lib';
|
|
2
2
|
export declare class AddressGenerator {
|
|
3
3
|
static generatePKSH(sha256Hash: Buffer, network: Network): string;
|
|
4
|
+
static generateTaprootAddress(pubKey: Buffer, network: {
|
|
5
|
+
bech32: string;
|
|
6
|
+
}): string;
|
|
4
7
|
private static toSegwitAddress;
|
|
5
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bech32 } from 'bech32';
|
|
1
|
+
import { bech32, bech32m } from 'bech32';
|
|
2
2
|
import { initEccLib } from 'bitcoinjs-lib';
|
|
3
3
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
4
4
|
import { ripemd160 } from 'bitcoinjs-lib/src/crypto.js';
|
|
@@ -10,6 +10,13 @@ export class AddressGenerator {
|
|
|
10
10
|
const pkh = ripemd160(sha256Hash);
|
|
11
11
|
return this.toSegwitAddress(pkh, network);
|
|
12
12
|
}
|
|
13
|
+
static generateTaprootAddress(pubKey, network) {
|
|
14
|
+
if (pubKey.length !== 32)
|
|
15
|
+
throw new Error('Invalid public key length');
|
|
16
|
+
const words = bech32m.toWords(pubKey);
|
|
17
|
+
words.unshift(0x01);
|
|
18
|
+
return bech32m.encode(network.bech32, words);
|
|
19
|
+
}
|
|
13
20
|
static toSegwitAddress(pkh, network) {
|
|
14
21
|
const words = bech32.toWords(pkh);
|
|
15
22
|
words.unshift(0x00);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
import { ECPairInterface } from 'ecpair';
|
|
3
|
+
export declare class Address extends Uint8Array {
|
|
4
|
+
#private;
|
|
5
|
+
private isP2TROnly;
|
|
6
|
+
constructor(bytes?: ArrayLike<number>);
|
|
7
|
+
private _keyPair;
|
|
8
|
+
get keyPair(): ECPairInterface;
|
|
9
|
+
static dead(): Address;
|
|
10
|
+
static fromString(pubKey: string): Address;
|
|
11
|
+
static wrap(bytes: ArrayLike<number>): Address;
|
|
12
|
+
toHex(): string;
|
|
13
|
+
equals(a: Address): boolean;
|
|
14
|
+
isBiggerThan(a: Address): boolean;
|
|
15
|
+
isSmallerThan(a: Address): boolean;
|
|
16
|
+
set(publicKey: ArrayLike<number>): void;
|
|
17
|
+
isValid(network: Network): boolean;
|
|
18
|
+
p2wpkh(network: Network): string;
|
|
19
|
+
p2pkh(network: Network): string;
|
|
20
|
+
p2shp2wpkh(network: Network): string;
|
|
21
|
+
toString(): string;
|
|
22
|
+
p2tr(network: Network): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _Address_p2tr, _Address_network;
|
|
13
|
+
import { EcKeyPair } from './EcKeyPair.js';
|
|
14
|
+
import { ADDRESS_BYTE_LENGTH } from '../utils/types.js';
|
|
15
|
+
import { AddressVerificator } from './AddressVerificator.js';
|
|
16
|
+
import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
|
|
17
|
+
export class Address extends Uint8Array {
|
|
18
|
+
constructor(bytes) {
|
|
19
|
+
super(ADDRESS_BYTE_LENGTH);
|
|
20
|
+
this.isP2TROnly = false;
|
|
21
|
+
_Address_p2tr.set(this, void 0);
|
|
22
|
+
_Address_network.set(this, void 0);
|
|
23
|
+
if (!bytes) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.set(bytes);
|
|
27
|
+
}
|
|
28
|
+
get keyPair() {
|
|
29
|
+
if (!this._keyPair) {
|
|
30
|
+
throw new Error('Public key not set for address');
|
|
31
|
+
}
|
|
32
|
+
return this._keyPair;
|
|
33
|
+
}
|
|
34
|
+
static dead() {
|
|
35
|
+
return Address.fromString('0x04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f');
|
|
36
|
+
}
|
|
37
|
+
static fromString(pubKey) {
|
|
38
|
+
if (pubKey.startsWith('0x')) {
|
|
39
|
+
pubKey = pubKey.slice(2);
|
|
40
|
+
}
|
|
41
|
+
return new Address(Buffer.from(pubKey, 'hex'));
|
|
42
|
+
}
|
|
43
|
+
static wrap(bytes) {
|
|
44
|
+
return new Address(bytes);
|
|
45
|
+
}
|
|
46
|
+
toHex() {
|
|
47
|
+
return '0x' + Buffer.from(this).toString('hex');
|
|
48
|
+
}
|
|
49
|
+
equals(a) {
|
|
50
|
+
if (a.length !== this.length) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
for (let i = 0; i < this.length; i++) {
|
|
54
|
+
if (this[i] !== a[i]) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
isBiggerThan(a) {
|
|
61
|
+
for (let i = 0; i < this.length; i++) {
|
|
62
|
+
if (this[i] < a[i]) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
isSmallerThan(a) {
|
|
69
|
+
for (let i = 0; i < this.length; i++) {
|
|
70
|
+
if (this[i] > a[i]) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
set(publicKey) {
|
|
77
|
+
if (publicKey.length !== 33 && publicKey.length !== 32 && publicKey.length !== 65) {
|
|
78
|
+
throw new Error('Invalid public key length');
|
|
79
|
+
}
|
|
80
|
+
if (publicKey.length === 32) {
|
|
81
|
+
this.isP2TROnly = true;
|
|
82
|
+
const buf = Buffer.alloc(32);
|
|
83
|
+
buf.set(publicKey);
|
|
84
|
+
super.set(publicKey);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this._keyPair = EcKeyPair.fromPublicKey(Uint8Array.from(publicKey));
|
|
88
|
+
const tweaked = toXOnly(Buffer.from(EcKeyPair.tweakPublicKey(this._keyPair.publicKey.toString('hex')), 'hex'));
|
|
89
|
+
super.set(Uint8Array.from(tweaked));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
isValid(network) {
|
|
93
|
+
return AddressVerificator.isValidPublicKey(Buffer.from(this).toString('hex'), network);
|
|
94
|
+
}
|
|
95
|
+
p2wpkh(network) {
|
|
96
|
+
return EcKeyPair.getP2WPKHAddress(this.keyPair, network);
|
|
97
|
+
}
|
|
98
|
+
p2pkh(network) {
|
|
99
|
+
return EcKeyPair.getLegacyAddress(this.keyPair, network);
|
|
100
|
+
}
|
|
101
|
+
p2shp2wpkh(network) {
|
|
102
|
+
return EcKeyPair.getLegacySegwitAddress(this.keyPair, network);
|
|
103
|
+
}
|
|
104
|
+
toString() {
|
|
105
|
+
if (__classPrivateFieldGet(this, _Address_p2tr, "f")) {
|
|
106
|
+
return __classPrivateFieldGet(this, _Address_p2tr, "f");
|
|
107
|
+
}
|
|
108
|
+
return this.toHex();
|
|
109
|
+
}
|
|
110
|
+
p2tr(network) {
|
|
111
|
+
if (__classPrivateFieldGet(this, _Address_p2tr, "f") && __classPrivateFieldGet(this, _Address_network, "f") === network) {
|
|
112
|
+
return __classPrivateFieldGet(this, _Address_p2tr, "f");
|
|
113
|
+
}
|
|
114
|
+
let p2trAddy;
|
|
115
|
+
if (this._keyPair) {
|
|
116
|
+
p2trAddy = EcKeyPair.getTaprootAddress(this.keyPair, network);
|
|
117
|
+
}
|
|
118
|
+
else if (this.isP2TROnly) {
|
|
119
|
+
p2trAddy = EcKeyPair.tweakedPubKeyBufferToAddress(this, network);
|
|
120
|
+
}
|
|
121
|
+
if (p2trAddy) {
|
|
122
|
+
__classPrivateFieldSet(this, _Address_network, network, "f");
|
|
123
|
+
__classPrivateFieldSet(this, _Address_p2tr, p2trAddy, "f");
|
|
124
|
+
return p2trAddy;
|
|
125
|
+
}
|
|
126
|
+
throw new Error('Public key not set');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
_Address_p2tr = new WeakMap(), _Address_network = new WeakMap();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Network } from 'bitcoinjs-lib';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
2
|
export declare enum AddressTypes {
|
|
4
3
|
P2PKH = "P2PKH",
|
|
5
4
|
P2SH = "P2SH",
|
|
@@ -10,7 +9,7 @@ export declare enum AddressTypes {
|
|
|
10
9
|
P2WPKH = "P2WPKH"
|
|
11
10
|
}
|
|
12
11
|
export declare class AddressVerificator {
|
|
13
|
-
static isValidP2TRAddress(inAddress:
|
|
12
|
+
static isValidP2TRAddress(inAddress: string, network: Network): boolean;
|
|
14
13
|
static isP2WPKHAddress(inAddress: string, network: Network): boolean;
|
|
15
14
|
static isP2PKHOrP2SH(addy: string, network: Network): boolean;
|
|
16
15
|
static isValidPublicKey(input: string, network: Network): boolean;
|
|
@@ -56,14 +56,19 @@ export class AddressVerificator {
|
|
|
56
56
|
input = input.slice(2);
|
|
57
57
|
}
|
|
58
58
|
const hexRegex = /^[0-9a-fA-F]+$/;
|
|
59
|
-
if (
|
|
59
|
+
if (!hexRegex.test(input)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (input.length === 64) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (input.length === 66 || input.length === 130) {
|
|
60
66
|
const pubKeyBuffer = Buffer.from(input, 'hex');
|
|
61
67
|
EcKeyPair.fromPublicKey(pubKeyBuffer, network);
|
|
62
68
|
return true;
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
catch (error) {
|
|
66
|
-
console.log(error);
|
|
67
72
|
return false;
|
|
68
73
|
}
|
|
69
74
|
return false;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
2
1
|
import { BIP32API, BIP32Interface } from 'bip32';
|
|
3
2
|
import { Network, Signer } from 'bitcoinjs-lib';
|
|
4
3
|
import { ECPairAPI, ECPairInterface } from 'ecpair';
|
|
@@ -9,20 +8,21 @@ export declare class EcKeyPair {
|
|
|
9
8
|
static fromWIF(wif: string, network?: Network): ECPairInterface;
|
|
10
9
|
static fromPrivateKey(privateKey: Buffer | Uint8Array, network?: Network): ECPairInterface;
|
|
11
10
|
static fromPublicKey(publicKey: Buffer | Uint8Array, network?: Network): ECPairInterface;
|
|
12
|
-
static generateMultiSigAddress(pubKeys: Buffer[], minimumSignatureRequired: number, network?: Network):
|
|
11
|
+
static generateMultiSigAddress(pubKeys: Buffer[], minimumSignatureRequired: number, network?: Network): string;
|
|
13
12
|
static verifyPubKeys(pubKeys: Buffer[], network?: Network): Buffer[];
|
|
14
|
-
static getP2WPKHAddress(keyPair: ECPairInterface, network?: Network):
|
|
13
|
+
static getP2WPKHAddress(keyPair: ECPairInterface, network?: Network): string;
|
|
15
14
|
static tweakedPubKeyToAddress(tweakedPubKeyHex: string, network: Network): string;
|
|
15
|
+
static tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer: Buffer | Uint8Array, network: Network): string;
|
|
16
16
|
static xOnlyTweakedPubKeyToAddress(tweakedPubKeyHex: string, network: Network): string;
|
|
17
17
|
static tweakPublicKey(compressedPubKeyHex: string): string;
|
|
18
18
|
static generateWallet(network?: Network): IWallet;
|
|
19
|
-
static verifyContractAddress(contractAddress:
|
|
20
|
-
static getLegacySegwitAddress(keyPair: ECPairInterface, network?: Network):
|
|
21
|
-
static getLegacyAddress(keyPair: ECPairInterface, network?: Network):
|
|
22
|
-
static getP2PKAddress(keyPair: ECPairInterface, network?: Network):
|
|
19
|
+
static verifyContractAddress(contractAddress: string, network?: Network): boolean;
|
|
20
|
+
static getLegacySegwitAddress(keyPair: ECPairInterface, network?: Network): string;
|
|
21
|
+
static getLegacyAddress(keyPair: ECPairInterface, network?: Network): string;
|
|
22
|
+
static getP2PKAddress(keyPair: ECPairInterface, network?: Network): string;
|
|
23
23
|
static generateRandomKeyPair(network?: Network): ECPairInterface;
|
|
24
24
|
static fromSeed(seed: Buffer, network?: Network): BIP32Interface;
|
|
25
|
-
static getTaprootAddress(keyPair: ECPairInterface | Signer, network?: Network):
|
|
26
|
-
static getTaprootAddressFromAddress(inAddr:
|
|
25
|
+
static getTaprootAddress(keyPair: ECPairInterface | Signer, network?: Network): string;
|
|
26
|
+
static getTaprootAddressFromAddress(inAddr: string, network?: Network): string;
|
|
27
27
|
static fromSeedKeyPair(seed: Buffer, network?: Network): ECPairInterface;
|
|
28
28
|
}
|
|
@@ -57,9 +57,16 @@ export class EcKeyPair {
|
|
|
57
57
|
if (tweakedPubKeyHex.startsWith('0x')) {
|
|
58
58
|
tweakedPubKeyHex = tweakedPubKeyHex.slice(2);
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
let tweakedPubKeyBuffer = Buffer.from(tweakedPubKeyHex, 'hex');
|
|
61
|
+
if (tweakedPubKeyBuffer.length !== 32)
|
|
62
|
+
tweakedPubKeyBuffer = toXOnly(tweakedPubKeyBuffer);
|
|
63
|
+
return EcKeyPair.tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer, network);
|
|
64
|
+
}
|
|
65
|
+
static tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer, network) {
|
|
61
66
|
const { address } = payments.p2tr({
|
|
62
|
-
pubkey:
|
|
67
|
+
pubkey: Buffer.isBuffer(tweakedPubKeyBuffer)
|
|
68
|
+
? tweakedPubKeyBuffer
|
|
69
|
+
: Buffer.from(tweakedPubKeyBuffer),
|
|
63
70
|
network: network,
|
|
64
71
|
});
|
|
65
72
|
if (!address) {
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import { IWallet } from './interfaces/IWallet.js';
|
|
2
2
|
import { ECPairInterface } from 'ecpair';
|
|
3
3
|
import { Network } from 'bitcoinjs-lib';
|
|
4
|
-
import { Address } from '
|
|
4
|
+
import { Address } from './Address.js';
|
|
5
5
|
export declare class Wallet {
|
|
6
6
|
readonly network: Network;
|
|
7
7
|
private readonly _keypair;
|
|
8
8
|
private readonly _p2wpkh;
|
|
9
9
|
private readonly _p2tr;
|
|
10
10
|
private readonly _legacy;
|
|
11
|
+
private readonly _segwitLegacy;
|
|
11
12
|
private readonly _bufferPubKey;
|
|
13
|
+
private readonly _tweakedKey;
|
|
14
|
+
private readonly _address;
|
|
12
15
|
constructor(wallet: IWallet, network?: Network);
|
|
16
|
+
get address(): Address;
|
|
17
|
+
get tweakedPubKeyKey(): Buffer;
|
|
13
18
|
get keypair(): ECPairInterface;
|
|
14
|
-
get p2wpkh():
|
|
15
|
-
get p2tr():
|
|
16
|
-
get legacy():
|
|
17
|
-
get addresses():
|
|
19
|
+
get p2wpkh(): string;
|
|
20
|
+
get p2tr(): string;
|
|
21
|
+
get legacy(): string;
|
|
22
|
+
get addresses(): string[];
|
|
23
|
+
get segwitLegacy(): string;
|
|
18
24
|
get publicKey(): Buffer;
|
|
19
25
|
get xOnly(): Buffer;
|
|
20
26
|
static fromWif(wif: string, network?: Network): Wallet;
|