@arkade-os/sdk 0.4.15 → 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 +102 -96
- 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 +1 -1
- 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/seedIdentity.js +2 -2
- package/dist/cjs/identity/singleKey.js +4 -0
- 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 +17 -2
- 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 +122 -82
- package/dist/cjs/wallet/wallet.js +125 -67
- 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 +1 -1
- 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/seedIdentity.js +2 -2
- package/dist/esm/identity/singleKey.js +4 -0
- package/dist/esm/index.js +1 -1
- 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 +17 -2
- 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 +121 -81
- package/dist/esm/wallet/wallet.js +125 -67
- 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 +1 -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 +16 -0
- package/dist/types/identity/seedIdentity.d.ts +8 -6
- package/dist/types/identity/singleKey.d.ts +4 -0
- 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 +1 -1
|
@@ -13,12 +13,15 @@ class AssetInput {
|
|
|
13
13
|
constructor(input) {
|
|
14
14
|
this.input = input;
|
|
15
15
|
}
|
|
16
|
+
/** Gets the transaction input index for an asset input, e.g. 0 */
|
|
16
17
|
get vin() {
|
|
17
18
|
return this.input.vin;
|
|
18
19
|
}
|
|
20
|
+
/** Gets the amount for an input (in most cases, 330 sats) */
|
|
19
21
|
get amount() {
|
|
20
22
|
return this.input.amount;
|
|
21
23
|
}
|
|
24
|
+
/** Create a local asset input that points at a transaction input index. */
|
|
22
25
|
static create(vin, amount) {
|
|
23
26
|
const input = new AssetInput({
|
|
24
27
|
type: types_1.AssetInputType.Local,
|
|
@@ -28,6 +31,7 @@ class AssetInput {
|
|
|
28
31
|
input.validate();
|
|
29
32
|
return input;
|
|
30
33
|
}
|
|
34
|
+
/** Create an intent-backed asset input referencing an external intent transaction. */
|
|
31
35
|
static createIntent(txid, vin, amount) {
|
|
32
36
|
if (!txid || txid.length === 0) {
|
|
33
37
|
throw new Error("missing input intent txid");
|
|
@@ -51,6 +55,7 @@ class AssetInput {
|
|
|
51
55
|
input.validate();
|
|
52
56
|
return input;
|
|
53
57
|
}
|
|
58
|
+
/** Decode an asset input from its hex string form. */
|
|
54
59
|
static fromString(s) {
|
|
55
60
|
let buf;
|
|
56
61
|
try {
|
|
@@ -61,18 +66,22 @@ class AssetInput {
|
|
|
61
66
|
}
|
|
62
67
|
return AssetInput.fromBytes(buf);
|
|
63
68
|
}
|
|
69
|
+
/** Decode an asset input from its serialized bytes. */
|
|
64
70
|
static fromBytes(buf) {
|
|
65
71
|
const reader = new utils_1.BufferReader(buf);
|
|
66
72
|
return AssetInput.fromReader(reader);
|
|
67
73
|
}
|
|
74
|
+
/** Serialize the asset input to raw bytes. */
|
|
68
75
|
serialize() {
|
|
69
76
|
const writer = new utils_1.BufferWriter();
|
|
70
77
|
this.serializeTo(writer);
|
|
71
78
|
return writer.toBytes();
|
|
72
79
|
}
|
|
80
|
+
/** Encode the asset input to a hex string. */
|
|
73
81
|
toString() {
|
|
74
82
|
return base_1.hex.encode(this.serialize());
|
|
75
83
|
}
|
|
84
|
+
/** Validate the asset input fields. */
|
|
76
85
|
validate() {
|
|
77
86
|
switch (this.input.type) {
|
|
78
87
|
case types_1.AssetInputType.Local:
|
|
@@ -84,6 +93,7 @@ class AssetInput {
|
|
|
84
93
|
break;
|
|
85
94
|
}
|
|
86
95
|
}
|
|
96
|
+
/** Decode an asset input from a buffer reader. */
|
|
87
97
|
static fromReader(reader) {
|
|
88
98
|
const type = reader.readByte();
|
|
89
99
|
let input;
|
|
@@ -121,6 +131,7 @@ class AssetInput {
|
|
|
121
131
|
input.validate();
|
|
122
132
|
return input;
|
|
123
133
|
}
|
|
134
|
+
/** Serialize the asset input into an existing buffer writer. */
|
|
124
135
|
serializeTo(writer) {
|
|
125
136
|
writer.writeByte(this.input.type);
|
|
126
137
|
if (this.input.type === types_1.AssetInputType.Intent) {
|
|
@@ -138,11 +149,13 @@ class AssetInputs {
|
|
|
138
149
|
constructor(inputs) {
|
|
139
150
|
this.inputs = inputs;
|
|
140
151
|
}
|
|
152
|
+
/** Create a validated list of asset inputs. */
|
|
141
153
|
static create(inputs) {
|
|
142
154
|
const list = new AssetInputs(inputs);
|
|
143
155
|
list.validate();
|
|
144
156
|
return list;
|
|
145
157
|
}
|
|
158
|
+
/** Decode an asset input list from its hex string form. */
|
|
146
159
|
static fromString(s) {
|
|
147
160
|
if (!s || s.length === 0) {
|
|
148
161
|
throw new Error("missing asset inputs");
|
|
@@ -157,14 +170,17 @@ class AssetInputs {
|
|
|
157
170
|
const reader = new utils_1.BufferReader(buf);
|
|
158
171
|
return AssetInputs.fromReader(reader);
|
|
159
172
|
}
|
|
173
|
+
/** Serialize the asset input list to raw bytes. */
|
|
160
174
|
serialize() {
|
|
161
175
|
const writer = new utils_1.BufferWriter();
|
|
162
176
|
this.serializeTo(writer);
|
|
163
177
|
return writer.toBytes();
|
|
164
178
|
}
|
|
179
|
+
/** Encode the asset input list to a hex string. */
|
|
165
180
|
toString() {
|
|
166
181
|
return base_1.hex.encode(this.serialize());
|
|
167
182
|
}
|
|
183
|
+
/** Validate the asset input list. */
|
|
168
184
|
validate() {
|
|
169
185
|
const seen = new Set();
|
|
170
186
|
let listType = types_1.AssetInputType.Unspecified;
|
|
@@ -186,6 +202,7 @@ class AssetInputs {
|
|
|
186
202
|
}
|
|
187
203
|
}
|
|
188
204
|
}
|
|
205
|
+
/** Decode an asset input list from a buffer reader. */
|
|
189
206
|
static fromReader(reader) {
|
|
190
207
|
const count = Number(reader.readVarUint());
|
|
191
208
|
const inputs = [];
|
|
@@ -194,6 +211,7 @@ class AssetInputs {
|
|
|
194
211
|
}
|
|
195
212
|
return AssetInputs.create(inputs);
|
|
196
213
|
}
|
|
214
|
+
/** Serialize the asset input list into an existing buffer writer. */
|
|
197
215
|
serializeTo(writer) {
|
|
198
216
|
writer.writeVarUint(this.inputs.length);
|
|
199
217
|
for (const input of this.inputs) {
|
|
@@ -15,11 +15,13 @@ class AssetOutput {
|
|
|
15
15
|
this.vout = vout;
|
|
16
16
|
this.amount = amount;
|
|
17
17
|
}
|
|
18
|
+
/** Create a local asset output referencing a transaction output index. */
|
|
18
19
|
static create(vout, amount) {
|
|
19
20
|
const output = new AssetOutput(vout, typeof amount === "number" ? BigInt(amount) : amount);
|
|
20
21
|
output.validate();
|
|
21
22
|
return output;
|
|
22
23
|
}
|
|
24
|
+
/** Decode an asset output from its hex string form. */
|
|
23
25
|
static fromString(s) {
|
|
24
26
|
let buf;
|
|
25
27
|
try {
|
|
@@ -30,6 +32,7 @@ class AssetOutput {
|
|
|
30
32
|
}
|
|
31
33
|
return AssetOutput.fromBytes(buf);
|
|
32
34
|
}
|
|
35
|
+
/** Decode an asset output from its serialized bytes. */
|
|
33
36
|
static fromBytes(buf) {
|
|
34
37
|
if (!buf || buf.length === 0) {
|
|
35
38
|
throw new Error("missing asset output");
|
|
@@ -39,14 +42,17 @@ class AssetOutput {
|
|
|
39
42
|
output.validate();
|
|
40
43
|
return output;
|
|
41
44
|
}
|
|
45
|
+
/** Serialize the asset output to raw bytes. */
|
|
42
46
|
serialize() {
|
|
43
47
|
const writer = new utils_1.BufferWriter();
|
|
44
48
|
this.serializeTo(writer);
|
|
45
49
|
return writer.toBytes();
|
|
46
50
|
}
|
|
51
|
+
/** Encode the asset output to a hex string. */
|
|
47
52
|
toString() {
|
|
48
53
|
return base_1.hex.encode(this.serialize());
|
|
49
54
|
}
|
|
55
|
+
/** Validate the asset output fields. */
|
|
50
56
|
validate() {
|
|
51
57
|
if (!Number.isInteger(this.vout) ||
|
|
52
58
|
this.vout < 0 ||
|
|
@@ -57,6 +63,7 @@ class AssetOutput {
|
|
|
57
63
|
throw new Error("asset output amount must be greater than 0");
|
|
58
64
|
}
|
|
59
65
|
}
|
|
66
|
+
/** Decode an asset output from a buffer reader. */
|
|
60
67
|
static fromReader(reader) {
|
|
61
68
|
if (reader.remaining() < 2) {
|
|
62
69
|
throw new Error("invalid asset output vout length");
|
|
@@ -78,6 +85,7 @@ class AssetOutput {
|
|
|
78
85
|
const amount = reader.readVarUint();
|
|
79
86
|
return new AssetOutput(vout, amount);
|
|
80
87
|
}
|
|
88
|
+
/** Serialize the asset output into an existing buffer writer. */
|
|
81
89
|
serializeTo(writer) {
|
|
82
90
|
writer.writeByte(0x01);
|
|
83
91
|
writer.writeUint16LE(this.vout);
|
|
@@ -98,11 +106,13 @@ class AssetOutputs {
|
|
|
98
106
|
constructor(outputs) {
|
|
99
107
|
this.outputs = outputs;
|
|
100
108
|
}
|
|
109
|
+
/** Create a validated list of asset outputs. */
|
|
101
110
|
static create(outputs) {
|
|
102
111
|
const list = new AssetOutputs(outputs);
|
|
103
112
|
list.validate();
|
|
104
113
|
return list;
|
|
105
114
|
}
|
|
115
|
+
/** Decode an asset output list from its hex string form. */
|
|
106
116
|
static fromString(s) {
|
|
107
117
|
if (!s || s.length === 0) {
|
|
108
118
|
throw new Error("missing asset outputs");
|
|
@@ -117,14 +127,17 @@ class AssetOutputs {
|
|
|
117
127
|
const reader = new utils_1.BufferReader(buf);
|
|
118
128
|
return AssetOutputs.fromReader(reader);
|
|
119
129
|
}
|
|
130
|
+
/** Serialize the asset output list to raw bytes. */
|
|
120
131
|
serialize() {
|
|
121
132
|
const writer = new utils_1.BufferWriter();
|
|
122
133
|
this.serializeTo(writer);
|
|
123
134
|
return writer.toBytes();
|
|
124
135
|
}
|
|
136
|
+
/** Encode the asset output list to a hex string. */
|
|
125
137
|
toString() {
|
|
126
138
|
return base_1.hex.encode(this.serialize());
|
|
127
139
|
}
|
|
140
|
+
/** Validate the asset output list. */
|
|
128
141
|
validate() {
|
|
129
142
|
const seen = new Set();
|
|
130
143
|
for (const output of this.outputs) {
|
|
@@ -135,6 +148,7 @@ class AssetOutputs {
|
|
|
135
148
|
seen.add(output.vout);
|
|
136
149
|
}
|
|
137
150
|
}
|
|
151
|
+
/** Decode an asset output list from a buffer reader. */
|
|
138
152
|
static fromReader(reader) {
|
|
139
153
|
const count = Number(reader.readVarUint());
|
|
140
154
|
if (count === 0) {
|
|
@@ -148,6 +162,7 @@ class AssetOutputs {
|
|
|
148
162
|
result.validate();
|
|
149
163
|
return result;
|
|
150
164
|
}
|
|
165
|
+
/** Serialize the asset output list into an existing buffer writer. */
|
|
151
166
|
serializeTo(writer) {
|
|
152
167
|
this.validate();
|
|
153
168
|
writer.writeVarUint(this.outputs.length);
|
|
@@ -5,19 +5,53 @@ const base_1 = require("@scure/base");
|
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
const assetId_1 = require("./assetId");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* Reference to either an explicit asset id or another asset group in the same packet.
|
|
10
|
+
*
|
|
11
|
+
* @see AssetId
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const refById = AssetRef.fromId(assetId)
|
|
16
|
+
* const refByGroup = AssetRef.fromGroupIndex(0)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
8
19
|
class AssetRef {
|
|
9
20
|
constructor(ref) {
|
|
10
21
|
this.ref = ref;
|
|
11
22
|
}
|
|
23
|
+
/** Reference type discriminator. */
|
|
12
24
|
get type() {
|
|
13
25
|
return this.ref.type;
|
|
14
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Create an asset reference that points to a specific asset id.
|
|
29
|
+
*
|
|
30
|
+
* @param assetId - Asset id referenced by this pointer
|
|
31
|
+
* @returns Asset reference by id
|
|
32
|
+
* @see fromGroupIndex
|
|
33
|
+
*/
|
|
15
34
|
static fromId(assetId) {
|
|
16
35
|
return new AssetRef({ type: types_1.AssetRefType.ByID, assetId });
|
|
17
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Create an asset reference that points to another asset group by index.
|
|
39
|
+
*
|
|
40
|
+
* @param groupIndex - Zero-based asset group index in the packet
|
|
41
|
+
* @returns Asset reference by group index
|
|
42
|
+
* @see fromId
|
|
43
|
+
*/
|
|
18
44
|
static fromGroupIndex(groupIndex) {
|
|
19
45
|
return new AssetRef({ type: types_1.AssetRefType.ByGroup, groupIndex });
|
|
20
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode an asset reference from its hex string form.
|
|
49
|
+
*
|
|
50
|
+
* @param s - Hex-encoded asset reference
|
|
51
|
+
* @returns Decoded asset reference
|
|
52
|
+
* @throws Error if the string is not valid hex or does not encode a valid asset reference
|
|
53
|
+
* @see toString
|
|
54
|
+
*/
|
|
21
55
|
static fromString(s) {
|
|
22
56
|
let buf;
|
|
23
57
|
try {
|
|
@@ -28,6 +62,13 @@ class AssetRef {
|
|
|
28
62
|
}
|
|
29
63
|
return AssetRef.fromBytes(buf);
|
|
30
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Decode an asset reference from its serialized bytes.
|
|
67
|
+
*
|
|
68
|
+
* @param buf - Serialized asset reference bytes
|
|
69
|
+
* @returns Decoded asset reference
|
|
70
|
+
* @throws Error if the buffer is empty or malformed
|
|
71
|
+
*/
|
|
31
72
|
static fromBytes(buf) {
|
|
32
73
|
if (!buf || buf.length === 0) {
|
|
33
74
|
throw new Error("missing asset ref");
|
|
@@ -35,14 +76,33 @@ class AssetRef {
|
|
|
35
76
|
const reader = new utils_1.BufferReader(buf);
|
|
36
77
|
return AssetRef.fromReader(reader);
|
|
37
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Serialize the asset reference to raw bytes.
|
|
81
|
+
*
|
|
82
|
+
* @returns Serialized asset reference bytes
|
|
83
|
+
* @see fromBytes
|
|
84
|
+
*/
|
|
38
85
|
serialize() {
|
|
39
86
|
const writer = new utils_1.BufferWriter();
|
|
40
87
|
this.serializeTo(writer);
|
|
41
88
|
return writer.toBytes();
|
|
42
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Encode the asset reference to a hex string.
|
|
92
|
+
*
|
|
93
|
+
* @returns Hex-encoded asset reference
|
|
94
|
+
* @see fromString
|
|
95
|
+
*/
|
|
43
96
|
toString() {
|
|
44
97
|
return base_1.hex.encode(this.serialize());
|
|
45
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Decode an asset reference from a binary reader.
|
|
101
|
+
*
|
|
102
|
+
* @param reader - Reader positioned at an asset reference
|
|
103
|
+
* @returns Decoded asset reference
|
|
104
|
+
* @throws Error if the type is unknown or the reader does not contain enough bytes
|
|
105
|
+
*/
|
|
46
106
|
static fromReader(reader) {
|
|
47
107
|
const type = reader.readByte();
|
|
48
108
|
let ref;
|
|
@@ -67,6 +127,12 @@ class AssetRef {
|
|
|
67
127
|
}
|
|
68
128
|
return ref;
|
|
69
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Serialize the asset reference into an existing binary writer.
|
|
132
|
+
*
|
|
133
|
+
* @param writer - Writer to append the asset reference to
|
|
134
|
+
* @see serialize
|
|
135
|
+
*/
|
|
70
136
|
serializeTo(writer) {
|
|
71
137
|
writer.writeByte(this.ref.type);
|
|
72
138
|
switch (this.ref.type) {
|
|
@@ -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,
|
|
@@ -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
|
*
|
|
@@ -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
|
|
@@ -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/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
|
*/
|