@tari-project/ootle-wallet-daemon-signer 0.2.0 → 0.3.0

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -38
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -2,10 +2,13 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import { SignerError as e, assertByteLength as t, fromHexStr as n, toHexStr as r } from "@tari-project/ootle";
5
- BigInt.prototype.toJSON = function() {
6
- return this > BigInt(2 ** 53 - 1) ? this.toString() : Number(this);
7
- };
8
- var i = class e2 {
5
+ function i(e4) {
6
+ return JSON.stringify(e4, a);
7
+ }
8
+ function a(e4, t2) {
9
+ return typeof t2 == "bigint" ? t2.toString() : t2;
10
+ }
11
+ var o = class e2 {
9
12
  constructor(e4, t2) {
10
13
  __publicField(this, "url");
11
14
  __publicField(this, "credentials");
@@ -17,26 +20,26 @@ var i = class e2 {
17
20
  async sendRequest(e4, t2) {
18
21
  let n2 = { "Content-Type": "application/json" };
19
22
  (t2 == null ? void 0 : t2.token) && (n2.Authorization = `Bearer ${t2.token}`);
20
- let r2 = new AbortController(), i3 = r2.signal, a2 = (t2 == null ? void 0 : t2.timeout_millis) ? setTimeout(() => {
23
+ let r2 = new AbortController(), a2 = r2.signal, o2 = (t2 == null ? void 0 : t2.timeout_millis) ? setTimeout(() => {
21
24
  r2.abort("Timeout");
22
- }, t2.timeout_millis) : null, o2 = await fetch(this.url, {
25
+ }, t2.timeout_millis) : null, s2 = await fetch(this.url, {
23
26
  method: "POST",
24
- body: JSON.stringify(e4),
27
+ body: i(e4),
25
28
  headers: n2,
26
29
  credentials: this.credentials,
27
- signal: i3
30
+ signal: a2
28
31
  });
29
- if (a2 && clearTimeout(a2), !o2.ok) {
30
- let e5 = await o2.text();
31
- throw Error(`HTTP error ${o2.status}: ${e5}`);
32
+ if (o2 && clearTimeout(o2), !s2.ok) {
33
+ let e5 = await s2.text();
34
+ throw Error(`HTTP error ${s2.status}: ${e5}`);
32
35
  }
33
- return await o2.json();
36
+ return await s2.json();
34
37
  }
35
- }, a = "tw_";
36
- function o(e4) {
37
- return e4.startsWith(a);
38
+ }, s = "tw_";
39
+ function c(e4) {
40
+ return e4.startsWith(s);
38
41
  }
39
- var s = class e3 {
42
+ var l = class e3 {
40
43
  constructor(e4) {
41
44
  __publicField(this, "token");
42
45
  __publicField(this, "transport");
@@ -49,7 +52,7 @@ var s = class e3 {
49
52
  return new e3(t2);
50
53
  }
51
54
  static usingFetchTransport(t2, n2) {
52
- return e3.new(i.new(t2, n2));
55
+ return e3.new(o.new(t2, n2));
53
56
  }
54
57
  setReauthenticationEnabled(e4) {
55
58
  this.reauthEnabled = e4, this.warnIfApiKeyReauth();
@@ -64,7 +67,7 @@ var s = class e3 {
64
67
  this.token = null, this.hasWarnedApiKeyReauth = false;
65
68
  }
66
69
  warnIfApiKeyReauth() {
67
- this.hasWarnedApiKeyReauth || !this.reauthEnabled || !this.token || !o(this.token) || (this.hasWarnedApiKeyReauth = true, console.warn("WalletDaemonClient: reauthentication is enabled but the credential is an API key. API keys cannot be refreshed; a 401 means the key is revoked, expired, or lacks the required permission."));
70
+ this.hasWarnedApiKeyReauth || !this.reauthEnabled || !this.token || !c(this.token) || (this.hasWarnedApiKeyReauth = true, console.warn("WalletDaemonClient: reauthentication is enabled but the credential is an API key. API keys cannot be refreshed; a 401 means the key is revoked, expired, or lacks the required permission."));
68
71
  }
69
72
  getToken() {
70
73
  return this.token;
@@ -312,7 +315,7 @@ var s = class e3 {
312
315
  ...r2.error
313
316
  } });
314
317
  if (e4.startsWith("auth.")) throw console.warn("Token refresh failed"), this.clearToken(), n3;
315
- if (this.token && o(this.token)) throw n3;
318
+ if (this.token && c(this.token)) throw n3;
316
319
  let i3 = this.id++, a2 = await this.transport.sendRequest({
317
320
  method: "auth.refresh",
318
321
  jsonrpc: "2.0",
@@ -336,35 +339,35 @@ var s = class e3 {
336
339
  } });
337
340
  return r2.result;
338
341
  }
339
- }, c = "tari-wallet-sdk", l = ["Admin"];
340
- function u(e4) {
342
+ }, u = "tari-wallet-sdk", d = ["Admin"];
343
+ function f(e4) {
341
344
  let t2 = e4.replace(/-/g, "+").replace(/_/g, "/"), n2 = t2.padEnd(Math.ceil(t2.length / 4) * 4, "=");
342
345
  return Uint8Array.from(atob(n2), (e5) => e5.charCodeAt(0));
343
346
  }
344
- async function d(t2, n2) {
345
- let r2 = (n2 == null ? void 0 : n2.permissions) ?? l, i3 = (n2 == null ? void 0 : n2.appName) ?? c, { method: a2 } = await t2.authGetMethod();
347
+ async function p(t2, n2) {
348
+ let r2 = (n2 == null ? void 0 : n2.permissions) ?? d, i3 = (n2 == null ? void 0 : n2.appName) ?? u, { method: a2 } = await t2.authGetMethod();
346
349
  switch (a2) {
347
350
  case "none":
348
351
  return t2.authRequest(r2, "None");
349
352
  case "webauthn":
350
- return f(t2, i3, r2);
353
+ return m(t2, i3, r2);
351
354
  default:
352
355
  throw new e(`Unsupported wallet daemon auth method: ${a2}. Configure the daemon for one of: "none" or "webauthn", and pass that value to WalletDaemonSigner.connect.`);
353
356
  }
354
357
  }
355
- async function f(t2, n2, r2) {
358
+ async function m(t2, n2, r2) {
356
359
  if (globalThis.navigator === void 0 || !globalThis.navigator.credentials) throw new e("WebAuthn is browser-only. Run in a browser, or pass `authToken` explicitly to `WalletDaemonSigner.connect({ url, authToken })` from Node.");
357
360
  let { registered: i3 } = await t2.webauthnAlreadyRegistered({ username: n2 });
358
- return i3 ? p(t2, n2, r2) : m(t2, n2, r2);
361
+ return i3 ? h(t2, n2, r2) : g(t2, n2, r2);
359
362
  }
360
- async function p(t2, n2, r2) {
363
+ async function h(t2, n2, r2) {
361
364
  var _a;
362
365
  let i3 = await t2.webauthnAuthStart({ username: n2 });
363
366
  if (!i3.challenge) throw new e("WebAuthn auth start: missing challenge");
364
367
  let a2 = i3.challenge;
365
368
  if (!((_a = a2.publicKey) == null ? void 0 : _a.challenge)) throw new e("WebAuthn auth start: malformed challenge response");
366
- let { publicKey: o2 } = a2, s2 = u(o2.challenge), c2 = (o2.allowCredentials ?? []).map((e4) => ({
367
- id: u(e4.id),
369
+ let { publicKey: o2 } = a2, s2 = f(o2.challenge), c2 = (o2.allowCredentials ?? []).map((e4) => ({
370
+ id: f(e4.id),
368
371
  type: e4.type
369
372
  })), l2 = await navigator.credentials.get({ publicKey: {
370
373
  challenge: s2,
@@ -378,13 +381,13 @@ async function p(t2, n2, r2) {
378
381
  credential: l2
379
382
  } });
380
383
  }
381
- async function m(t2, n2, r2) {
384
+ async function g(t2, n2, r2) {
382
385
  var _a, _b, _c;
383
386
  let i3 = await t2.webauthnStartRegistration({ username: n2 });
384
387
  if (!i3.public_key) throw new e("WebAuthn registration start: missing public_key");
385
388
  let a2 = i3.public_key;
386
389
  if (!a2.challenge) throw new e("WebAuthn registration start: malformed public_key response");
387
- let o2 = u(a2.challenge), s2 = await navigator.credentials.create({ publicKey: {
390
+ let o2 = f(a2.challenge), s2 = await navigator.credentials.create({ publicKey: {
388
391
  rp: {
389
392
  name: ((_a = a2.rp) == null ? void 0 : _a.name) ?? "Tari Wallet",
390
393
  id: ((_b = a2.rp) == null ? void 0 : _b.id) ?? ((_c = globalThis.location) == null ? void 0 : _c.hostname)
@@ -422,7 +425,7 @@ async function m(t2, n2, r2) {
422
425
  });
423
426
  return c2;
424
427
  }
425
- var h = class i2 {
428
+ var _ = class i2 {
426
429
  constructor(e4) {
427
430
  __publicField(this, "client");
428
431
  __publicField(this, "_publicKey", null);
@@ -430,14 +433,14 @@ var h = class i2 {
430
433
  this.client = e4;
431
434
  }
432
435
  static new(e4) {
433
- let t2 = s.usingFetchTransport(e4.url);
436
+ let t2 = l.usingFetchTransport(e4.url);
434
437
  return t2.setToken(e4.authToken), new i2(t2);
435
438
  }
436
439
  static async connect(e4) {
437
- let t2 = s.usingFetchTransport(e4.url);
440
+ let t2 = l.usingFetchTransport(e4.url);
438
441
  if (e4.authToken) t2.setToken(e4.authToken);
439
442
  else {
440
- let n3 = await d(t2, e4);
443
+ let n3 = await p(t2, e4);
441
444
  t2.setToken(n3);
442
445
  }
443
446
  t2.setReauthenticationEnabled(true);
@@ -478,7 +481,7 @@ var h = class i2 {
478
481
  }
479
482
  };
480
483
  export {
481
- s as WalletDaemonClient,
482
- h as WalletDaemonSigner,
483
- d as authenticate
484
+ l as WalletDaemonClient,
485
+ _ as WalletDaemonSigner,
486
+ p as authenticate
484
487
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/ootle-wallet-daemon-signer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tari-project/ootle.ts.git",
@@ -25,9 +25,9 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@tari-project/ootle-ts-bindings": "^1.47.1",
29
- "@tari-project/wallet_jrpc_client": "^1.20.0",
30
- "@tari-project/ootle": "0.2.0"
28
+ "@tari-project/ootle-ts-bindings": "^1.49.1",
29
+ "@tari-project/wallet_jrpc_client": "^1.22.0",
30
+ "@tari-project/ootle": "0.3.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@microsoft/api-extractor": "^7.57.7",