@canton-network/core-wallet-store-sql 1.13.2 → 1.14.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/bootstrap.d.ts +4 -4
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/index.cjs +73 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -27
- package/dist/index.js.map +1 -1
- package/dist/migrations/001-init.d.ts +2 -2
- package/dist/migrations/001-init.d.ts.map +1 -1
- package/dist/migrations/002-add-transaction-timestamps.d.ts +2 -2
- package/dist/migrations/002-add-transaction-timestamps.d.ts.map +1 -1
- package/dist/migrations/003-add-transaction-origin.d.ts +2 -2
- package/dist/migrations/003-add-transaction-origin.d.ts.map +1 -1
- package/dist/migrations/004-add-session-id.d.ts +2 -2
- package/dist/migrations/004-add-session-id.d.ts.map +1 -1
- package/dist/migrations/005-add-wallet-disabled-reason.d.ts +2 -2
- package/dist/migrations/005-add-wallet-disabled-reason.d.ts.map +1 -1
- package/dist/migrations/006-change-wallet-primary-key-to-composite.d.ts +2 -2
- package/dist/migrations/006-change-wallet-primary-key-to-composite.d.ts.map +1 -1
- package/dist/migrations/007-add-unique-primary-per-network.d.ts +2 -2
- package/dist/migrations/007-add-unique-primary-per-network.d.ts.map +1 -1
- package/dist/migrations/008-add-transaction-external-tx-id.d.ts +2 -2
- package/dist/migrations/008-add-transaction-external-tx-id.d.ts.map +1 -1
- package/dist/migrations/009-add-wallet-rights-columns.d.ts +2 -2
- package/dist/migrations/009-add-wallet-rights-columns.d.ts.map +1 -1
- package/dist/migrations/010-add-transaction-network-id.d.ts +2 -2
- package/dist/migrations/010-add-transaction-network-id.d.ts.map +1 -1
- package/dist/migrations/011-add-transaction-id-primary-key.d.ts +2 -2
- package/dist/migrations/011-add-transaction-id-primary-key.d.ts.map +1 -1
- package/dist/migrations/012-add-messages-to-sign.d.ts +1 -1
- package/dist/migrations/012-add-messages-to-sign.d.ts.map +1 -1
- package/dist/migrations/013-add-api-key.d.ts +1 -1
- package/dist/migrations/013-add-api-key.d.ts.map +1 -1
- package/dist/migrations/014-add-service-account-column.d.ts +2 -2
- package/dist/migrations/014-add-service-account-column.d.ts.map +1 -1
- package/dist/migrations/015-add-origin-field-session.d.ts +2 -2
- package/dist/migrations/015-add-origin-field-session.d.ts.map +1 -1
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.d.ts +5 -0
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.d.ts.map +1 -0
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js +27 -0
- package/dist/migrations/017-make-idp-issuer-nullable.d.ts +5 -0
- package/dist/migrations/017-make-idp-issuer-nullable.d.ts.map +1 -0
- package/dist/migrations/017-make-idp-issuer-nullable.js +88 -0
- package/dist/migrations/018-add-wallet-is-auth-party.d.ts +5 -0
- package/dist/migrations/018-add-wallet-is-auth-party.d.ts.map +1 -0
- package/dist/migrations/018-add-wallet-is-auth-party.js +11 -0
- package/dist/migrations/019-make-session-access-token-nullable.d.ts +5 -0
- package/dist/migrations/019-make-session-access-token-nullable.d.ts.map +1 -0
- package/dist/migrations/019-make-session-access-token-nullable.js +92 -0
- package/dist/migrations-test/helpers.d.ts +2 -2
- package/dist/migrations-test/helpers.d.ts.map +1 -1
- package/dist/migrations-test/seeds/001-init.d.ts +2 -2
- package/dist/migrations-test/seeds/001-init.d.ts.map +1 -1
- package/dist/migrations-test/seeds/002-transaction-timestamps.d.ts +2 -2
- package/dist/migrations-test/seeds/002-transaction-timestamps.d.ts.map +1 -1
- package/dist/migrations-test/seeds/003-transaction-origin.d.ts +2 -2
- package/dist/migrations-test/seeds/003-transaction-origin.d.ts.map +1 -1
- package/dist/migrations-test/seeds/004-add-session-id.d.ts +2 -2
- package/dist/migrations-test/seeds/004-add-session-id.d.ts.map +1 -1
- package/dist/migrations-test/seeds/005-add-wallet-disabled-reason.d.ts +2 -2
- package/dist/migrations-test/seeds/005-add-wallet-disabled-reason.d.ts.map +1 -1
- package/dist/migrations-test/seeds/008-transaction-external-tx-id.d.ts +2 -2
- package/dist/migrations-test/seeds/008-transaction-external-tx-id.d.ts.map +1 -1
- package/dist/migrations-test/seeds/009-add-wallet-rights-columns.d.ts +2 -2
- package/dist/migrations-test/seeds/009-add-wallet-rights-columns.d.ts.map +1 -1
- package/dist/migrations-test/seeds/010-transaction-with-network.d.ts +2 -2
- package/dist/migrations-test/seeds/010-transaction-with-network.d.ts.map +1 -1
- package/dist/migrations-test/seeds/012-add-messages-to-sign.d.ts +2 -2
- package/dist/migrations-test/seeds/012-add-messages-to-sign.d.ts.map +1 -1
- package/dist/migrations-test/seeds/013-add-api-key.d.ts +2 -2
- package/dist/migrations-test/seeds/013-add-api-key.d.ts.map +1 -1
- package/dist/migrations-test/seeds/014-add-service-account-column.d.ts +2 -2
- package/dist/migrations-test/seeds/014-add-service-account-column.d.ts.map +1 -1
- package/dist/migrations-test/seeds/016-add-failure-reason-and-awaiting-signature.d.ts +18 -0
- package/dist/migrations-test/seeds/016-add-failure-reason-and-awaiting-signature.d.ts.map +1 -0
- package/dist/migrations-test/seeds/017-make-idp-issuer-nullable.d.ts +9 -0
- package/dist/migrations-test/seeds/017-make-idp-issuer-nullable.d.ts.map +1 -0
- package/dist/migrations-test/seeds/019-make-session-access-token-nullable.d.ts +10 -0
- package/dist/migrations-test/seeds/019-make-session-access-token-nullable.d.ts.map +1 -0
- package/dist/migrator.d.ts +2 -2
- package/dist/migrator.d.ts.map +1 -1
- package/dist/schema.d.ts +8 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +26 -5
- package/dist/store-sql.d.ts +13 -7
- package/dist/store-sql.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -11,16 +11,23 @@ const toIdp = (table) => {
|
|
|
11
11
|
switch (table.type) {
|
|
12
12
|
case "oauth":
|
|
13
13
|
if (!table.configUrl) throw new Error(`Missing configUrl for oauth IdP: ${table.id}`);
|
|
14
|
+
if (table.issuer === null) throw new Error(`Missing issuer for oauth IdP: ${table.id}`);
|
|
14
15
|
return {
|
|
15
16
|
id: table.id,
|
|
16
17
|
type: table.type,
|
|
17
18
|
issuer: table.issuer,
|
|
18
19
|
configUrl: table.configUrl
|
|
19
20
|
};
|
|
20
|
-
case "self_signed":
|
|
21
|
+
case "self_signed":
|
|
22
|
+
if (table.issuer === null) throw new Error(`Missing issuer for self_signed IdP: ${table.id}`);
|
|
23
|
+
return {
|
|
24
|
+
id: table.id,
|
|
25
|
+
type: table.type,
|
|
26
|
+
issuer: table.issuer
|
|
27
|
+
};
|
|
28
|
+
case "self_issued": return {
|
|
21
29
|
id: table.id,
|
|
22
|
-
type: table.type
|
|
23
|
-
issuer: table.issuer
|
|
30
|
+
type: table.type
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
};
|
|
@@ -36,7 +43,13 @@ const fromIdp = (idp) => {
|
|
|
36
43
|
id: idp.id,
|
|
37
44
|
type: idp.type,
|
|
38
45
|
issuer: idp.issuer,
|
|
39
|
-
configUrl:
|
|
46
|
+
configUrl: null
|
|
47
|
+
};
|
|
48
|
+
case "self_issued": return {
|
|
49
|
+
id: idp.id,
|
|
50
|
+
type: idp.type,
|
|
51
|
+
issuer: null,
|
|
52
|
+
configUrl: null
|
|
40
53
|
};
|
|
41
54
|
}
|
|
42
55
|
};
|
|
@@ -72,24 +85,25 @@ const toSession = (table) => {
|
|
|
72
85
|
id: table.id,
|
|
73
86
|
network: table.network,
|
|
74
87
|
origin: table.origin,
|
|
75
|
-
accessToken: table.accessToken,
|
|
88
|
+
...table.accessToken ? { accessToken: table.accessToken } : {},
|
|
76
89
|
userId: table.userId
|
|
77
90
|
};
|
|
78
91
|
};
|
|
79
92
|
const fromWallet = (wallet, userId) => {
|
|
80
|
-
const { externalTxId, topologyTransactions, rights, ...rest } = wallet;
|
|
93
|
+
const { externalTxId, topologyTransactions, rights, isAuthParty, ...rest } = wallet;
|
|
81
94
|
return {
|
|
82
95
|
...rest,
|
|
83
96
|
primary: wallet.primary ? 1 : 0,
|
|
84
97
|
userId,
|
|
85
98
|
disabled: wallet.disabled !== void 0 && wallet.disabled ? 1 : 0,
|
|
99
|
+
isAuthParty: isAuthParty ? 1 : 0,
|
|
86
100
|
reason: wallet.reason ?? null,
|
|
87
101
|
externalTxId: externalTxId && externalTxId !== "" ? externalTxId : null,
|
|
88
102
|
topologyTransactions: topologyTransactions && topologyTransactions !== "" ? topologyTransactions : null
|
|
89
103
|
};
|
|
90
104
|
};
|
|
91
105
|
const toWalletUpdateProperties = (params) => {
|
|
92
|
-
const { status, externalTxId, topologyTransactions, disabled, reason, primary, signingProviderId, publicKey, namespace } = params;
|
|
106
|
+
const { status, externalTxId, topologyTransactions, disabled, reason, primary, signingProviderId, publicKey, namespace, isAuthParty } = params;
|
|
93
107
|
return {
|
|
94
108
|
...status !== void 0 && { status },
|
|
95
109
|
...externalTxId !== void 0 && { externalTxId },
|
|
@@ -99,7 +113,8 @@ const toWalletUpdateProperties = (params) => {
|
|
|
99
113
|
...reason !== void 0 && { reason },
|
|
100
114
|
...signingProviderId !== void 0 && { signingProviderId },
|
|
101
115
|
...publicKey !== void 0 && { publicKey },
|
|
102
|
-
...namespace !== void 0 && { namespace }
|
|
116
|
+
...namespace !== void 0 && { namespace },
|
|
117
|
+
...isAuthParty !== void 0 && { isAuthParty: isAuthParty ? 1 : 0 }
|
|
103
118
|
};
|
|
104
119
|
};
|
|
105
120
|
const toWalletStatus = (status) => {
|
|
@@ -118,6 +133,7 @@ const toWallet = (table) => {
|
|
|
118
133
|
networkId: table.networkId,
|
|
119
134
|
signingProviderId: table.signingProviderId,
|
|
120
135
|
disabled: table.disabled === 1,
|
|
136
|
+
isAuthParty: Boolean(table.isAuthParty),
|
|
121
137
|
userId: table.userId,
|
|
122
138
|
...table.externalTxId !== null && { externalTxId: table.externalTxId },
|
|
123
139
|
...table.topologyTransactions !== null && { topologyTransactions: table.topologyTransactions },
|
|
@@ -216,7 +232,7 @@ const toApiKey = (apiKey) => {
|
|
|
216
232
|
};
|
|
217
233
|
};
|
|
218
234
|
//#endregion
|
|
219
|
-
//#region \0@oxc-project+runtime@0.
|
|
235
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/typeof.js
|
|
220
236
|
function _typeof(o) {
|
|
221
237
|
"@babel/helpers - typeof";
|
|
222
238
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -226,7 +242,7 @@ function _typeof(o) {
|
|
|
226
242
|
}, _typeof(o);
|
|
227
243
|
}
|
|
228
244
|
//#endregion
|
|
229
|
-
//#region \0@oxc-project+runtime@0.
|
|
245
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPrimitive.js
|
|
230
246
|
function toPrimitive(t, r) {
|
|
231
247
|
if ("object" != _typeof(t) || !t) return t;
|
|
232
248
|
var e = t[Symbol.toPrimitive];
|
|
@@ -238,13 +254,13 @@ function toPrimitive(t, r) {
|
|
|
238
254
|
return ("string" === r ? String : Number)(t);
|
|
239
255
|
}
|
|
240
256
|
//#endregion
|
|
241
|
-
//#region \0@oxc-project+runtime@0.
|
|
257
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPropertyKey.js
|
|
242
258
|
function toPropertyKey(t) {
|
|
243
259
|
var i = toPrimitive(t, "string");
|
|
244
260
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
245
261
|
}
|
|
246
262
|
//#endregion
|
|
247
|
-
//#region \0@oxc-project+runtime@0.
|
|
263
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/defineProperty.js
|
|
248
264
|
function _defineProperty(e, r, t) {
|
|
249
265
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
250
266
|
value: t,
|
|
@@ -431,15 +447,39 @@ var StoreSql = class StoreSql {
|
|
|
431
447
|
const userId = this.assertConnected();
|
|
432
448
|
if (!session.origin) throw new Error("Session origin is required");
|
|
433
449
|
await this.db.transaction().execute(async (trx) => {
|
|
434
|
-
|
|
435
|
-
|
|
450
|
+
if (session.accessToken) {
|
|
451
|
+
const deleted = await trx.deleteFrom("sessions").where((eb) => eb.and([
|
|
452
|
+
eb("userId", "=", userId),
|
|
453
|
+
eb("origin", "=", session.origin),
|
|
454
|
+
eb("accessToken", "is not", null)
|
|
455
|
+
])).execute();
|
|
456
|
+
this.logger.debug(deleted, "Deleted old session");
|
|
457
|
+
}
|
|
436
458
|
const inserted = await trx.insertInto("sessions").values({
|
|
437
459
|
...session,
|
|
460
|
+
accessToken: session.accessToken ?? null,
|
|
438
461
|
userId
|
|
439
462
|
}).execute();
|
|
440
463
|
this.logger.debug(inserted, "Inserted new session");
|
|
441
464
|
});
|
|
442
465
|
}
|
|
466
|
+
async getOnboardingSession(sessionId) {
|
|
467
|
+
const row = await this.db.selectFrom("sessions").selectAll().where("id", "=", sessionId).where("accessToken", "is", null).executeTakeFirst();
|
|
468
|
+
return row ? toSession(row) : void 0;
|
|
469
|
+
}
|
|
470
|
+
async upgradeOnboardingSession(sessionId, accessToken) {
|
|
471
|
+
const userId = this.assertConnected();
|
|
472
|
+
return this.db.transaction().execute(async (trx) => {
|
|
473
|
+
const row = await trx.selectFrom("sessions").selectAll().where("id", "=", sessionId).where("userId", "=", userId).where("accessToken", "is", null).executeTakeFirst();
|
|
474
|
+
if (!row) throw new Error("Onboarding session not found");
|
|
475
|
+
await trx.deleteFrom("sessions").where("userId", "=", userId).where("origin", "=", row.origin).where("id", "!=", sessionId).execute();
|
|
476
|
+
await trx.updateTable("sessions").set({ accessToken }).where("id", "=", sessionId).execute();
|
|
477
|
+
return toSession({
|
|
478
|
+
...row,
|
|
479
|
+
accessToken
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
443
483
|
async removeSession(accessToken) {
|
|
444
484
|
const userId = this.assertConnected();
|
|
445
485
|
await this.db.deleteFrom("sessions").where((eb) => eb.and([eb("userId", "=", userId), eb("accessToken", "=", accessToken)])).execute();
|
|
@@ -448,7 +488,7 @@ var StoreSql = class StoreSql {
|
|
|
448
488
|
* Lists all pending transactions across all users.
|
|
449
489
|
*/
|
|
450
490
|
async listAllPendingTransactions() {
|
|
451
|
-
return (await this.db.selectFrom("transactions").selectAll().where("status", "=", "pending").execute()).map((row) => toTransaction(row));
|
|
491
|
+
return (await this.db.selectFrom("transactions").selectAll().where((eb) => eb.or([eb("status", "=", "pending"), eb("status", "=", "awaiting-signature")])).execute()).map((row) => toTransaction(row));
|
|
452
492
|
}
|
|
453
493
|
async getIdp(idpId) {
|
|
454
494
|
const idps = await this.listIdps();
|
|
@@ -488,11 +528,13 @@ var StoreSql = class StoreSql {
|
|
|
488
528
|
return network;
|
|
489
529
|
}
|
|
490
530
|
async getCurrentNetwork() {
|
|
531
|
+
const userId = this.assertConnected();
|
|
491
532
|
const token = this.authContext?.accessToken;
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
533
|
+
const onboardingSessionId = this.authContext && !this.authContext.isApiKey ? this.authContext.sessionId : void 0;
|
|
534
|
+
if (!token && !onboardingSessionId) throw new Error("No session found");
|
|
535
|
+
const sessionRow = await this.db.selectFrom("sessions").selectAll().where("userId", "=", userId).where((eb) => token ? eb("accessToken", "=", token) : eb.and([eb("id", "=", onboardingSessionId), eb("accessToken", "is", null)])).executeTakeFirst();
|
|
536
|
+
if (!sessionRow) throw new Error("No session found");
|
|
537
|
+
const networkId = toSession(sessionRow).network;
|
|
496
538
|
if (!networkId) throw new Error("No current network set in session");
|
|
497
539
|
const network = (await this.listNetworks()).find((n) => n.id === networkId);
|
|
498
540
|
if (!network) throw new Error(`Network "${networkId}" not found`);
|
|
@@ -541,6 +583,7 @@ var StoreSql = class StoreSql {
|
|
|
541
583
|
const payload = updates.payload ?? existing.payload;
|
|
542
584
|
const signedAt = updates.signedAt ?? existing.signedAt;
|
|
543
585
|
const externalTxId = updates.externalTxId ?? existing.externalTxId;
|
|
586
|
+
const failureReason = updates.failureReason ?? existing.failureReason;
|
|
544
587
|
return {
|
|
545
588
|
id: existing.id,
|
|
546
589
|
commandId: existing.commandId,
|
|
@@ -551,7 +594,8 @@ var StoreSql = class StoreSql {
|
|
|
551
594
|
...payload !== void 0 && { payload },
|
|
552
595
|
...existing.createdAt !== void 0 && { createdAt: existing.createdAt },
|
|
553
596
|
...signedAt !== void 0 && { signedAt },
|
|
554
|
-
...externalTxId !== void 0 && { externalTxId }
|
|
597
|
+
...externalTxId !== void 0 && { externalTxId },
|
|
598
|
+
...failureReason !== void 0 && { failureReason }
|
|
555
599
|
};
|
|
556
600
|
}
|
|
557
601
|
async setTransaction(transaction) {
|
|
@@ -559,23 +603,25 @@ var StoreSql = class StoreSql {
|
|
|
559
603
|
const network = await this.getCurrentNetwork();
|
|
560
604
|
await this.db.insertInto("transactions").values(fromTransaction(transaction, userId, network.id)).execute();
|
|
561
605
|
}
|
|
562
|
-
async setTransactionSigned(transactionId, signedAt, externalTxId) {
|
|
563
|
-
await this.setTransactionStatus(transactionId, "signed", {
|
|
606
|
+
async setTransactionSigned(transactionId, signedAt, externalTxId, opts) {
|
|
607
|
+
return await this.setTransactionStatus(transactionId, "signed", {
|
|
564
608
|
signedAt,
|
|
565
609
|
...externalTxId !== void 0 && { externalTxId }
|
|
566
|
-
});
|
|
610
|
+
}, opts);
|
|
567
611
|
}
|
|
568
|
-
async setTransactionStatus(transactionId, status, updates = {}) {
|
|
612
|
+
async setTransactionStatus(transactionId, status, updates = {}, opts) {
|
|
569
613
|
const userId = this.assertConnected();
|
|
570
614
|
const network = await this.getCurrentNetwork();
|
|
571
615
|
const existing = await this.getTransaction(transactionId);
|
|
572
616
|
if (!existing) throw new Error(`Transaction not found with id: ${transactionId}`);
|
|
617
|
+
if (opts?.expectedStatus && existing.status !== opts.expectedStatus) return false;
|
|
573
618
|
const updated = this.mergeTransactionStatusUpdate(existing, status, updates);
|
|
574
|
-
await this.db.updateTable("transactions").set(fromTransaction(updated, userId, network.id)).where((eb) => eb.and([
|
|
619
|
+
return (await this.db.updateTable("transactions").set(fromTransaction(updated, userId, network.id)).where((eb) => eb.and([
|
|
575
620
|
eb("id", "=", transactionId),
|
|
576
621
|
eb("userId", "=", userId),
|
|
577
|
-
eb("networkId", "=", network.id)
|
|
578
|
-
|
|
622
|
+
eb("networkId", "=", network.id),
|
|
623
|
+
...opts?.expectedStatus ? [eb("status", "=", opts.expectedStatus)] : []
|
|
624
|
+
])).executeTakeFirst()).numUpdatedRows > 0n;
|
|
579
625
|
}
|
|
580
626
|
async getTransaction(transactionId) {
|
|
581
627
|
const userId = this.assertConnected();
|