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