@tari-project/ootle-wallet-daemon-signer 0.1.0 → 0.2.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.
- package/dist/index.d.ts +6 -5
- package/dist/index.js +113 -36
- package/package.json +12 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Permission } from '@tari-project/ootle-ts-bindings';
|
|
2
2
|
import { Signer } from '@tari-project/ootle';
|
|
3
3
|
import { TransactionSignature } from '@tari-project/ootle-ts-bindings';
|
|
4
4
|
import { UnsignedTransactionV1 } from '@tari-project/ootle-ts-bindings';
|
|
@@ -23,7 +23,7 @@ export declare function authenticate(client: WalletDaemonClient, options?: AuthO
|
|
|
23
23
|
|
|
24
24
|
export declare interface AuthOptions {
|
|
25
25
|
/** Permissions to request from the wallet daemon. Defaults to `["Admin"]`. */
|
|
26
|
-
permissions?:
|
|
26
|
+
permissions?: Permission[];
|
|
27
27
|
/** Application name used as the WebAuthn username/identifier. Defaults to `"tari-wallet-sdk"`. */
|
|
28
28
|
appName?: string;
|
|
29
29
|
}
|
|
@@ -76,9 +76,10 @@ export declare class WalletDaemonSigner implements Signer {
|
|
|
76
76
|
* engine rejects the envelope.
|
|
77
77
|
*
|
|
78
78
|
* TODO(daemon): the `transactions.sign` JRPC's acceptance of `seal_public_key` is unverified
|
|
79
|
-
* against a running `tari_ootle_walletd`, and
|
|
80
|
-
*
|
|
81
|
-
*
|
|
79
|
+
* against a running `tari_ootle_walletd`, and the daemon advertises no capability signal for
|
|
80
|
+
* it. (`walletGetInfo` returns a daemon `version` string, but nothing maps a version to
|
|
81
|
+
* "honours `seal_public_key`", so it cannot answer this question.) This call therefore cannot
|
|
82
|
+
* fail fast the way {@link getViewSecret} does. If the daemon ignores the
|
|
82
83
|
* parameter and hashes with its own pk, the per-signer signatures will not verify and the
|
|
83
84
|
* failure surfaces only LATE — at submit time — as the opaque engine error
|
|
84
85
|
* `"Transaction has one or more invalid signature(s)"`, not here. An unconditional throw is
|
package/dist/index.js
CHANGED
|
@@ -6,12 +6,13 @@ BigInt.prototype.toJSON = function() {
|
|
|
6
6
|
return this > BigInt(2 ** 53 - 1) ? this.toString() : Number(this);
|
|
7
7
|
};
|
|
8
8
|
var i = class e2 {
|
|
9
|
-
constructor(e4) {
|
|
9
|
+
constructor(e4, t2) {
|
|
10
10
|
__publicField(this, "url");
|
|
11
|
-
this
|
|
11
|
+
__publicField(this, "credentials");
|
|
12
|
+
this.url = e4, this.credentials = (t2 == null ? void 0 : t2.credentials) ?? "same-origin";
|
|
12
13
|
}
|
|
13
|
-
static new(t2) {
|
|
14
|
-
return new e2(t2);
|
|
14
|
+
static new(t2, n2) {
|
|
15
|
+
return new e2(t2, n2);
|
|
15
16
|
}
|
|
16
17
|
async sendRequest(e4, t2) {
|
|
17
18
|
let n2 = { "Content-Type": "application/json" };
|
|
@@ -22,6 +23,7 @@ var i = class e2 {
|
|
|
22
23
|
method: "POST",
|
|
23
24
|
body: JSON.stringify(e4),
|
|
24
25
|
headers: n2,
|
|
26
|
+
credentials: this.credentials,
|
|
25
27
|
signal: i3
|
|
26
28
|
});
|
|
27
29
|
if (a2 && clearTimeout(a2), !o2.ok) {
|
|
@@ -30,28 +32,39 @@ var i = class e2 {
|
|
|
30
32
|
}
|
|
31
33
|
return await o2.json();
|
|
32
34
|
}
|
|
33
|
-
}, a =
|
|
35
|
+
}, a = "tw_";
|
|
36
|
+
function o(e4) {
|
|
37
|
+
return e4.startsWith(a);
|
|
38
|
+
}
|
|
39
|
+
var s = class e3 {
|
|
34
40
|
constructor(e4) {
|
|
35
41
|
__publicField(this, "token");
|
|
36
42
|
__publicField(this, "transport");
|
|
37
43
|
__publicField(this, "id");
|
|
38
44
|
__publicField(this, "reauthEnabled", true);
|
|
45
|
+
__publicField(this, "hasWarnedApiKeyReauth", false);
|
|
39
46
|
this.token = null, this.transport = e4, this.id = 0;
|
|
40
47
|
}
|
|
41
48
|
static new(t2) {
|
|
42
49
|
return new e3(t2);
|
|
43
50
|
}
|
|
44
|
-
static usingFetchTransport(t2) {
|
|
45
|
-
return e3.new(i.new(t2));
|
|
51
|
+
static usingFetchTransport(t2, n2) {
|
|
52
|
+
return e3.new(i.new(t2, n2));
|
|
46
53
|
}
|
|
47
54
|
setReauthenticationEnabled(e4) {
|
|
48
|
-
this.reauthEnabled = e4;
|
|
55
|
+
this.reauthEnabled = e4, this.warnIfApiKeyReauth();
|
|
49
56
|
}
|
|
50
57
|
isAuthenticated() {
|
|
51
58
|
return !!this.token;
|
|
52
59
|
}
|
|
53
60
|
setToken(e4) {
|
|
54
|
-
this.token = e4;
|
|
61
|
+
this.token = e4, this.warnIfApiKeyReauth();
|
|
62
|
+
}
|
|
63
|
+
clearToken() {
|
|
64
|
+
this.token = null, this.hasWarnedApiKeyReauth = false;
|
|
65
|
+
}
|
|
66
|
+
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."));
|
|
55
68
|
}
|
|
56
69
|
getToken() {
|
|
57
70
|
return this.token;
|
|
@@ -78,6 +91,36 @@ var i = class e2 {
|
|
|
78
91
|
authRefresh() {
|
|
79
92
|
return this.sendRequest("auth.refresh");
|
|
80
93
|
}
|
|
94
|
+
transactionRequestsCreate(e4) {
|
|
95
|
+
return this.sendRequest("transaction_requests.create", e4);
|
|
96
|
+
}
|
|
97
|
+
transactionRequestsGet(e4) {
|
|
98
|
+
return this.sendRequest("transaction_requests.get", e4);
|
|
99
|
+
}
|
|
100
|
+
transactionRequestsList(e4 = { status: null }) {
|
|
101
|
+
return this.sendRequest("transaction_requests.list", e4);
|
|
102
|
+
}
|
|
103
|
+
transactionRequestsApprove(e4) {
|
|
104
|
+
return this.sendRequest("transaction_requests.approve", e4);
|
|
105
|
+
}
|
|
106
|
+
transactionRequestsReject(e4) {
|
|
107
|
+
return this.sendRequest("transaction_requests.reject", e4);
|
|
108
|
+
}
|
|
109
|
+
transactionRequestsSubmit(e4) {
|
|
110
|
+
return this.sendRequest("transaction_requests.submit", e4);
|
|
111
|
+
}
|
|
112
|
+
authCreateApiKey(e4) {
|
|
113
|
+
return this.sendRequest("auth.create_api_key", e4);
|
|
114
|
+
}
|
|
115
|
+
authListApiKeys(e4 = { include_revoked: false }) {
|
|
116
|
+
return this.sendRequest("auth.list_api_keys", e4);
|
|
117
|
+
}
|
|
118
|
+
authRevokeApiKey(e4) {
|
|
119
|
+
return this.sendRequest("auth.revoke_api_key", e4);
|
|
120
|
+
}
|
|
121
|
+
authenticateWithApiKey(e4) {
|
|
122
|
+
this.setToken(e4);
|
|
123
|
+
}
|
|
81
124
|
walletGetInfo() {
|
|
82
125
|
return this.sendRequest("wallet.get_info", {});
|
|
83
126
|
}
|
|
@@ -90,6 +133,9 @@ var i = class e2 {
|
|
|
90
133
|
burnProofsList(e4) {
|
|
91
134
|
return this.sendRequest("burn_proofs.list", e4);
|
|
92
135
|
}
|
|
136
|
+
burnProofsGet(e4) {
|
|
137
|
+
return this.sendRequest("burn_proofs.get", e4);
|
|
138
|
+
}
|
|
93
139
|
accountsClaimBurn(e4) {
|
|
94
140
|
return this.sendRequest("accounts.claim_burn", e4);
|
|
95
141
|
}
|
|
@@ -99,6 +145,9 @@ var i = class e2 {
|
|
|
99
145
|
accountsGetBalances(e4) {
|
|
100
146
|
return this.sendRequest("accounts.get_balances", e4);
|
|
101
147
|
}
|
|
148
|
+
accountsGetBalanceChanges(e4) {
|
|
149
|
+
return this.sendRequest("accounts.get_balance_changes", e4);
|
|
150
|
+
}
|
|
102
151
|
accountsList(e4) {
|
|
103
152
|
return this.sendRequest("accounts.list", e4);
|
|
104
153
|
}
|
|
@@ -126,6 +175,9 @@ var i = class e2 {
|
|
|
126
175
|
submitTransactionDryRun(e4) {
|
|
127
176
|
return this.sendRequest("transactions.submit_dry_run", e4);
|
|
128
177
|
}
|
|
178
|
+
transactionsDetectInputs(e4) {
|
|
179
|
+
return this.sendRequest("transactions.detect_inputs", e4);
|
|
180
|
+
}
|
|
129
181
|
submitTransactionManifest(e4) {
|
|
130
182
|
return this.sendRequest("transactions.submit_manifest", e4);
|
|
131
183
|
}
|
|
@@ -138,6 +190,12 @@ var i = class e2 {
|
|
|
138
190
|
substatesList(e4) {
|
|
139
191
|
return this.sendRequest("substates.list", e4);
|
|
140
192
|
}
|
|
193
|
+
swapPoolGetExchangeRate(e4) {
|
|
194
|
+
return this.sendRequest("swap_pools.get_exchange_rate", e4);
|
|
195
|
+
}
|
|
196
|
+
swapPoolsList(e4) {
|
|
197
|
+
return this.sendRequest("swap_pools.list", e4);
|
|
198
|
+
}
|
|
141
199
|
transactionsList(e4) {
|
|
142
200
|
return this.sendRequest("transactions.list", e4);
|
|
143
201
|
}
|
|
@@ -210,9 +268,27 @@ var i = class e2 {
|
|
|
210
268
|
stealthUtxosList(e4) {
|
|
211
269
|
return this.sendRequest("stealth_utxos.list", e4);
|
|
212
270
|
}
|
|
271
|
+
confidentialListOutputs(e4) {
|
|
272
|
+
return this.sendRequest("confidential.list_outputs", e4);
|
|
273
|
+
}
|
|
213
274
|
stealthUtxosDecryptValue(e4) {
|
|
214
275
|
return this.sendRequest("stealth_utxos.decrypt_value", e4);
|
|
215
276
|
}
|
|
277
|
+
addressBookAdd(e4) {
|
|
278
|
+
return this.sendRequest("address_book.add", e4);
|
|
279
|
+
}
|
|
280
|
+
addressBookList() {
|
|
281
|
+
return this.sendRequest("address_book.list", {});
|
|
282
|
+
}
|
|
283
|
+
addressBookGet(e4) {
|
|
284
|
+
return this.sendRequest("address_book.get", e4);
|
|
285
|
+
}
|
|
286
|
+
addressBookUpdate(e4) {
|
|
287
|
+
return this.sendRequest("address_book.update", e4);
|
|
288
|
+
}
|
|
289
|
+
addressBookDelete(e4) {
|
|
290
|
+
return this.sendRequest("address_book.delete", e4);
|
|
291
|
+
}
|
|
216
292
|
async sendRequest(e4, t2 = null) {
|
|
217
293
|
let n2 = this.id++, r2 = await this.transport.sendRequest({
|
|
218
294
|
method: e4,
|
|
@@ -235,14 +311,15 @@ var i = class e2 {
|
|
|
235
311
|
method: e4,
|
|
236
312
|
...r2.error
|
|
237
313
|
} });
|
|
238
|
-
if (e4.startsWith("auth.")) throw console.warn("Token refresh failed"), this.
|
|
314
|
+
if (e4.startsWith("auth.")) throw console.warn("Token refresh failed"), this.clearToken(), n3;
|
|
315
|
+
if (this.token && o(this.token)) throw n3;
|
|
239
316
|
let i3 = this.id++, a2 = await this.transport.sendRequest({
|
|
240
317
|
method: "auth.refresh",
|
|
241
318
|
jsonrpc: "2.0",
|
|
242
319
|
id: i3,
|
|
243
320
|
params: {}
|
|
244
321
|
});
|
|
245
|
-
if (a2.error) throw console.debug("Refresh resp", a2), this.
|
|
322
|
+
if (a2.error) throw console.debug("Refresh resp", a2), this.clearToken(), n3;
|
|
246
323
|
console.debug("Token refreshed successfully. Retrying original request."), this.token = a2.result.token, r2 = await this.transport.sendRequest({
|
|
247
324
|
method: e4,
|
|
248
325
|
jsonrpc: "2.0",
|
|
@@ -259,55 +336,55 @@ var i = class e2 {
|
|
|
259
336
|
} });
|
|
260
337
|
return r2.result;
|
|
261
338
|
}
|
|
262
|
-
},
|
|
263
|
-
function
|
|
339
|
+
}, c = "tari-wallet-sdk", l = ["Admin"];
|
|
340
|
+
function u(e4) {
|
|
264
341
|
let t2 = e4.replace(/-/g, "+").replace(/_/g, "/"), n2 = t2.padEnd(Math.ceil(t2.length / 4) * 4, "=");
|
|
265
342
|
return Uint8Array.from(atob(n2), (e5) => e5.charCodeAt(0));
|
|
266
343
|
}
|
|
267
|
-
async function
|
|
268
|
-
let r2 = (n2 == null ? void 0 : n2.permissions) ??
|
|
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();
|
|
269
346
|
switch (a2) {
|
|
270
347
|
case "none":
|
|
271
348
|
return t2.authRequest(r2, "None");
|
|
272
349
|
case "webauthn":
|
|
273
|
-
return
|
|
350
|
+
return f(t2, i3, r2);
|
|
274
351
|
default:
|
|
275
352
|
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.`);
|
|
276
353
|
}
|
|
277
354
|
}
|
|
278
|
-
async function
|
|
355
|
+
async function f(t2, n2, r2) {
|
|
279
356
|
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.");
|
|
280
357
|
let { registered: i3 } = await t2.webauthnAlreadyRegistered({ username: n2 });
|
|
281
|
-
return i3 ?
|
|
358
|
+
return i3 ? p(t2, n2, r2) : m(t2, n2, r2);
|
|
282
359
|
}
|
|
283
|
-
async function
|
|
360
|
+
async function p(t2, n2, r2) {
|
|
284
361
|
var _a;
|
|
285
362
|
let i3 = await t2.webauthnAuthStart({ username: n2 });
|
|
286
363
|
if (!i3.challenge) throw new e("WebAuthn auth start: missing challenge");
|
|
287
364
|
let a2 = i3.challenge;
|
|
288
365
|
if (!((_a = a2.publicKey) == null ? void 0 : _a.challenge)) throw new e("WebAuthn auth start: malformed challenge response");
|
|
289
|
-
let { publicKey: o2 } = a2, s2 =
|
|
290
|
-
id:
|
|
366
|
+
let { publicKey: o2 } = a2, s2 = u(o2.challenge), c2 = (o2.allowCredentials ?? []).map((e4) => ({
|
|
367
|
+
id: u(e4.id),
|
|
291
368
|
type: e4.type
|
|
292
|
-
})),
|
|
369
|
+
})), l2 = await navigator.credentials.get({ publicKey: {
|
|
293
370
|
challenge: s2,
|
|
294
|
-
allowCredentials:
|
|
371
|
+
allowCredentials: c2,
|
|
295
372
|
timeout: 6e4,
|
|
296
373
|
userVerification: "required"
|
|
297
374
|
} });
|
|
298
|
-
if (!
|
|
375
|
+
if (!l2) throw new e("WebAuthn authentication was cancelled");
|
|
299
376
|
return t2.authRequest(r2, { WebAuthN: {
|
|
300
377
|
session_id: i3.session_id,
|
|
301
|
-
credential:
|
|
378
|
+
credential: l2
|
|
302
379
|
} });
|
|
303
380
|
}
|
|
304
|
-
async function
|
|
381
|
+
async function m(t2, n2, r2) {
|
|
305
382
|
var _a, _b, _c;
|
|
306
383
|
let i3 = await t2.webauthnStartRegistration({ username: n2 });
|
|
307
384
|
if (!i3.public_key) throw new e("WebAuthn registration start: missing public_key");
|
|
308
385
|
let a2 = i3.public_key;
|
|
309
386
|
if (!a2.challenge) throw new e("WebAuthn registration start: malformed public_key response");
|
|
310
|
-
let o2 =
|
|
387
|
+
let o2 = u(a2.challenge), s2 = await navigator.credentials.create({ publicKey: {
|
|
311
388
|
rp: {
|
|
312
389
|
name: ((_a = a2.rp) == null ? void 0 : _a.name) ?? "Tari Wallet",
|
|
313
390
|
id: ((_b = a2.rp) == null ? void 0 : _b.id) ?? ((_c = globalThis.location) == null ? void 0 : _c.hostname)
|
|
@@ -338,14 +415,14 @@ async function f(t2, n2, r2) {
|
|
|
338
415
|
authenticatorSelection: { userVerification: "required" }
|
|
339
416
|
} });
|
|
340
417
|
if (!s2) throw new e("WebAuthn registration was cancelled");
|
|
341
|
-
let { token:
|
|
418
|
+
let { token: c2 } = await t2.webauthnFinishRegistration({
|
|
342
419
|
session_id: i3.session_id,
|
|
343
420
|
credential: s2,
|
|
344
421
|
requested_permissions: r2
|
|
345
422
|
});
|
|
346
|
-
return
|
|
423
|
+
return c2;
|
|
347
424
|
}
|
|
348
|
-
var
|
|
425
|
+
var h = class i2 {
|
|
349
426
|
constructor(e4) {
|
|
350
427
|
__publicField(this, "client");
|
|
351
428
|
__publicField(this, "_publicKey", null);
|
|
@@ -353,14 +430,14 @@ var p = class i2 {
|
|
|
353
430
|
this.client = e4;
|
|
354
431
|
}
|
|
355
432
|
static new(e4) {
|
|
356
|
-
let t2 =
|
|
433
|
+
let t2 = s.usingFetchTransport(e4.url);
|
|
357
434
|
return t2.setToken(e4.authToken), new i2(t2);
|
|
358
435
|
}
|
|
359
436
|
static async connect(e4) {
|
|
360
|
-
let t2 =
|
|
437
|
+
let t2 = s.usingFetchTransport(e4.url);
|
|
361
438
|
if (e4.authToken) t2.setToken(e4.authToken);
|
|
362
439
|
else {
|
|
363
|
-
let n3 = await
|
|
440
|
+
let n3 = await d(t2, e4);
|
|
364
441
|
t2.setToken(n3);
|
|
365
442
|
}
|
|
366
443
|
t2.setReauthenticationEnabled(true);
|
|
@@ -401,7 +478,7 @@ var p = class i2 {
|
|
|
401
478
|
}
|
|
402
479
|
};
|
|
403
480
|
export {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
481
|
+
s as WalletDaemonClient,
|
|
482
|
+
h as WalletDaemonSigner,
|
|
483
|
+
d as authenticate
|
|
407
484
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/ootle-wallet-daemon-signer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/tari-project/ootle.ts.git",
|
|
7
|
+
"directory": "packages/ootle-wallet-daemon-signer"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
4
12
|
"type": "module",
|
|
5
13
|
"main": "./dist/index.js",
|
|
6
14
|
"types": "./dist/index.d.ts",
|
|
@@ -17,9 +25,9 @@
|
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
27
|
"dependencies": {
|
|
20
|
-
"@tari-project/ootle-ts-bindings": "^1.
|
|
21
|
-
"@tari-project/wallet_jrpc_client": "^1.
|
|
22
|
-
"@tari-project/ootle": "0.
|
|
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"
|
|
23
31
|
},
|
|
24
32
|
"devDependencies": {
|
|
25
33
|
"@microsoft/api-extractor": "^7.57.7",
|