@arkade-os/sdk 0.2.3 → 0.3.0-alpha.1
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 +114 -43
- package/dist/cjs/adapters/asyncStorage.js +5 -0
- package/dist/cjs/adapters/fileSystem.js +5 -0
- package/dist/cjs/adapters/indexedDB.js +5 -0
- package/dist/cjs/adapters/localStorage.js +5 -0
- package/dist/cjs/arknote/index.js +4 -4
- package/dist/cjs/bip322/index.js +11 -9
- package/dist/cjs/forfeit.js +2 -2
- package/dist/cjs/identity/index.js +15 -0
- package/dist/cjs/identity/singleKey.js +24 -5
- package/dist/cjs/index.js +7 -5
- package/dist/cjs/musig2/keys.js +7 -7
- package/dist/cjs/musig2/nonces.js +1 -1
- package/dist/cjs/musig2/sign.js +6 -6
- package/dist/cjs/networks.js +6 -6
- package/dist/cjs/repositories/contractRepository.js +130 -0
- package/dist/cjs/repositories/index.js +18 -0
- package/dist/cjs/repositories/walletRepository.js +136 -0
- package/dist/cjs/script/address.js +3 -3
- package/dist/cjs/script/base.js +7 -7
- package/dist/cjs/script/tapscript.js +21 -21
- package/dist/cjs/script/vhtlc.js +2 -2
- package/dist/cjs/storage/asyncStorage.js +47 -0
- package/dist/cjs/storage/fileSystem.js +138 -0
- package/dist/cjs/storage/inMemory.js +21 -0
- package/dist/cjs/storage/indexedDB.js +97 -0
- package/dist/cjs/storage/localStorage.js +48 -0
- package/dist/cjs/tree/signingSession.js +12 -11
- package/dist/cjs/tree/txTree.js +6 -6
- package/dist/cjs/tree/validation.js +5 -5
- package/dist/cjs/utils/arkTransaction.js +5 -5
- package/dist/cjs/utils/unknownFields.js +5 -5
- package/dist/cjs/wallet/onchain.js +16 -10
- package/dist/cjs/wallet/serviceWorker/request.js +4 -14
- package/dist/cjs/wallet/serviceWorker/response.js +0 -13
- package/dist/cjs/wallet/serviceWorker/wallet.js +124 -130
- package/dist/cjs/wallet/serviceWorker/worker.js +84 -53
- package/dist/cjs/wallet/unroll.js +6 -6
- package/dist/cjs/wallet/wallet.js +37 -20
- package/dist/esm/adapters/asyncStorage.js +1 -0
- package/dist/esm/adapters/fileSystem.js +1 -0
- package/dist/esm/adapters/indexedDB.js +1 -0
- package/dist/esm/adapters/localStorage.js +1 -0
- package/dist/esm/arknote/index.js +2 -2
- package/dist/esm/bip322/index.js +4 -2
- package/dist/esm/forfeit.js +1 -1
- package/dist/esm/identity/index.js +1 -1
- package/dist/esm/identity/singleKey.js +22 -3
- package/dist/esm/index.js +5 -4
- package/dist/esm/musig2/keys.js +7 -7
- package/dist/esm/musig2/nonces.js +1 -1
- package/dist/esm/musig2/sign.js +5 -5
- package/dist/esm/networks.js +1 -1
- package/dist/esm/repositories/contractRepository.js +126 -0
- package/dist/esm/repositories/index.js +2 -0
- package/dist/esm/repositories/walletRepository.js +132 -0
- package/dist/esm/script/address.js +1 -1
- package/dist/esm/script/base.js +3 -3
- package/dist/esm/script/tapscript.js +2 -2
- package/dist/esm/script/vhtlc.js +1 -1
- package/dist/esm/storage/asyncStorage.js +43 -0
- package/dist/esm/storage/fileSystem.js +101 -0
- package/dist/esm/storage/inMemory.js +17 -0
- package/dist/esm/storage/indexedDB.js +93 -0
- package/dist/esm/storage/localStorage.js +44 -0
- package/dist/esm/tree/signingSession.js +4 -3
- package/dist/esm/tree/txTree.js +2 -2
- package/dist/esm/tree/validation.js +2 -2
- package/dist/esm/utils/arkTransaction.js +2 -2
- package/dist/esm/utils/unknownFields.js +1 -1
- package/dist/esm/wallet/onchain.js +14 -8
- package/dist/esm/wallet/serviceWorker/request.js +4 -14
- package/dist/esm/wallet/serviceWorker/response.js +0 -13
- package/dist/esm/wallet/serviceWorker/wallet.js +125 -131
- package/dist/esm/wallet/serviceWorker/worker.js +85 -54
- package/dist/esm/wallet/unroll.js +2 -2
- package/dist/esm/wallet/wallet.js +25 -8
- package/dist/types/adapters/asyncStorage.d.ts +2 -0
- package/dist/types/adapters/fileSystem.d.ts +2 -0
- package/dist/types/adapters/indexedDB.d.ts +2 -0
- package/dist/types/adapters/localStorage.d.ts +2 -0
- package/dist/types/arknote/index.d.ts +1 -1
- package/dist/types/bip322/index.d.ts +2 -2
- package/dist/types/forfeit.d.ts +1 -1
- package/dist/types/identity/index.d.ts +4 -2
- package/dist/types/identity/singleKey.d.ts +13 -2
- package/dist/types/index.d.ts +5 -5
- package/dist/types/repositories/contractRepository.d.ts +20 -0
- package/dist/types/repositories/index.d.ts +2 -0
- package/dist/types/repositories/walletRepository.d.ts +38 -0
- package/dist/types/script/address.d.ts +1 -1
- package/dist/types/script/base.d.ts +1 -1
- package/dist/types/script/default.d.ts +1 -1
- package/dist/types/script/tapscript.d.ts +1 -1
- package/dist/types/script/vhtlc.d.ts +1 -1
- package/dist/types/storage/asyncStorage.d.ts +9 -0
- package/dist/types/storage/fileSystem.d.ts +11 -0
- package/dist/types/storage/inMemory.d.ts +8 -0
- package/dist/types/storage/index.d.ts +6 -0
- package/dist/types/storage/indexedDB.d.ts +12 -0
- package/dist/types/storage/localStorage.d.ts +8 -0
- package/dist/types/tree/txTree.d.ts +1 -1
- package/dist/types/tree/validation.d.ts +1 -1
- package/dist/types/utils/anchor.d.ts +1 -1
- package/dist/types/utils/arkTransaction.d.ts +3 -3
- package/dist/types/utils/unknownFields.d.ts +1 -1
- package/dist/types/wallet/index.d.ts +4 -1
- package/dist/types/wallet/onchain.d.ts +5 -4
- package/dist/types/wallet/serviceWorker/request.d.ts +1 -7
- package/dist/types/wallet/serviceWorker/response.d.ts +1 -8
- package/dist/types/wallet/serviceWorker/wallet.d.ts +67 -21
- package/dist/types/wallet/serviceWorker/worker.d.ts +16 -4
- package/dist/types/wallet/unroll.d.ts +1 -1
- package/dist/types/wallet/wallet.d.ts +5 -1
- package/package.json +39 -15
- package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +0 -185
- package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +0 -181
- package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +0 -20
- package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +0 -14
- /package/dist/cjs/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
- /package/dist/esm/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as bip68 from "bip68";
|
|
2
|
-
import { Script, ScriptNum } from "@scure/btc-signer/script";
|
|
3
|
-
import { p2tr_ms } from "@scure/btc-signer/payment";
|
|
2
|
+
import { Script, ScriptNum } from "@scure/btc-signer/script.js";
|
|
3
|
+
import { p2tr_ms } from "@scure/btc-signer/payment.js";
|
|
4
4
|
import { hex } from "@scure/base";
|
|
5
5
|
const MinimalScriptNum = ScriptNum(undefined, true);
|
|
6
6
|
export var TapscriptType;
|
package/dist/esm/script/vhtlc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Script } from "@scure/btc-signer";
|
|
1
|
+
import { Script } from "@scure/btc-signer/script.js";
|
|
2
2
|
import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, MultisigTapscript, } from './tapscript.js';
|
|
3
3
|
import { hex } from "@scure/base";
|
|
4
4
|
import { VtxoScript } from './base.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Note: This requires @react-native-async-storage/async-storage to be installed
|
|
2
|
+
export class AsyncStorageAdapter {
|
|
3
|
+
constructor() {
|
|
4
|
+
try {
|
|
5
|
+
// Dynamic import to avoid errors in non-React Native environments
|
|
6
|
+
this.AsyncStorage =
|
|
7
|
+
require("@react-native-async-storage/async-storage").default;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
throw new Error("AsyncStorage is not available. Make sure @react-native-async-storage/async-storage is installed in React Native environment.");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async getItem(key) {
|
|
14
|
+
return await this.AsyncStorage.getItem(key);
|
|
15
|
+
}
|
|
16
|
+
async setItem(key, value) {
|
|
17
|
+
try {
|
|
18
|
+
await this.AsyncStorage.setItem(key, value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(`Failed to set item for key ${key}:`, error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async removeItem(key) {
|
|
26
|
+
try {
|
|
27
|
+
await this.AsyncStorage.removeItem(key);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(`Failed to remove item for key ${key}:`, error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async clear() {
|
|
35
|
+
try {
|
|
36
|
+
await this.AsyncStorage.clear();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error("Failed to clear AsyncStorage:", error);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as fs from "fs/promises";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
export class FileSystemStorageAdapter {
|
|
4
|
+
constructor(dirPath) {
|
|
5
|
+
// Normalize and resolve the storage base path once
|
|
6
|
+
this.basePath = path.resolve(dirPath).replace(/[/\\]+$/, "");
|
|
7
|
+
}
|
|
8
|
+
validateAndGetFilePath(key) {
|
|
9
|
+
// Reject dangerous keys
|
|
10
|
+
if (key === "." || key === "..") {
|
|
11
|
+
throw new Error("Invalid key: '.' and '..' are not allowed");
|
|
12
|
+
}
|
|
13
|
+
// Check for null bytes
|
|
14
|
+
if (key.includes("\0")) {
|
|
15
|
+
throw new Error("Invalid key: null bytes are not allowed");
|
|
16
|
+
}
|
|
17
|
+
// Check for path traversal attempts before normalization
|
|
18
|
+
if (key.includes("..")) {
|
|
19
|
+
throw new Error("Invalid key: directory traversal is not allowed");
|
|
20
|
+
}
|
|
21
|
+
// Check for reserved Windows names (case-insensitive)
|
|
22
|
+
const reservedNames = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i;
|
|
23
|
+
const keyWithoutExt = key.split(".")[0];
|
|
24
|
+
if (reservedNames.test(keyWithoutExt)) {
|
|
25
|
+
throw new Error(`Invalid key: '${key}' uses a reserved Windows name`);
|
|
26
|
+
}
|
|
27
|
+
// Check for trailing spaces or dots
|
|
28
|
+
if (key.endsWith(" ") || key.endsWith(".")) {
|
|
29
|
+
throw new Error("Invalid key: trailing spaces or dots are not allowed");
|
|
30
|
+
}
|
|
31
|
+
// Normalize path separators and sanitize key
|
|
32
|
+
const normalizedKey = key
|
|
33
|
+
.replace(/[/\\]/g, "_")
|
|
34
|
+
.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
35
|
+
// Resolve the full path and check for directory traversal
|
|
36
|
+
const resolved = path.resolve(this.basePath, normalizedKey);
|
|
37
|
+
const relative = path.relative(this.basePath, resolved);
|
|
38
|
+
// Reject if trying to escape the base directory
|
|
39
|
+
if (relative.startsWith("..") || relative.includes(path.sep + "..")) {
|
|
40
|
+
throw new Error("Invalid key: directory traversal is not allowed");
|
|
41
|
+
}
|
|
42
|
+
return resolved;
|
|
43
|
+
}
|
|
44
|
+
async ensureDirectory() {
|
|
45
|
+
try {
|
|
46
|
+
await fs.access(this.basePath);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
await fs.mkdir(this.basePath, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async getItem(key) {
|
|
53
|
+
try {
|
|
54
|
+
const filePath = this.validateAndGetFilePath(key);
|
|
55
|
+
const data = await fs.readFile(filePath, "utf-8");
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.code === "ENOENT") {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
console.error(`Failed to read file for key ${key}:`, error);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async setItem(key, value) {
|
|
67
|
+
try {
|
|
68
|
+
await this.ensureDirectory();
|
|
69
|
+
const filePath = this.validateAndGetFilePath(key);
|
|
70
|
+
await fs.writeFile(filePath, value, "utf-8");
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error(`Failed to write file for key ${key}:`, error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async removeItem(key) {
|
|
78
|
+
try {
|
|
79
|
+
const filePath = this.validateAndGetFilePath(key);
|
|
80
|
+
await fs.unlink(filePath);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error.code !== "ENOENT") {
|
|
84
|
+
console.error(`Failed to remove file for key ${key}:`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async clear() {
|
|
89
|
+
try {
|
|
90
|
+
const entries = await fs.readdir(this.basePath);
|
|
91
|
+
await Promise.all(entries.map(async (entry) => {
|
|
92
|
+
const entryPath = path.join(this.basePath, entry);
|
|
93
|
+
// Use fs.rm with recursive option to handle both files and directories
|
|
94
|
+
await fs.rm(entryPath, { recursive: true, force: true });
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Failed to clear storage directory:", error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class InMemoryStorageAdapter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.store = new Map();
|
|
4
|
+
}
|
|
5
|
+
async getItem(key) {
|
|
6
|
+
return this.store.get(key) ?? null;
|
|
7
|
+
}
|
|
8
|
+
async setItem(key, value) {
|
|
9
|
+
this.store.set(key, value);
|
|
10
|
+
}
|
|
11
|
+
async removeItem(key) {
|
|
12
|
+
this.store.delete(key);
|
|
13
|
+
}
|
|
14
|
+
async clear() {
|
|
15
|
+
this.store.clear();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export class IndexedDBStorageAdapter {
|
|
2
|
+
constructor(dbName, version = 1) {
|
|
3
|
+
this.db = null;
|
|
4
|
+
this.dbName = dbName;
|
|
5
|
+
this.version = version;
|
|
6
|
+
}
|
|
7
|
+
async getDB() {
|
|
8
|
+
if (this.db)
|
|
9
|
+
return this.db;
|
|
10
|
+
const globalObject = typeof window === "undefined" ? self : window;
|
|
11
|
+
if (!(globalObject && "indexedDB" in globalObject)) {
|
|
12
|
+
throw new Error("IndexedDB is not available in this environment");
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const request = globalObject.indexedDB.open(this.dbName, this.version);
|
|
16
|
+
request.onerror = () => reject(request.error);
|
|
17
|
+
request.onsuccess = () => {
|
|
18
|
+
this.db = request.result;
|
|
19
|
+
resolve(this.db);
|
|
20
|
+
};
|
|
21
|
+
request.onupgradeneeded = () => {
|
|
22
|
+
const db = request.result;
|
|
23
|
+
if (!db.objectStoreNames.contains("storage")) {
|
|
24
|
+
db.createObjectStore("storage");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async getItem(key) {
|
|
30
|
+
try {
|
|
31
|
+
const db = await this.getDB();
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const transaction = db.transaction(["storage"], "readonly");
|
|
34
|
+
const store = transaction.objectStore("storage");
|
|
35
|
+
const request = store.get(key);
|
|
36
|
+
request.onerror = () => reject(request.error);
|
|
37
|
+
request.onsuccess = () => {
|
|
38
|
+
resolve(request.result || null);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`Failed to get item for key ${key}:`, error);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async setItem(key, value) {
|
|
48
|
+
try {
|
|
49
|
+
const db = await this.getDB();
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const transaction = db.transaction(["storage"], "readwrite");
|
|
52
|
+
const store = transaction.objectStore("storage");
|
|
53
|
+
const request = store.put(value, key);
|
|
54
|
+
request.onerror = () => reject(request.error);
|
|
55
|
+
request.onsuccess = () => resolve();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(`Failed to set item for key ${key}:`, error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async removeItem(key) {
|
|
64
|
+
try {
|
|
65
|
+
const db = await this.getDB();
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const transaction = db.transaction(["storage"], "readwrite");
|
|
68
|
+
const store = transaction.objectStore("storage");
|
|
69
|
+
const request = store.delete(key);
|
|
70
|
+
request.onerror = () => reject(request.error);
|
|
71
|
+
request.onsuccess = () => resolve();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error(`Failed to remove item for key ${key}:`, error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async clear() {
|
|
79
|
+
try {
|
|
80
|
+
const db = await this.getDB();
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const transaction = db.transaction(["storage"], "readwrite");
|
|
83
|
+
const store = transaction.objectStore("storage");
|
|
84
|
+
const request = store.clear();
|
|
85
|
+
request.onerror = () => reject(request.error);
|
|
86
|
+
request.onsuccess = () => resolve();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error("Failed to clear storage:", error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class LocalStorageAdapter {
|
|
2
|
+
getSafeLocalStorage() {
|
|
3
|
+
try {
|
|
4
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
// Test access to ensure localStorage is actually available
|
|
8
|
+
window.localStorage.length;
|
|
9
|
+
return window.localStorage;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// localStorage may throw in some environments (e.g., private browsing, disabled storage)
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async getItem(key) {
|
|
17
|
+
const localStorage = this.getSafeLocalStorage();
|
|
18
|
+
if (!localStorage) {
|
|
19
|
+
throw new Error("localStorage is not available in this environment");
|
|
20
|
+
}
|
|
21
|
+
return localStorage.getItem(key);
|
|
22
|
+
}
|
|
23
|
+
async setItem(key, value) {
|
|
24
|
+
const localStorage = this.getSafeLocalStorage();
|
|
25
|
+
if (!localStorage) {
|
|
26
|
+
throw new Error("localStorage is not available in this environment");
|
|
27
|
+
}
|
|
28
|
+
localStorage.setItem(key, value);
|
|
29
|
+
}
|
|
30
|
+
async removeItem(key) {
|
|
31
|
+
const localStorage = this.getSafeLocalStorage();
|
|
32
|
+
if (!localStorage) {
|
|
33
|
+
throw new Error("localStorage is not available in this environment");
|
|
34
|
+
}
|
|
35
|
+
localStorage.removeItem(key);
|
|
36
|
+
}
|
|
37
|
+
async clear() {
|
|
38
|
+
const localStorage = this.getSafeLocalStorage();
|
|
39
|
+
if (!localStorage) {
|
|
40
|
+
throw new Error("localStorage is not available in this environment");
|
|
41
|
+
}
|
|
42
|
+
localStorage.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as musig2 from '../musig2/index.js';
|
|
2
|
-
import { Script
|
|
2
|
+
import { Script } from "@scure/btc-signer/script.js";
|
|
3
|
+
import { SigHash } from "@scure/btc-signer/transaction.js";
|
|
3
4
|
import { hex } from "@scure/base";
|
|
4
|
-
import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
|
|
5
|
-
import { randomPrivateKeyBytes, sha256x2 } from "@scure/btc-signer/utils";
|
|
5
|
+
import { schnorr, secp256k1 } from "@noble/curves/secp256k1.js";
|
|
6
|
+
import { randomPrivateKeyBytes, sha256x2 } from "@scure/btc-signer/utils.js";
|
|
6
7
|
import { CosignerPublicKey, getArkPsbtFields } from '../utils/unknownFields.js';
|
|
7
8
|
export const ErrMissingVtxoGraph = new Error("missing vtxo graph");
|
|
8
9
|
export const ErrMissingAggregateKey = new Error("missing aggregate key");
|
package/dist/esm/tree/txTree.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Transaction } from "@scure/btc-signer";
|
|
1
|
+
import { Transaction } from "@scure/btc-signer/transaction.js";
|
|
2
2
|
import { base64 } from "@scure/base";
|
|
3
3
|
import { hex } from "@scure/base";
|
|
4
|
-
import { sha256x2 } from "@scure/btc-signer/utils";
|
|
4
|
+
import { sha256x2 } from "@scure/btc-signer/utils.js";
|
|
5
5
|
/**
|
|
6
6
|
* TxTree is a graph of bitcoin transactions.
|
|
7
7
|
* It is used to represent batch tree created during settlement session
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hex } from "@scure/base";
|
|
2
|
-
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { Transaction } from "@scure/btc-signer/transaction.js";
|
|
3
3
|
import { base64 } from "@scure/base";
|
|
4
|
-
import { sha256x2 } from "@scure/btc-signer/utils";
|
|
4
|
+
import { sha256x2 } from "@scure/btc-signer/utils.js";
|
|
5
5
|
import { aggregateKeys } from '../musig2/index.js';
|
|
6
6
|
import { CosignerPublicKey, getArkPsbtFields } from '../utils/unknownFields.js';
|
|
7
7
|
export const ErrInvalidSettlementTx = (tx) => new Error(`invalid settlement transaction: ${tx}`);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DEFAULT_SEQUENCE, Transaction } from "@scure/btc-signer";
|
|
1
|
+
import { DEFAULT_SEQUENCE, Transaction, } from "@scure/btc-signer/transaction.js";
|
|
2
2
|
import { CLTVMultisigTapscript, decodeTapscript } from '../script/tapscript.js';
|
|
3
3
|
import { scriptFromTapLeafScript, VtxoScript, } from '../script/base.js';
|
|
4
4
|
import { P2A } from './anchor.js';
|
|
5
5
|
import { hex } from "@scure/base";
|
|
6
|
-
import { sha256x2 } from "@scure/btc-signer/utils";
|
|
6
|
+
import { sha256x2 } from "@scure/btc-signer/utils.js";
|
|
7
7
|
import { setArkPsbtField, VtxoTaprootTree } from './unknownFields.js';
|
|
8
8
|
/**
|
|
9
9
|
* Builds an offchain transaction with checkpoint transactions.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { p2tr } from "@scure/btc-signer/payment";
|
|
1
|
+
import { p2tr } from "@scure/btc-signer/payment.js";
|
|
2
2
|
import { getNetwork } from '../networks.js';
|
|
3
3
|
import { ESPLORA_URL, EsploraProvider, } from '../providers/onchain.js';
|
|
4
|
-
import { Transaction } from "@scure/btc-signer";
|
|
4
|
+
import { Transaction } from "@scure/btc-signer/transaction.js";
|
|
5
5
|
import { findP2AOutput, P2A } from '../utils/anchor.js';
|
|
6
6
|
import { TxWeightEstimator } from '../utils/txSizeEstimator.js';
|
|
7
7
|
/**
|
|
@@ -13,7 +13,7 @@ import { TxWeightEstimator } from '../utils/txSizeEstimator.js';
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* const wallet =
|
|
16
|
+
* const wallet = await OnchainWallet.create(identity, 'mainnet');
|
|
17
17
|
* const balance = await wallet.getBalance();
|
|
18
18
|
* const txid = await wallet.send({
|
|
19
19
|
* address: 'bc1...',
|
|
@@ -22,15 +22,21 @@ import { TxWeightEstimator } from '../utils/txSizeEstimator.js';
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export class OnchainWallet {
|
|
25
|
-
constructor(identity, network, provider) {
|
|
25
|
+
constructor(identity, network, onchainP2TR, provider) {
|
|
26
26
|
this.identity = identity;
|
|
27
|
-
|
|
27
|
+
this.network = network;
|
|
28
|
+
this.onchainP2TR = onchainP2TR;
|
|
29
|
+
this.provider = provider;
|
|
30
|
+
}
|
|
31
|
+
static async create(identity, networkName, provider) {
|
|
32
|
+
const pubkey = await identity.xOnlyPublicKey();
|
|
28
33
|
if (!pubkey) {
|
|
29
34
|
throw new Error("Invalid configured public key");
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
const network = getNetwork(networkName);
|
|
37
|
+
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
38
|
+
const onchainP2TR = p2tr(pubkey, undefined, network);
|
|
39
|
+
return new OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
34
40
|
}
|
|
35
41
|
get address() {
|
|
36
42
|
return this.onchainP2TR.address || "";
|
|
@@ -9,13 +9,13 @@ export var Request;
|
|
|
9
9
|
Request.isBase = isBase;
|
|
10
10
|
function isInitWallet(message) {
|
|
11
11
|
return (message.type === "INIT_WALLET" &&
|
|
12
|
-
"privateKey" in message &&
|
|
13
|
-
typeof message.privateKey === "string" &&
|
|
14
12
|
"arkServerUrl" in message &&
|
|
15
13
|
typeof message.arkServerUrl === "string" &&
|
|
14
|
+
"privateKey" in message &&
|
|
15
|
+
typeof message.privateKey === "string" &&
|
|
16
16
|
("arkServerPublicKey" in message
|
|
17
|
-
?
|
|
18
|
-
message.arkServerPublicKey ===
|
|
17
|
+
? message.arkServerPublicKey === undefined ||
|
|
18
|
+
typeof message.arkServerPublicKey === "string"
|
|
19
19
|
: true));
|
|
20
20
|
}
|
|
21
21
|
Request.isInitWallet = isInitWallet;
|
|
@@ -66,14 +66,4 @@ export var Request;
|
|
|
66
66
|
return message.type === "GET_STATUS";
|
|
67
67
|
}
|
|
68
68
|
Request.isGetStatus = isGetStatus;
|
|
69
|
-
function isSign(message) {
|
|
70
|
-
return (message.type === "SIGN" &&
|
|
71
|
-
"tx" in message &&
|
|
72
|
-
typeof message.tx === "string" &&
|
|
73
|
-
("inputIndexes" in message && message.inputIndexes != undefined
|
|
74
|
-
? Array.isArray(message.inputIndexes) &&
|
|
75
|
-
message.inputIndexes.every((index) => typeof index === "number")
|
|
76
|
-
: true));
|
|
77
|
-
}
|
|
78
|
-
Request.isSign = isSign;
|
|
79
69
|
})(Request || (Request = {}));
|
|
@@ -172,17 +172,4 @@ export var Response;
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
Response.clearResponse = clearResponse;
|
|
175
|
-
function signSuccess(id, tx) {
|
|
176
|
-
return {
|
|
177
|
-
type: "SIGN_SUCCESS",
|
|
178
|
-
success: true,
|
|
179
|
-
tx,
|
|
180
|
-
id,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
Response.signSuccess = signSuccess;
|
|
184
|
-
function isSignSuccess(response) {
|
|
185
|
-
return response.type === "SIGN_SUCCESS" && response.success === true;
|
|
186
|
-
}
|
|
187
|
-
Response.isSignSuccess = isSignSuccess;
|
|
188
175
|
})(Response || (Response = {}));
|