@btc-vision/transaction 1.0.112 → 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 +15 -4
- package/browser/keypair/EcKeyPair.d.ts +15 -12
- package/browser/keypair/Wallet.d.ts +12 -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/signer/TweakedSigner.d.ts +2 -2
- 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/FundingTransaction.d.ts +2 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +6 -7
- 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/transaction/shared/TweakedTransaction.d.ts +8 -7
- 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 +15 -4
- package/build/keypair/AddressVerificator.js +79 -3
- package/build/keypair/EcKeyPair.d.ts +15 -12
- package/build/keypair/EcKeyPair.js +61 -9
- package/build/keypair/Wallet.d.ts +12 -5
- package/build/keypair/Wallet.js +19 -5
- 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/signer/TweakedSigner.d.ts +2 -2
- package/build/signer/TweakedSigner.js +1 -1
- 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/CustomScriptTransaction.js +3 -3
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
- package/build/transaction/builders/DeploymentTransaction.js +10 -6
- package/build/transaction/builders/FundingTransaction.d.ts +2 -1
- package/build/transaction/builders/MultiSignTransaction.d.ts +6 -6
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
- package/build/transaction/builders/TransactionBuilder.d.ts +6 -7
- package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
- package/build/transaction/builders/UnwrapTransaction.js +4 -3
- 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/transaction/shared/TweakedTransaction.d.ts +8 -7
- package/build/transaction/shared/TweakedTransaction.js +1 -1
- 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 +4 -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 +149 -6
- package/src/keypair/EcKeyPair.ts +146 -47
- package/src/keypair/Wallet.ts +72 -15
- 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/signer/TweakedSigner.ts +3 -2
- 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 +10 -10
- package/src/transaction/builders/DeploymentTransaction.ts +23 -9
- package/src/transaction/builders/FundingTransaction.ts +2 -1
- package/src/transaction/builders/MultiSignTransaction.ts +10 -7
- package/src/transaction/builders/SharedInteractionTransaction.ts +5 -5
- package/src/transaction/builders/TransactionBuilder.ts +26 -17
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +10 -4
- package/src/transaction/builders/UnwrapTransaction.ts +5 -19
- package/src/transaction/builders/WrapTransaction.ts +7 -13
- 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/transaction/shared/TweakedTransaction.ts +12 -12
- 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,10 @@
|
|
|
1
|
+
import { i32 } from '../utils/types.js';
|
|
2
|
+
import { Address } from '../keypair/Address.js';
|
|
3
|
+
import { Map } from './Map.js';
|
|
4
|
+
export declare class AddressMap<V> extends Map<Address, V> {
|
|
5
|
+
set(key: Address, value: V): void;
|
|
6
|
+
indexOf(address: Address): i32;
|
|
7
|
+
has(key: Address): boolean;
|
|
8
|
+
get(key: Address): V;
|
|
9
|
+
delete(key: Address): boolean;
|
|
10
|
+
}
|
|
@@ -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,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
export declare enum AddressTypes {
|
|
3
|
+
P2PKH = "P2PKH",
|
|
4
|
+
P2SH = "P2SH",
|
|
5
|
+
P2SH_P2WPKH = "P2SH-P2WPKH",
|
|
6
|
+
P2SH_OR_P2SH_P2WPKH = "P2SH_OR_P2SH-P2WPKH",
|
|
7
|
+
P2PK = "P2PK",
|
|
8
|
+
P2TR = "P2TR",
|
|
9
|
+
P2WPKH = "P2WPKH"
|
|
10
|
+
}
|
|
3
11
|
export declare class AddressVerificator {
|
|
4
|
-
static isValidP2TRAddress(inAddress:
|
|
5
|
-
static
|
|
12
|
+
static isValidP2TRAddress(inAddress: string, network: Network): boolean;
|
|
13
|
+
static isP2WPKHAddress(inAddress: string, network: Network): boolean;
|
|
14
|
+
static isP2PKHOrP2SH(addy: string, network: Network): boolean;
|
|
15
|
+
static isValidPublicKey(input: string, network: Network): boolean;
|
|
16
|
+
static validateBitcoinAddress(addy: string, network: Network): AddressTypes | null;
|
|
6
17
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { address, initEccLib } from 'bitcoinjs-lib';
|
|
2
2
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
3
|
+
import { EcKeyPair } from './EcKeyPair.js';
|
|
3
4
|
initEccLib(ecc);
|
|
5
|
+
export var AddressTypes;
|
|
6
|
+
(function (AddressTypes) {
|
|
7
|
+
AddressTypes["P2PKH"] = "P2PKH";
|
|
8
|
+
AddressTypes["P2SH"] = "P2SH";
|
|
9
|
+
AddressTypes["P2SH_P2WPKH"] = "P2SH-P2WPKH";
|
|
10
|
+
AddressTypes["P2SH_OR_P2SH_P2WPKH"] = "P2SH_OR_P2SH-P2WPKH";
|
|
11
|
+
AddressTypes["P2PK"] = "P2PK";
|
|
12
|
+
AddressTypes["P2TR"] = "P2TR";
|
|
13
|
+
AddressTypes["P2WPKH"] = "P2WPKH";
|
|
14
|
+
})(AddressTypes || (AddressTypes = {}));
|
|
4
15
|
export class AddressVerificator {
|
|
5
16
|
static isValidP2TRAddress(inAddress, network) {
|
|
6
17
|
if (!inAddress || inAddress.length < 50)
|
|
@@ -11,10 +22,10 @@ export class AddressVerificator {
|
|
|
11
22
|
const decodedAddress = address.fromBech32(inAddress);
|
|
12
23
|
isValidTapRootAddress = decodedAddress.version === 1;
|
|
13
24
|
}
|
|
14
|
-
catch
|
|
25
|
+
catch { }
|
|
15
26
|
return isValidTapRootAddress;
|
|
16
27
|
}
|
|
17
|
-
static
|
|
28
|
+
static isP2WPKHAddress(inAddress, network) {
|
|
18
29
|
if (!inAddress || inAddress.length < 20 || inAddress.length > 50)
|
|
19
30
|
return false;
|
|
20
31
|
let isValidSegWitAddress = false;
|
|
@@ -24,7 +35,72 @@ export class AddressVerificator {
|
|
|
24
35
|
isValidSegWitAddress =
|
|
25
36
|
decodedAddress.version === 0 && decodedAddress.data.length === 20;
|
|
26
37
|
}
|
|
27
|
-
catch
|
|
38
|
+
catch { }
|
|
28
39
|
return isValidSegWitAddress;
|
|
29
40
|
}
|
|
41
|
+
static isP2PKHOrP2SH(addy, network) {
|
|
42
|
+
try {
|
|
43
|
+
const decodedBase58 = address.fromBase58Check(addy);
|
|
44
|
+
if (decodedBase58.version === network.pubKeyHash) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return decodedBase58.version === network.scriptHash;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
static isValidPublicKey(input, network) {
|
|
54
|
+
try {
|
|
55
|
+
if (input.startsWith('0x')) {
|
|
56
|
+
input = input.slice(2);
|
|
57
|
+
}
|
|
58
|
+
const hexRegex = /^[0-9a-fA-F]+$/;
|
|
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) {
|
|
66
|
+
const pubKeyBuffer = Buffer.from(input, 'hex');
|
|
67
|
+
EcKeyPair.fromPublicKey(pubKeyBuffer, network);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
static validateBitcoinAddress(addy, network) {
|
|
77
|
+
if (AddressVerificator.isValidPublicKey(addy, network)) {
|
|
78
|
+
return AddressTypes.P2PK;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const decodedBase58 = address.fromBase58Check(addy);
|
|
82
|
+
if (decodedBase58.version === network.pubKeyHash) {
|
|
83
|
+
return AddressTypes.P2PKH;
|
|
84
|
+
}
|
|
85
|
+
if (decodedBase58.version === network.scriptHash) {
|
|
86
|
+
return AddressTypes.P2SH_OR_P2SH_P2WPKH;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const decodedBech32 = address.fromBech32(addy);
|
|
93
|
+
if (decodedBech32.prefix === network.bech32) {
|
|
94
|
+
if (decodedBech32.version === 0 && decodedBech32.data.length === 20) {
|
|
95
|
+
return AddressTypes.P2WPKH;
|
|
96
|
+
}
|
|
97
|
+
if (decodedBech32.version === 1 && decodedBech32.data.length === 32) {
|
|
98
|
+
return AddressTypes.P2TR;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
30
106
|
}
|