@arkade-os/sdk 0.4.14 → 0.4.16
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/README.md +287 -215
- package/dist/cjs/arkfee/estimator.js +1 -1
- package/dist/cjs/arkfee/types.js +2 -1
- package/dist/cjs/arknote/index.js +43 -4
- package/dist/cjs/bip322/index.js +1 -1
- package/dist/cjs/contracts/arkcontract.js +1 -1
- package/dist/cjs/contracts/contractManager.js +40 -24
- package/dist/cjs/contracts/contractWatcher.js +29 -22
- package/dist/cjs/contracts/handlers/default.js +1 -1
- package/dist/cjs/contracts/handlers/delegate.js +1 -1
- package/dist/cjs/contracts/handlers/helpers.js +25 -1
- package/dist/cjs/contracts/handlers/vhtlc.js +2 -4
- package/dist/cjs/extension/asset/assetGroup.js +92 -5
- package/dist/cjs/extension/asset/assetId.js +67 -3
- package/dist/cjs/extension/asset/assetInput.js +18 -0
- package/dist/cjs/extension/asset/assetOutput.js +15 -0
- package/dist/cjs/extension/asset/assetRef.js +66 -0
- package/dist/cjs/extension/asset/metadata.js +15 -0
- package/dist/cjs/extension/asset/packet.js +4 -1
- package/dist/cjs/extension/index.js +1 -1
- package/dist/cjs/forfeit.js +14 -0
- package/dist/cjs/identity/index.js +6 -0
- package/dist/cjs/identity/seedIdentity.js +5 -5
- package/dist/cjs/identity/singleKey.js +4 -0
- package/dist/cjs/index.js +5 -3
- package/dist/cjs/intent/index.js +28 -12
- package/dist/cjs/providers/ark.js +3 -2
- package/dist/cjs/providers/delegator.js +20 -1
- package/dist/cjs/providers/expoArk.js +2 -2
- package/dist/cjs/providers/indexer.js +2 -2
- package/dist/cjs/providers/onchain.js +2 -1
- package/dist/cjs/repositories/realm/schemas.js +2 -2
- package/dist/cjs/repositories/realm/types.js +1 -1
- package/dist/cjs/script/address.js +37 -6
- package/dist/cjs/script/base.js +70 -1
- package/dist/cjs/script/default.js +3 -0
- package/dist/cjs/script/delegate.js +4 -0
- package/dist/cjs/script/tapscript.js +25 -4
- package/dist/cjs/script/vhtlc.js +35 -27
- package/dist/cjs/storage/fileSystem.js +1 -1
- package/dist/cjs/storage/inMemory.js +1 -1
- package/dist/cjs/storage/indexedDB.js +1 -1
- package/dist/cjs/storage/localStorage.js +1 -1
- package/dist/cjs/tree/validation.js +1 -1
- package/dist/cjs/utils/arkTransaction.js +5 -5
- package/dist/cjs/utils/bip21.js +16 -3
- package/dist/cjs/utils/syncCursors.js +4 -4
- package/dist/cjs/utils/transaction.js +1 -1
- package/dist/cjs/utils/transactionHistory.js +11 -11
- package/dist/cjs/utils/unknownFields.js +3 -3
- package/dist/cjs/wallet/asset-manager.js +4 -4
- package/dist/cjs/wallet/batch.js +5 -5
- package/dist/cjs/wallet/delegator.js +9 -8
- package/dist/cjs/wallet/expo/background.js +3 -3
- package/dist/cjs/wallet/expo/wallet.js +7 -7
- package/dist/cjs/wallet/index.js +43 -0
- package/dist/cjs/wallet/onchain.js +43 -5
- package/dist/cjs/wallet/ramps.js +44 -14
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +22 -22
- package/dist/cjs/wallet/serviceWorker/wallet.js +28 -24
- package/dist/cjs/wallet/unroll.js +12 -8
- package/dist/cjs/wallet/utils.js +1 -1
- package/dist/cjs/wallet/vtxo-manager.js +123 -82
- package/dist/cjs/wallet/wallet.js +231 -98
- package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +1 -1
- package/dist/cjs/worker/expo/processors/contractPollProcessor.js +2 -2
- package/dist/cjs/worker/expo/taskRunner.js +3 -3
- package/dist/cjs/worker/messageBus.js +3 -0
- package/dist/esm/arkfee/estimator.js +1 -1
- package/dist/esm/arkfee/types.js +2 -1
- package/dist/esm/arknote/index.js +43 -4
- package/dist/esm/bip322/index.js +1 -1
- package/dist/esm/contracts/arkcontract.js +1 -1
- package/dist/esm/contracts/contractManager.js +40 -24
- package/dist/esm/contracts/contractWatcher.js +29 -22
- package/dist/esm/contracts/handlers/default.js +1 -1
- package/dist/esm/contracts/handlers/delegate.js +1 -1
- package/dist/esm/contracts/handlers/helpers.js +24 -1
- package/dist/esm/contracts/handlers/vhtlc.js +3 -5
- package/dist/esm/extension/asset/assetGroup.js +92 -5
- package/dist/esm/extension/asset/assetId.js +67 -3
- package/dist/esm/extension/asset/assetInput.js +18 -0
- package/dist/esm/extension/asset/assetOutput.js +15 -0
- package/dist/esm/extension/asset/assetRef.js +66 -0
- package/dist/esm/extension/asset/metadata.js +15 -0
- package/dist/esm/extension/asset/packet.js +4 -1
- package/dist/esm/extension/index.js +1 -1
- package/dist/esm/forfeit.js +14 -0
- package/dist/esm/identity/index.js +5 -0
- package/dist/esm/identity/seedIdentity.js +5 -5
- package/dist/esm/identity/singleKey.js +4 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/intent/index.js +28 -12
- package/dist/esm/providers/ark.js +3 -2
- package/dist/esm/providers/delegator.js +20 -1
- package/dist/esm/providers/expoArk.js +2 -2
- package/dist/esm/providers/indexer.js +2 -2
- package/dist/esm/providers/onchain.js +2 -1
- package/dist/esm/repositories/realm/schemas.js +2 -2
- package/dist/esm/repositories/realm/types.js +1 -1
- package/dist/esm/script/address.js +37 -6
- package/dist/esm/script/base.js +70 -1
- package/dist/esm/script/default.js +3 -0
- package/dist/esm/script/delegate.js +4 -0
- package/dist/esm/script/tapscript.js +25 -4
- package/dist/esm/script/vhtlc.js +35 -27
- package/dist/esm/storage/fileSystem.js +1 -1
- package/dist/esm/storage/inMemory.js +1 -1
- package/dist/esm/storage/indexedDB.js +1 -1
- package/dist/esm/storage/localStorage.js +1 -1
- package/dist/esm/tree/validation.js +1 -1
- package/dist/esm/utils/arkTransaction.js +5 -5
- package/dist/esm/utils/bip21.js +16 -3
- package/dist/esm/utils/syncCursors.js +4 -4
- package/dist/esm/utils/transaction.js +1 -1
- package/dist/esm/utils/transactionHistory.js +11 -11
- package/dist/esm/utils/unknownFields.js +3 -3
- package/dist/esm/wallet/asset-manager.js +4 -4
- package/dist/esm/wallet/batch.js +5 -5
- package/dist/esm/wallet/delegator.js +9 -8
- package/dist/esm/wallet/expo/background.js +3 -3
- package/dist/esm/wallet/expo/wallet.js +7 -7
- package/dist/esm/wallet/index.js +43 -0
- package/dist/esm/wallet/onchain.js +43 -5
- package/dist/esm/wallet/ramps.js +44 -14
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +22 -22
- package/dist/esm/wallet/serviceWorker/wallet.js +28 -24
- package/dist/esm/wallet/unroll.js +12 -8
- package/dist/esm/wallet/utils.js +1 -1
- package/dist/esm/wallet/vtxo-manager.js +122 -81
- package/dist/esm/wallet/wallet.js +232 -99
- package/dist/esm/worker/expo/asyncStorageTaskQueue.js +1 -1
- package/dist/esm/worker/expo/processors/contractPollProcessor.js +2 -2
- package/dist/esm/worker/expo/taskRunner.js +3 -3
- package/dist/esm/worker/messageBus.js +3 -0
- package/dist/types/arkfee/estimator.d.ts +1 -1
- package/dist/types/arkfee/types.d.ts +2 -1
- package/dist/types/arknote/index.d.ts +44 -4
- package/dist/types/bip322/index.d.ts +1 -1
- package/dist/types/contracts/arkcontract.d.ts +1 -1
- package/dist/types/contracts/contractManager.d.ts +40 -63
- package/dist/types/contracts/contractWatcher.d.ts +39 -18
- package/dist/types/contracts/handlers/default.d.ts +1 -1
- package/dist/types/contracts/handlers/delegate.d.ts +1 -1
- package/dist/types/contracts/handlers/helpers.d.ts +11 -1
- package/dist/types/contracts/types.d.ts +36 -26
- package/dist/types/extension/asset/assetGroup.d.ts +92 -1
- package/dist/types/extension/asset/assetId.d.ts +67 -3
- package/dist/types/extension/asset/assetInput.d.ts +18 -0
- package/dist/types/extension/asset/assetOutput.d.ts +15 -0
- package/dist/types/extension/asset/assetRef.d.ts +66 -0
- package/dist/types/extension/asset/metadata.d.ts +15 -0
- package/dist/types/extension/asset/packet.d.ts +4 -1
- package/dist/types/extension/index.d.ts +1 -1
- package/dist/types/forfeit.d.ts +14 -0
- package/dist/types/identity/index.d.ts +36 -0
- package/dist/types/identity/seedIdentity.d.ts +10 -8
- package/dist/types/identity/singleKey.d.ts +4 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/intent/index.d.ts +19 -6
- package/dist/types/providers/ark.d.ts +40 -2
- package/dist/types/providers/delegator.d.ts +54 -1
- package/dist/types/providers/expoArk.d.ts +2 -2
- package/dist/types/providers/indexer.d.ts +105 -2
- package/dist/types/providers/onchain.d.ts +62 -1
- package/dist/types/repositories/realm/schemas.d.ts +2 -2
- package/dist/types/repositories/realm/types.d.ts +2 -2
- package/dist/types/repositories/walletRepository.d.ts +16 -0
- package/dist/types/script/address.d.ts +35 -2
- package/dist/types/script/base.d.ts +66 -1
- package/dist/types/script/default.d.ts +3 -0
- package/dist/types/script/delegate.d.ts +4 -0
- package/dist/types/script/tapscript.d.ts +17 -2
- package/dist/types/script/vhtlc.d.ts +35 -27
- package/dist/types/storage/fileSystem.d.ts +1 -1
- package/dist/types/storage/inMemory.d.ts +1 -1
- package/dist/types/storage/index.d.ts +1 -1
- package/dist/types/storage/indexedDB.d.ts +1 -1
- package/dist/types/storage/localStorage.d.ts +1 -1
- package/dist/types/utils/arkTransaction.d.ts +3 -3
- package/dist/types/utils/bip21.d.ts +17 -0
- package/dist/types/utils/syncCursors.d.ts +4 -4
- package/dist/types/utils/transaction.d.ts +1 -1
- package/dist/types/utils/transactionHistory.d.ts +3 -3
- package/dist/types/utils/unknownFields.d.ts +5 -5
- package/dist/types/wallet/asset-manager.d.ts +3 -3
- package/dist/types/wallet/batch.d.ts +27 -7
- package/dist/types/wallet/delegator.d.ts +10 -0
- package/dist/types/wallet/expo/background.d.ts +4 -4
- package/dist/types/wallet/expo/wallet.d.ts +10 -10
- package/dist/types/wallet/index.d.ts +457 -25
- package/dist/types/wallet/onchain.d.ts +42 -4
- package/dist/types/wallet/ramps.d.ts +40 -10
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +4 -4
- package/dist/types/wallet/serviceWorker/wallet.d.ts +71 -33
- package/dist/types/wallet/unroll.d.ts +8 -6
- package/dist/types/wallet/vtxo-manager.d.ts +146 -93
- package/dist/types/wallet/wallet.d.ts +91 -33
- package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +1 -1
- package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +1 -1
- package/dist/types/worker/expo/taskRunner.d.ts +6 -6
- package/dist/types/worker/messageBus.d.ts +5 -3
- package/package.json +18 -10
|
@@ -15,11 +15,13 @@ class Metadata {
|
|
|
15
15
|
this.key = key;
|
|
16
16
|
this.value = value;
|
|
17
17
|
}
|
|
18
|
+
/** Create a metadata entry from raw key and value bytes. */
|
|
18
19
|
static create(key, value) {
|
|
19
20
|
const md = new Metadata(key, value);
|
|
20
21
|
md.validate();
|
|
21
22
|
return md;
|
|
22
23
|
}
|
|
24
|
+
/** Decode metadata from its hex string form. */
|
|
23
25
|
static fromString(s) {
|
|
24
26
|
let buf;
|
|
25
27
|
try {
|
|
@@ -30,6 +32,7 @@ class Metadata {
|
|
|
30
32
|
}
|
|
31
33
|
return Metadata.fromBytes(buf);
|
|
32
34
|
}
|
|
35
|
+
/** Decode metadata from its serialized bytes. */
|
|
33
36
|
static fromBytes(buf) {
|
|
34
37
|
if (!buf || buf.length === 0) {
|
|
35
38
|
throw new Error("missing metadata");
|
|
@@ -37,11 +40,13 @@ class Metadata {
|
|
|
37
40
|
const reader = new utils_1.BufferReader(buf);
|
|
38
41
|
return Metadata.fromReader(reader);
|
|
39
42
|
}
|
|
43
|
+
/** Serialize metadata to raw bytes. */
|
|
40
44
|
serialize() {
|
|
41
45
|
const writer = new utils_1.BufferWriter();
|
|
42
46
|
this.serializeTo(writer);
|
|
43
47
|
return writer.toBytes();
|
|
44
48
|
}
|
|
49
|
+
/** Encode metadata to a hex string. */
|
|
45
50
|
toString() {
|
|
46
51
|
return base_1.hex.encode(this.serialize());
|
|
47
52
|
}
|
|
@@ -51,6 +56,7 @@ class Metadata {
|
|
|
51
56
|
get valueString() {
|
|
52
57
|
return new TextDecoder().decode(this.value);
|
|
53
58
|
}
|
|
59
|
+
/** Validate the metadata key and value. */
|
|
54
60
|
validate() {
|
|
55
61
|
if (this.key.length === 0) {
|
|
56
62
|
throw new Error("missing metadata key");
|
|
@@ -59,6 +65,7 @@ class Metadata {
|
|
|
59
65
|
throw new Error("missing metadata value");
|
|
60
66
|
}
|
|
61
67
|
}
|
|
68
|
+
/** Decode metadata from a buffer reader. */
|
|
62
69
|
static fromReader(reader) {
|
|
63
70
|
let key;
|
|
64
71
|
let value;
|
|
@@ -78,6 +85,7 @@ class Metadata {
|
|
|
78
85
|
md.validate();
|
|
79
86
|
return md;
|
|
80
87
|
}
|
|
88
|
+
/** Serialize metadata into an existing buffer writer. */
|
|
81
89
|
serializeTo(writer) {
|
|
82
90
|
writer.writeVarSlice(this.key);
|
|
83
91
|
writer.writeVarSlice(this.value);
|
|
@@ -88,6 +96,7 @@ class MetadataList {
|
|
|
88
96
|
constructor(items) {
|
|
89
97
|
this.items = items;
|
|
90
98
|
}
|
|
99
|
+
/** Create a metadata list from its hex string form. */
|
|
91
100
|
static fromString(s) {
|
|
92
101
|
let buf;
|
|
93
102
|
try {
|
|
@@ -98,6 +107,7 @@ class MetadataList {
|
|
|
98
107
|
}
|
|
99
108
|
return MetadataList.fromBytes(buf);
|
|
100
109
|
}
|
|
110
|
+
/** Decode a metadata list from its serialized bytes. */
|
|
101
111
|
static fromBytes(buf) {
|
|
102
112
|
if (!buf || buf.length === 0) {
|
|
103
113
|
throw new Error("missing metadata list");
|
|
@@ -105,28 +115,33 @@ class MetadataList {
|
|
|
105
115
|
const reader = new utils_1.BufferReader(buf);
|
|
106
116
|
return MetadataList.fromReader(reader);
|
|
107
117
|
}
|
|
118
|
+
/** Decode a metadata list from a buffer reader. */
|
|
108
119
|
static fromReader(reader) {
|
|
109
120
|
const count = Number(reader.readVarUint());
|
|
110
121
|
const items = Array.from({ length: count }, () => Metadata.fromReader(reader));
|
|
111
122
|
return new MetadataList(items);
|
|
112
123
|
}
|
|
124
|
+
/** Serialize the metadata list into an existing buffer writer. */
|
|
113
125
|
serializeTo(writer) {
|
|
114
126
|
writer.writeVarUint(this.items.length);
|
|
115
127
|
for (const item of this) {
|
|
116
128
|
item.serializeTo(writer);
|
|
117
129
|
}
|
|
118
130
|
}
|
|
131
|
+
/** Serialize the metadata list to raw bytes. */
|
|
119
132
|
serialize() {
|
|
120
133
|
const writer = new utils_1.BufferWriter();
|
|
121
134
|
this.serializeTo(writer);
|
|
122
135
|
return writer.toBytes();
|
|
123
136
|
}
|
|
137
|
+
/** Iterate through metadata entries in insertion order. */
|
|
124
138
|
[Symbol.iterator]() {
|
|
125
139
|
return this.items[Symbol.iterator]();
|
|
126
140
|
}
|
|
127
141
|
get length() {
|
|
128
142
|
return this.items.length;
|
|
129
143
|
}
|
|
144
|
+
/** Compute the tagged Merkle root for the metadata list. */
|
|
130
145
|
hash() {
|
|
131
146
|
if (this.items.length === 0)
|
|
132
147
|
throw new Error("missing metadata list");
|
|
@@ -13,6 +13,7 @@ class Packet {
|
|
|
13
13
|
constructor(groups) {
|
|
14
14
|
this.groups = groups;
|
|
15
15
|
}
|
|
16
|
+
/** Create a validated asset packet from a list of asset groups. */
|
|
16
17
|
static create(groups) {
|
|
17
18
|
const p = new Packet(groups);
|
|
18
19
|
p.validate();
|
|
@@ -46,13 +47,14 @@ class Packet {
|
|
|
46
47
|
type() {
|
|
47
48
|
return Packet.PACKET_TYPE;
|
|
48
49
|
}
|
|
50
|
+
/** Convert the packet into the batch-leaf form for a specific intent transaction id. */
|
|
49
51
|
leafTxPacket(intentTxid) {
|
|
50
52
|
const leafGroups = this.groups.map((group) => group.toBatchLeafAssetGroup(intentTxid));
|
|
51
53
|
return new Packet(leafGroups);
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
56
|
* serialize encodes the packet as raw bytes (varint group count + group data).
|
|
55
|
-
* Does NOT include OP_RETURN,
|
|
57
|
+
* Does NOT include OP_RETURN, Arkade magic bytes (`ARK`), or TLV type/length; those are
|
|
56
58
|
* added by the Extension module.
|
|
57
59
|
*/
|
|
58
60
|
serialize() {
|
|
@@ -72,6 +74,7 @@ class Packet {
|
|
|
72
74
|
toString() {
|
|
73
75
|
return base_1.hex.encode(this.serialize());
|
|
74
76
|
}
|
|
77
|
+
/** Validate packet structure and cross-group references. */
|
|
75
78
|
validate() {
|
|
76
79
|
if (this.groups.length === 0) {
|
|
77
80
|
throw new Error("missing assets");
|
|
@@ -11,7 +11,7 @@ var packet_3 = require("./packet");
|
|
|
11
11
|
Object.defineProperty(exports, "UnknownPacket", { enumerable: true, get: function () { return packet_3.UnknownPacket; } });
|
|
12
12
|
/**
|
|
13
13
|
* ArkadeMagic is the 3-byte magic prefix ("ARK") that identifies an OP_RETURN
|
|
14
|
-
* output as an
|
|
14
|
+
* output as an Arkade extension blob.
|
|
15
15
|
*/
|
|
16
16
|
exports.ARKADE_MAGIC = new Uint8Array([0x41, 0x52, 0x4b]); // "ARK"
|
|
17
17
|
/**
|
package/dist/cjs/forfeit.js
CHANGED
|
@@ -4,6 +4,13 @@ exports.buildForfeitTx = buildForfeitTx;
|
|
|
4
4
|
exports.buildForfeitTxWithOutput = buildForfeitTxWithOutput;
|
|
5
5
|
const transaction_1 = require("./utils/transaction");
|
|
6
6
|
const anchor_1 = require("./utils/anchor");
|
|
7
|
+
/**
|
|
8
|
+
* Build a forfeit transaction that spends the provided inputs to a single forfeit output.
|
|
9
|
+
*
|
|
10
|
+
* @param inputs - Inputs to include in the forfeit transaction
|
|
11
|
+
* @param forfeitPkScript - ScriptPubKey for the forfeit output
|
|
12
|
+
* @param txLocktime - Optional locktime to apply to the transaction
|
|
13
|
+
*/
|
|
7
14
|
function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
8
15
|
let amount = 0n;
|
|
9
16
|
for (const input of inputs) {
|
|
@@ -17,6 +24,13 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
17
24
|
amount,
|
|
18
25
|
}, txLocktime);
|
|
19
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Build a forfeit transaction using an explicit output descriptor (used for delegated renewals)
|
|
29
|
+
*
|
|
30
|
+
* @param inputs - Inputs to include in the forfeit transaction
|
|
31
|
+
* @param output - Primary transaction output
|
|
32
|
+
* @param txLocktime - Optional locktime to apply to the transaction
|
|
33
|
+
*/
|
|
20
34
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
21
35
|
const tx = new transaction_1.Transaction({
|
|
22
36
|
version: 3,
|
|
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isBatchSignable = isBatchSignable;
|
|
18
|
+
/** Type guard for identities that support batch signing. */
|
|
19
|
+
function isBatchSignable(identity) {
|
|
20
|
+
return ("signMultiple" in identity &&
|
|
21
|
+
typeof identity.signMultiple === "function");
|
|
22
|
+
}
|
|
17
23
|
__exportStar(require("./singleKey"), exports);
|
|
18
24
|
__exportStar(require("./seedIdentity"), exports);
|
|
@@ -17,7 +17,7 @@ const ALL_SIGHASH = Object.values(btc_signer_1.SigHash).filter((x) => typeof x =
|
|
|
17
17
|
function detectNetwork(descriptor) {
|
|
18
18
|
return descriptor.includes("tpub") ? descriptors_scure_1.networks.testnet : descriptors_scure_1.networks.bitcoin;
|
|
19
19
|
}
|
|
20
|
-
function hasDescriptor(opts) {
|
|
20
|
+
function hasDescriptor(opts = {}) {
|
|
21
21
|
return "descriptor" in opts && typeof opts.descriptor === "string";
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -44,7 +44,7 @@ function buildDescriptor(seed, isMainnet) {
|
|
|
44
44
|
* format is HD-ready, allowing future support for multiple addresses
|
|
45
45
|
* and change derivation.
|
|
46
46
|
*
|
|
47
|
-
* Prefer this (or
|
|
47
|
+
* Prefer this (or @see MnemonicIdentity) over `SingleKey` for new
|
|
48
48
|
* integrations — `SingleKey` exists for backward compatibility with
|
|
49
49
|
* raw nsec-style keys.
|
|
50
50
|
*
|
|
@@ -101,7 +101,7 @@ class SeedIdentity {
|
|
|
101
101
|
* @param seed - 64-byte seed (typically from mnemonicToSeedSync)
|
|
102
102
|
* @param opts - Network selection or custom descriptor.
|
|
103
103
|
*/
|
|
104
|
-
static fromSeed(seed, opts) {
|
|
104
|
+
static fromSeed(seed, opts = {}) {
|
|
105
105
|
const descriptor = hasDescriptor(opts)
|
|
106
106
|
? opts.descriptor
|
|
107
107
|
: buildDescriptor(seed, opts.isMainnet ?? true);
|
|
@@ -161,7 +161,7 @@ exports.SeedIdentity = SeedIdentity;
|
|
|
161
161
|
*
|
|
162
162
|
* This is the most user-friendly identity type — recommended for wallet
|
|
163
163
|
* applications where users manage their own backup phrase. Extends
|
|
164
|
-
*
|
|
164
|
+
* @see SeedIdentity with mnemonic validation and optional passphrase
|
|
165
165
|
* support.
|
|
166
166
|
*
|
|
167
167
|
* @example
|
|
@@ -185,7 +185,7 @@ class MnemonicIdentity extends SeedIdentity {
|
|
|
185
185
|
* @param phrase - BIP39 mnemonic phrase (12 or 24 words)
|
|
186
186
|
* @param opts - Network selection or custom descriptor, plus optional passphrase
|
|
187
187
|
*/
|
|
188
|
-
static fromMnemonic(phrase, opts) {
|
|
188
|
+
static fromMnemonic(phrase, opts = {}) {
|
|
189
189
|
if (!(0, bip39_1.validateMnemonic)(phrase, english_js_1.wordlist)) {
|
|
190
190
|
throw new Error("Invalid mnemonic");
|
|
191
191
|
}
|
|
@@ -29,12 +29,15 @@ class SingleKey {
|
|
|
29
29
|
constructor(key) {
|
|
30
30
|
this.key = key || (0, utils_js_1.randomPrivateKeyBytes)();
|
|
31
31
|
}
|
|
32
|
+
/** Create a signing identity from raw private key bytes. */
|
|
32
33
|
static fromPrivateKey(privateKey) {
|
|
33
34
|
return new SingleKey(privateKey);
|
|
34
35
|
}
|
|
36
|
+
/** Create a signing identity from a hex-encoded private key. */
|
|
35
37
|
static fromHex(privateKeyHex) {
|
|
36
38
|
return new SingleKey(base_1.hex.decode(privateKeyHex));
|
|
37
39
|
}
|
|
40
|
+
/** Create a signing identity with a freshly generated random private key. */
|
|
38
41
|
static fromRandomBytes() {
|
|
39
42
|
return new SingleKey((0, utils_js_1.randomPrivateKeyBytes)());
|
|
40
43
|
}
|
|
@@ -92,6 +95,7 @@ class SingleKey {
|
|
|
92
95
|
}
|
|
93
96
|
exports.SingleKey = SingleKey;
|
|
94
97
|
class ReadonlySingleKey {
|
|
98
|
+
/** Create a readonly identity from a compressed public key. */
|
|
95
99
|
constructor(publicKey) {
|
|
96
100
|
this.publicKey = publicKey;
|
|
97
101
|
if (publicKey.length !== 33) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -36,9 +36,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.isArkContract = exports.contractFromArkContractWithAddress = exports.contractFromArkContract = void 0;
|
|
39
|
+
exports.getArkPsbtFields = exports.setArkPsbtField = exports.ArkPsbtFieldKeyType = exports.ArkPsbtFieldKey = exports.TapTreeCoder = exports.CLTVMultisigTapscript = exports.ConditionMultisigTapscript = exports.ConditionCSVMultisigTapscript = exports.CSVMultisigTapscript = exports.MultisigTapscript = exports.decodeTapscript = exports.DEFAULT_MESSAGE_TIMEOUTS = exports.ServiceWorkerReadonlyWallet = exports.ServiceWorkerWallet = exports.ServiceWorkerTimeoutError = exports.MessageBusNotInitializedError = exports.MESSAGE_BUS_NOT_INITIALIZED = exports.DelegatorNotConfiguredError = exports.ReadonlyWalletError = exports.WalletNotInitializedError = exports.WalletMessageHandler = exports.MessageBus = exports.setupServiceWorker = exports.SettlementEventType = exports.ChainTxType = exports.IndexerTxType = exports.TxType = exports.VHTLC = exports.VtxoScript = exports.DelegateVtxo = exports.DefaultVtxo = exports.ArkAddress = exports.RestIndexerProvider = exports.RestArkProvider = exports.EsploraProvider = exports.ESPLORA_URL = exports.RestDelegatorProvider = exports.DelegatorManagerImpl = exports.VtxoManager = exports.Ramps = exports.OnchainWallet = exports.isBatchSignable = exports.ReadonlyDescriptorIdentity = exports.MnemonicIdentity = exports.SeedIdentity = exports.ReadonlySingleKey = exports.SingleKey = exports.ReadonlyWallet = exports.Wallet = exports.asset = void 0;
|
|
40
|
+
exports.encodeArkContract = exports.VHTLCContractHandler = exports.DelegateContractHandler = exports.DefaultContractHandler = exports.contractHandlers = exports.ContractWatcher = exports.ContractManager = exports.getSequence = exports.isExpired = exports.isSubdust = exports.isSpendable = exports.isRecoverable = exports.buildForfeitTx = exports.validateConnectorsTxGraph = exports.validateVtxoTxGraph = exports.Batch = exports.maybeArkError = exports.ArkError = exports.Transaction = exports.Unroll = exports.P2A = exports.TxTree = exports.BIP322 = exports.Intent = exports.ContractRepositoryImpl = exports.WalletRepositoryImpl = exports.rollbackMigration = exports.getMigrationStatus = exports.requiresMigration = exports.migrateWalletRepository = exports.MIGRATION_KEY = exports.InMemoryContractRepository = exports.InMemoryWalletRepository = exports.IndexedDBContractRepository = exports.IndexedDBWalletRepository = exports.openDatabase = exports.closeDatabase = exports.networks = exports.ArkNote = exports.isValidArkAddress = exports.isVtxoExpiringSoon = exports.combineTapscriptSigs = exports.hasBoardingTxExpired = exports.waitForIncomingFunds = exports.verifyTapscriptSignatures = exports.buildOffchainTx = exports.ConditionWitness = exports.VtxoTaprootTree = exports.VtxoTreeExpiry = exports.CosignerPublicKey = void 0;
|
|
41
|
+
exports.isArkContract = exports.contractFromArkContractWithAddress = exports.contractFromArkContract = exports.decodeArkContract = void 0;
|
|
42
42
|
const transaction_1 = require("./utils/transaction");
|
|
43
43
|
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
44
44
|
const singleKey_1 = require("./identity/singleKey");
|
|
@@ -48,6 +48,8 @@ const seedIdentity_1 = require("./identity/seedIdentity");
|
|
|
48
48
|
Object.defineProperty(exports, "SeedIdentity", { enumerable: true, get: function () { return seedIdentity_1.SeedIdentity; } });
|
|
49
49
|
Object.defineProperty(exports, "MnemonicIdentity", { enumerable: true, get: function () { return seedIdentity_1.MnemonicIdentity; } });
|
|
50
50
|
Object.defineProperty(exports, "ReadonlyDescriptorIdentity", { enumerable: true, get: function () { return seedIdentity_1.ReadonlyDescriptorIdentity; } });
|
|
51
|
+
const identity_1 = require("./identity");
|
|
52
|
+
Object.defineProperty(exports, "isBatchSignable", { enumerable: true, get: function () { return identity_1.isBatchSignable; } });
|
|
51
53
|
const address_1 = require("./script/address");
|
|
52
54
|
Object.defineProperty(exports, "ArkAddress", { enumerable: true, get: function () { return address_1.ArkAddress; } });
|
|
53
55
|
const vhtlc_1 = require("./script/vhtlc");
|
package/dist/cjs/intent/index.js
CHANGED
|
@@ -12,10 +12,11 @@ const base_2 = require("../script/base");
|
|
|
12
12
|
* Intent proof implementation for Bitcoin message signing.
|
|
13
13
|
*
|
|
14
14
|
* Intent proof defines a standard for signing Bitcoin messages as well as proving
|
|
15
|
-
* ownership of
|
|
16
|
-
* validating Intent proof.
|
|
15
|
+
* ownership of outputs.
|
|
17
16
|
*
|
|
18
|
-
*
|
|
17
|
+
* This namespace provides utilities for creating and validating Intent proof.
|
|
18
|
+
*
|
|
19
|
+
* It is greatly inspired by BIP322.
|
|
19
20
|
* @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
20
21
|
*
|
|
21
22
|
* @example
|
|
@@ -37,11 +38,11 @@ var Intent;
|
|
|
37
38
|
* Creates a new Intent proof unsigned transaction.
|
|
38
39
|
*
|
|
39
40
|
* This function constructs a special transaction that can be signed to prove
|
|
40
|
-
* ownership of
|
|
41
|
+
* ownership of onchain and virtual outputs. The proof includes the message to be
|
|
41
42
|
* signed and the inputs/outputs that demonstrate ownership.
|
|
42
43
|
*
|
|
43
44
|
* @param message - The Intent message to be signed, either raw string of Message object
|
|
44
|
-
* @param
|
|
45
|
+
* @param ins - Array of transaction inputs to prove ownership of
|
|
45
46
|
* @param outputs - Optional array of transaction outputs
|
|
46
47
|
* @returns An unsigned Intent proof transaction
|
|
47
48
|
*/
|
|
@@ -56,12 +57,18 @@ var Intent;
|
|
|
56
57
|
throw new Error("invalid inputs");
|
|
57
58
|
if (!validateOutputs(outputs))
|
|
58
59
|
throw new Error("invalid outputs");
|
|
59
|
-
//
|
|
60
|
+
// Create the initial transaction to spend.
|
|
60
61
|
const toSpend = craftToSpendTx(message, inputs[0].witnessUtxo.script);
|
|
61
|
-
//
|
|
62
|
+
// Create the transaction to sign.
|
|
62
63
|
return craftToSignTx(toSpend, inputs, outputs);
|
|
63
64
|
}
|
|
64
65
|
Intent.create = create;
|
|
66
|
+
/**
|
|
67
|
+
* Compute the fee paid by an intent proof transaction.
|
|
68
|
+
*
|
|
69
|
+
* @param proof - Intent proof transaction
|
|
70
|
+
* @returns The fee in satoshis
|
|
71
|
+
*/
|
|
65
72
|
function fee(proof) {
|
|
66
73
|
let sumOfInputs = 0n;
|
|
67
74
|
for (let i = 0; i < proof.inputsLength; i++) {
|
|
@@ -83,6 +90,12 @@ var Intent;
|
|
|
83
90
|
return Number(sumOfInputs - sumOfOutputs);
|
|
84
91
|
}
|
|
85
92
|
Intent.fee = fee;
|
|
93
|
+
/**
|
|
94
|
+
* Serialize an intent message to the canonical JSON string used for signing.
|
|
95
|
+
*
|
|
96
|
+
* @param message - Intent message payload
|
|
97
|
+
* @returns Canonical string form of the message
|
|
98
|
+
*/
|
|
86
99
|
function encodeMessage(message) {
|
|
87
100
|
switch (message.type) {
|
|
88
101
|
case "register":
|
|
@@ -143,7 +156,7 @@ function validateOutputs(outputs) {
|
|
|
143
156
|
*
|
|
144
157
|
* @param message - The message to embed
|
|
145
158
|
* @param pkScript - The scriptPubKey of the signer's address
|
|
146
|
-
* @param tag - Tagged-hash tag (defaults to the
|
|
159
|
+
* @param tag - Tagged-hash tag (defaults to the Arkade intent proof tag)
|
|
147
160
|
*/
|
|
148
161
|
function craftToSpendTx(message, pkScript, tag = exports.TAG_INTENT_PROOF) {
|
|
149
162
|
const messageHash = hashMessage(message, tag);
|
|
@@ -169,12 +182,15 @@ function craftToSpendTx(message, pkScript, tag = exports.TAG_INTENT_PROOF) {
|
|
|
169
182
|
// craftToSignTx creates the transaction that will be signed for the proof
|
|
170
183
|
function craftToSignTx(toSpend, inputs, outputs) {
|
|
171
184
|
const firstInput = inputs[0];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
185
|
+
// Proof tx is never broadcast onchain — toSpend references a zero-hash
|
|
186
|
+
// outpoint (see BIP-322). The tx exists only as a sighash commitment
|
|
187
|
+
// the server verifies signatures against; nLockTime and nSequence carry
|
|
188
|
+
// no consensus meaning here, they only need to match between signer and
|
|
189
|
+
// verifier. Use lockTime = 0 (BIP-322 convention) and leave each input's
|
|
190
|
+
// nSequence untouched.
|
|
175
191
|
const tx = new transaction_1.Transaction({
|
|
176
192
|
version: 2,
|
|
177
|
-
lockTime,
|
|
193
|
+
lockTime: 0,
|
|
178
194
|
});
|
|
179
195
|
// add the first "toSpend" input
|
|
180
196
|
tx.addInput({
|
|
@@ -19,11 +19,12 @@ var SettlementEventType;
|
|
|
19
19
|
SettlementEventType["StreamStarted"] = "stream_started";
|
|
20
20
|
})(SettlementEventType || (exports.SettlementEventType = SettlementEventType = {}));
|
|
21
21
|
/**
|
|
22
|
-
* REST-based
|
|
22
|
+
* REST-based Arkade provider implementation.
|
|
23
|
+
*
|
|
23
24
|
* @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.ArkService
|
|
24
25
|
* @example
|
|
25
26
|
* ```typescript
|
|
26
|
-
* const provider = new RestArkProvider('https://
|
|
27
|
+
* const provider = new RestArkProvider('https://arkade.computer');
|
|
27
28
|
* const info = await provider.getInfo();
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RestDelegatorProvider = void 0;
|
|
4
4
|
const intent_1 = require("../intent");
|
|
5
5
|
/**
|
|
6
|
-
* REST-based
|
|
6
|
+
* REST-based delegation provider implementation.
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
9
|
* const provider = new RestDelegatorProvider('https://delegator.example.com');
|
|
@@ -12,9 +12,22 @@ const intent_1 = require("../intent");
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
class RestDelegatorProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Create a REST delegation provider targeting the given base URL.
|
|
17
|
+
*
|
|
18
|
+
* @param url - Base URL of the delegation service
|
|
19
|
+
*/
|
|
15
20
|
constructor(url) {
|
|
16
21
|
this.url = url;
|
|
17
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Submit a delegation request to the remote delegation service.
|
|
25
|
+
*
|
|
26
|
+
* @param intent - Signed register intent to delegate
|
|
27
|
+
* @param forfeitTxs - Forfeit transactions associated with the delegation request
|
|
28
|
+
* @param options - Optional delegate behavior flags
|
|
29
|
+
* @throws Error if the remote service rejects the request
|
|
30
|
+
*/
|
|
18
31
|
async delegate(intent, forfeitTxs, options) {
|
|
19
32
|
const url = `${this.url}/v1/delegate`;
|
|
20
33
|
const response = await fetch(url, {
|
|
@@ -36,6 +49,12 @@ class RestDelegatorProvider {
|
|
|
36
49
|
throw new Error(`Failed to delegate: ${errorText}`);
|
|
37
50
|
}
|
|
38
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetch delegate metadata exposed by the remote delegation service.
|
|
54
|
+
*
|
|
55
|
+
* @returns Delegate identity and fee information
|
|
56
|
+
* @throws Error if the remote service returns invalid data
|
|
57
|
+
*/
|
|
39
58
|
async getDelegateInfo() {
|
|
40
59
|
const url = `${this.url}/v1/delegator/info`;
|
|
41
60
|
const response = await fetch(url);
|
|
@@ -4,7 +4,7 @@ exports.ExpoArkProvider = void 0;
|
|
|
4
4
|
const ark_1 = require("./ark");
|
|
5
5
|
const expoUtils_1 = require("./expoUtils");
|
|
6
6
|
/**
|
|
7
|
-
* Expo-compatible
|
|
7
|
+
* Expo-compatible Arkade provider implementation using expo/fetch for SSE support.
|
|
8
8
|
* This provider works specifically in React Native/Expo environments where
|
|
9
9
|
* standard EventSource is not available but expo/fetch provides SSE capabilities.
|
|
10
10
|
*
|
|
@@ -12,7 +12,7 @@ const expoUtils_1 = require("./expoUtils");
|
|
|
12
12
|
* ```typescript
|
|
13
13
|
* import { ExpoArkProvider } from '@arkade-os/sdk/providers/expo';
|
|
14
14
|
*
|
|
15
|
-
* const provider = new ExpoArkProvider('https://
|
|
15
|
+
* const provider = new ExpoArkProvider('https://arkade.computer');
|
|
16
16
|
* const info = await provider.getInfo();
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
@@ -20,11 +20,11 @@ var ChainTxType;
|
|
|
20
20
|
ChainTxType["CHECKPOINT"] = "INDEXER_CHAINED_TX_TYPE_CHECKPOINT";
|
|
21
21
|
})(ChainTxType || (exports.ChainTxType = ChainTxType = {}));
|
|
22
22
|
/**
|
|
23
|
-
* REST-based
|
|
23
|
+
* REST-based indexer provider implementation.
|
|
24
24
|
* @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.IndexerService
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
* const provider = new RestIndexerProvider('https://
|
|
27
|
+
* const provider = new RestIndexerProvider('https://arkade.computer');
|
|
28
28
|
* const commitmentTx = await provider.getCommitmentTx("6686af8f3be3517880821f62e6c3d749b9d6713736a1d8e229a55daa659446b2");
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
@@ -13,11 +13,12 @@ exports.ESPLORA_URL = {
|
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Implementation of the onchain provider interface for esplora REST API.
|
|
16
|
+
*
|
|
16
17
|
* @see https://mempool.space/docs/api/rest
|
|
17
18
|
* @example
|
|
18
19
|
* ```typescript
|
|
19
20
|
* const provider = new EsploraProvider("https://mempool.space/api");
|
|
20
|
-
* const
|
|
21
|
+
* const outputs = await provider.getCoins("bcrt1q679zsd45msawvr7782r0twvmukns3drlstjt77");
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
24
|
class EsploraProvider {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Realm object schemas for the
|
|
3
|
+
* Realm object schemas for the Arkade wallet.
|
|
4
4
|
*
|
|
5
5
|
* All schema names are prefixed with "Ark" to avoid collisions with
|
|
6
6
|
* other Realm schemas in the consuming application.
|
|
@@ -96,7 +96,7 @@ exports.ArkContractSchema = {
|
|
|
96
96
|
},
|
|
97
97
|
};
|
|
98
98
|
/**
|
|
99
|
-
* All Realm schemas needed by the
|
|
99
|
+
* All Realm schemas needed by the Arkade wallet repositories.
|
|
100
100
|
* Pass this array to your Realm configuration's `schema` property.
|
|
101
101
|
*/
|
|
102
102
|
exports.ArkRealmSchemas = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Minimal interface for the subset of the Realm API used by the
|
|
4
|
-
*
|
|
4
|
+
* Arkade repositories. Consumers pass their real Realm instance and
|
|
5
5
|
* the compiler validates it satisfies this shape.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -4,13 +4,20 @@ exports.ArkAddress = void 0;
|
|
|
4
4
|
const base_1 = require("@scure/base");
|
|
5
5
|
const script_js_1 = require("@scure/btc-signer/script.js");
|
|
6
6
|
/**
|
|
7
|
-
* ArkAddress allows
|
|
8
|
-
*
|
|
7
|
+
* ArkAddress allows creating and decoding bech32m-encoded Arkade addresses.
|
|
8
|
+
*
|
|
9
|
+
* An Arkade address is composed of:
|
|
9
10
|
* - a human readable prefix (hrp)
|
|
10
11
|
* - a version byte (1 byte)
|
|
11
12
|
* - a server public key (32 bytes)
|
|
12
13
|
* - a vtxo taproot public key (32 bytes)
|
|
13
14
|
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This is an Arkade-specific address format.
|
|
17
|
+
* It is distinct from the Taproot onchain address returned by `VtxoScript.onchainAddress`.
|
|
18
|
+
*
|
|
19
|
+
* @see VtxoScript
|
|
20
|
+
*
|
|
14
21
|
* @example
|
|
15
22
|
* ```typescript
|
|
16
23
|
* const address = new ArkAddress(
|
|
@@ -26,6 +33,16 @@ const script_js_1 = require("@scure/btc-signer/script.js");
|
|
|
26
33
|
* ```
|
|
27
34
|
*/
|
|
28
35
|
class ArkAddress {
|
|
36
|
+
/**
|
|
37
|
+
* Create an Arkade address from its server key, vtxo taproot public key, and prefix.
|
|
38
|
+
*
|
|
39
|
+
* @param serverPubKey - 32-byte Arkade server public key
|
|
40
|
+
* @param vtxoTaprootKey - 32-byte tweaked vtxo taproot public key
|
|
41
|
+
* @param hrp - Bech32 human-readable prefix
|
|
42
|
+
* @param version - Address version byte
|
|
43
|
+
* @defaultValue `version = 0`
|
|
44
|
+
* @throws Error if either public key is not 32 bytes long
|
|
45
|
+
*/
|
|
29
46
|
constructor(serverPubKey, vtxoTaprootKey, hrp, version = 0) {
|
|
30
47
|
this.serverPubKey = serverPubKey;
|
|
31
48
|
this.vtxoTaprootKey = vtxoTaprootKey;
|
|
@@ -40,13 +57,21 @@ class ArkAddress {
|
|
|
40
57
|
vtxoTaprootKey.length);
|
|
41
58
|
}
|
|
42
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Decode an Arkade address from its bech32m string form.
|
|
62
|
+
*
|
|
63
|
+
* @param address - Bech32m-encoded Arkade address
|
|
64
|
+
* @returns Decoded Arkade address
|
|
65
|
+
* @throws Error if the address is malformed or has an invalid payload length
|
|
66
|
+
* @see encode
|
|
67
|
+
*/
|
|
43
68
|
static decode(address) {
|
|
44
69
|
const decoded = base_1.bech32m.decodeUnsafe(address, 1023);
|
|
45
70
|
if (!decoded) {
|
|
46
71
|
throw new Error("Invalid address");
|
|
47
72
|
}
|
|
48
73
|
const data = new Uint8Array(base_1.bech32m.fromWords(decoded.words));
|
|
49
|
-
// First the version byte, then 32 bytes server pubkey, then 32 bytes vtxo taproot
|
|
74
|
+
// First the version byte, then 32 bytes server pubkey, then 32 bytes vtxo taproot public key.
|
|
50
75
|
if (data.length !== 1 + 32 + 32) {
|
|
51
76
|
throw new Error("Invalid data length, expected 65 bytes, got " + data.length);
|
|
52
77
|
}
|
|
@@ -55,8 +80,14 @@ class ArkAddress {
|
|
|
55
80
|
const vtxoTaprootPubKey = data.slice(33, 65);
|
|
56
81
|
return new ArkAddress(serverPubKey, vtxoTaprootPubKey, decoded.prefix, version);
|
|
57
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Encode the address to its bech32m string form.
|
|
85
|
+
*
|
|
86
|
+
* @returns Bech32m-encoded Arkade address
|
|
87
|
+
* @see decode
|
|
88
|
+
*/
|
|
58
89
|
encode() {
|
|
59
|
-
// Combine version byte, server pubkey, and vtxo taproot
|
|
90
|
+
// Combine version byte, server pubkey, and vtxo taproot public key.
|
|
60
91
|
const data = new Uint8Array(1 + 32 + 32);
|
|
61
92
|
data[0] = this.version;
|
|
62
93
|
data.set(this.serverPubKey, 1);
|
|
@@ -64,11 +95,11 @@ class ArkAddress {
|
|
|
64
95
|
const words = base_1.bech32m.toWords(data);
|
|
65
96
|
return base_1.bech32m.encode(this.hrp, words, 1023);
|
|
66
97
|
}
|
|
67
|
-
|
|
98
|
+
/** ScriptPubKey used to send non-dust funds to the address. */
|
|
68
99
|
get pkScript() {
|
|
69
100
|
return script_js_1.Script.encode(["OP_1", this.vtxoTaprootKey]);
|
|
70
101
|
}
|
|
71
|
-
|
|
102
|
+
/** ScriptPubKey used to send sub-dust funds to the address. */
|
|
72
103
|
get subdustPkScript() {
|
|
73
104
|
return script_js_1.Script.encode(["RETURN", this.vtxoTaprootKey]);
|
|
74
105
|
}
|