@arkade-os/sdk 0.1.0 → 0.1.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.
@@ -43,16 +43,25 @@ function addConditionWitness(inIndex, tx, witness) {
43
43
  });
44
44
  }
45
45
  function createVirtualTx(inputs, outputs) {
46
- let lockTime;
46
+ let lockTime = 0n;
47
47
  for (const input of inputs) {
48
48
  const tapscript = (0, tapscript_1.decodeTapscript)((0, base_1.scriptFromTapLeafScript)(input.tapLeafScript));
49
49
  if (tapscript_1.CLTVMultisigTapscript.is(tapscript)) {
50
- lockTime = Number(tapscript.params.absoluteTimelock);
50
+ if (lockTime !== 0n) {
51
+ // if a locktime is already set, check if the new locktime is in the same unit
52
+ if (isSeconds(lockTime) !==
53
+ isSeconds(tapscript.params.absoluteTimelock)) {
54
+ throw new Error("cannot mix seconds and blocks locktime");
55
+ }
56
+ }
57
+ if (tapscript.params.absoluteTimelock > lockTime) {
58
+ lockTime = tapscript.params.absoluteTimelock;
59
+ }
51
60
  }
52
61
  }
53
62
  const tx = new btc_signer_1.Transaction({
54
63
  allowUnknown: true,
55
- lockTime,
64
+ lockTime: Number(lockTime),
56
65
  });
57
66
  for (const [i, input] of inputs.entries()) {
58
67
  tx.addInput({
@@ -122,3 +131,7 @@ function encodeCompactSizeUint(value) {
122
131
  return buffer;
123
132
  }
124
133
  }
134
+ const nLocktimeMinSeconds = 500000000n;
135
+ function isSeconds(locktime) {
136
+ return locktime >= nLocktimeMinSeconds;
137
+ }
@@ -82,20 +82,17 @@ class ServiceWorkerWallet {
82
82
  registration = await navigator.serviceWorker.register(path);
83
83
  // Handle updates
84
84
  registration.addEventListener("updatefound", () => {
85
- console.info("@arklabs/wallet-sdk: Service worker auto-update...");
86
85
  const newWorker = registration.installing;
87
86
  if (!newWorker)
88
87
  return;
89
88
  newWorker.addEventListener("statechange", () => {
90
- if (newWorker.state === "installed" &&
89
+ if (newWorker.state === "activated" &&
91
90
  navigator.serviceWorker.controller) {
92
- console.info("@arklabs/wallet-sdk: Service worker updated, reloading...");
91
+ console.info("Service worker activated, reloading...");
93
92
  window.location.reload();
94
93
  }
95
94
  });
96
95
  });
97
- // Check for updates
98
- await registration.update();
99
96
  const sw = registration.active ||
100
97
  registration.waiting ||
101
98
  registration.installing;
@@ -17,10 +17,20 @@ class Worker {
17
17
  this.vtxoRepository = vtxoRepository;
18
18
  this.messageCallback = messageCallback;
19
19
  }
20
- async start() {
20
+ async start(withServiceWorkerUpdate = true) {
21
21
  self.addEventListener("message", async (event) => {
22
22
  await this.handleMessage(event);
23
23
  });
24
+ if (withServiceWorkerUpdate) {
25
+ // activate service worker immediately
26
+ self.addEventListener("install", () => {
27
+ self.skipWaiting();
28
+ });
29
+ // take control of clients immediately
30
+ self.addEventListener("activate", () => {
31
+ self.clients.claim();
32
+ });
33
+ }
24
34
  }
25
35
  async clear() {
26
36
  if (this.vtxoSubscription) {
@@ -369,7 +369,6 @@ class Wallet {
369
369
  amount: BigInt(input.value),
370
370
  },
371
371
  tapInternalKey: this.onchainP2TR.tapInternalKey,
372
- tapMerkleRoot: this.onchainP2TR.tapMerkleRoot,
373
372
  });
374
373
  }
375
374
  // Add payment output
@@ -37,16 +37,25 @@ export function addConditionWitness(inIndex, tx, witness) {
37
37
  });
38
38
  }
39
39
  export function createVirtualTx(inputs, outputs) {
40
- let lockTime;
40
+ let lockTime = 0n;
41
41
  for (const input of inputs) {
42
42
  const tapscript = decodeTapscript(scriptFromTapLeafScript(input.tapLeafScript));
43
43
  if (CLTVMultisigTapscript.is(tapscript)) {
44
- lockTime = Number(tapscript.params.absoluteTimelock);
44
+ if (lockTime !== 0n) {
45
+ // if a locktime is already set, check if the new locktime is in the same unit
46
+ if (isSeconds(lockTime) !==
47
+ isSeconds(tapscript.params.absoluteTimelock)) {
48
+ throw new Error("cannot mix seconds and blocks locktime");
49
+ }
50
+ }
51
+ if (tapscript.params.absoluteTimelock > lockTime) {
52
+ lockTime = tapscript.params.absoluteTimelock;
53
+ }
45
54
  }
46
55
  }
47
56
  const tx = new Transaction({
48
57
  allowUnknown: true,
49
- lockTime,
58
+ lockTime: Number(lockTime),
50
59
  });
51
60
  for (const [i, input] of inputs.entries()) {
52
61
  tx.addInput({
@@ -116,3 +125,7 @@ function encodeCompactSizeUint(value) {
116
125
  return buffer;
117
126
  }
118
127
  }
128
+ const nLocktimeMinSeconds = 500000000n;
129
+ function isSeconds(locktime) {
130
+ return locktime >= nLocktimeMinSeconds;
131
+ }
@@ -79,20 +79,17 @@ export class ServiceWorkerWallet {
79
79
  registration = await navigator.serviceWorker.register(path);
80
80
  // Handle updates
81
81
  registration.addEventListener("updatefound", () => {
82
- console.info("@arklabs/wallet-sdk: Service worker auto-update...");
83
82
  const newWorker = registration.installing;
84
83
  if (!newWorker)
85
84
  return;
86
85
  newWorker.addEventListener("statechange", () => {
87
- if (newWorker.state === "installed" &&
86
+ if (newWorker.state === "activated" &&
88
87
  navigator.serviceWorker.controller) {
89
- console.info("@arklabs/wallet-sdk: Service worker updated, reloading...");
88
+ console.info("Service worker activated, reloading...");
90
89
  window.location.reload();
91
90
  }
92
91
  });
93
92
  });
94
- // Check for updates
95
- await registration.update();
96
93
  const sw = registration.active ||
97
94
  registration.waiting ||
98
95
  registration.installing;
@@ -14,10 +14,20 @@ export class Worker {
14
14
  this.vtxoRepository = vtxoRepository;
15
15
  this.messageCallback = messageCallback;
16
16
  }
17
- async start() {
17
+ async start(withServiceWorkerUpdate = true) {
18
18
  self.addEventListener("message", async (event) => {
19
19
  await this.handleMessage(event);
20
20
  });
21
+ if (withServiceWorkerUpdate) {
22
+ // activate service worker immediately
23
+ self.addEventListener("install", () => {
24
+ self.skipWaiting();
25
+ });
26
+ // take control of clients immediately
27
+ self.addEventListener("activate", () => {
28
+ self.clients.claim();
29
+ });
30
+ }
21
31
  }
22
32
  async clear() {
23
33
  if (this.vtxoSubscription) {
@@ -366,7 +366,6 @@ export class Wallet {
366
366
  amount: BigInt(input.value),
367
367
  },
368
368
  tapInternalKey: this.onchainP2TR.tapInternalKey,
369
- tapMerkleRoot: this.onchainP2TR.tapMerkleRoot,
370
369
  });
371
370
  }
372
371
  // Add payment output
@@ -6,7 +6,7 @@ export declare class Worker {
6
6
  private arkProvider;
7
7
  private vtxoSubscription;
8
8
  constructor(vtxoRepository?: VtxoRepository, messageCallback?: (message: ExtendableMessageEvent) => void);
9
- start(): Promise<void>;
9
+ start(withServiceWorkerUpdate?: boolean): Promise<void>;
10
10
  clear(): Promise<void>;
11
11
  private onWalletInitialized;
12
12
  private processVtxoSubscription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -23,11 +23,11 @@
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
25
  "dependencies": {
26
- "@noble/curves": "1.7.0",
27
- "@noble/hashes": "1.6.1",
26
+ "@noble/curves": "1.9.1",
27
+ "@noble/hashes": "1.8.0",
28
28
  "@noble/secp256k1": "2.2.3",
29
- "@scure/base": "1.2.1",
30
- "@scure/btc-signer": "1.7.0",
29
+ "@scure/base": "1.2.6",
30
+ "@scure/btc-signer": "1.8.1",
31
31
  "bip68": "1.0.4"
32
32
  },
33
33
  "devDependencies": {
@@ -36,7 +36,7 @@
36
36
  "@types/node": "22.10.2",
37
37
  "@typescript-eslint/eslint-plugin": "8.18.2",
38
38
  "@typescript-eslint/parser": "8.18.2",
39
- "@vitest/coverage-v8": "2.1.8",
39
+ "@vitest/coverage-v8": "2.1.9",
40
40
  "esbuild": "^0.20.1",
41
41
  "eslint": "^9.17.0",
42
42
  "glob": "11.0.1",
@@ -44,7 +44,7 @@
44
44
  "lint-staged": "15.3.0",
45
45
  "prettier": "3.4.2",
46
46
  "typescript": "5.7.2",
47
- "vitest": "2.1.8"
47
+ "vitest": "2.1.9"
48
48
  },
49
49
  "keywords": [
50
50
  "bitcoin",