@canton-network/core-wallet-store-sql 1.13.2 → 1.15.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 +87 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -29
- 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 +14 -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 +20 -12
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Kysely } from 'kysely';
|
|
2
|
-
import { BootstrapConfig } from '@canton-network/core-wallet-store';
|
|
3
|
-
import { Logger } from 'pino';
|
|
4
|
-
import { DB } from './schema';
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import type { BootstrapConfig } from '@canton-network/core-wallet-store';
|
|
3
|
+
import type { Logger } from 'pino';
|
|
4
|
+
import type { DB } from './schema';
|
|
5
5
|
export declare function bootstrap(db: Kysely<DB>, config: BootstrapConfig, logger: Logger): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAElC,wBAAsB,SAAS,CAC3B,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EACd,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
package/dist/index.cjs
CHANGED
|
@@ -22,10 +22,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
24
|
let _canton_network_core_wallet_auth = require("@canton-network/core-wallet-auth");
|
|
25
|
+
let _canton_network_core_rpc_errors = require("@canton-network/core-rpc-errors");
|
|
26
|
+
let _canton_network_core_wallet_store = require("@canton-network/core-wallet-store");
|
|
25
27
|
let kysely = require("kysely");
|
|
26
28
|
let better_sqlite3 = require("better-sqlite3");
|
|
27
29
|
better_sqlite3 = __toESM(better_sqlite3, 1);
|
|
28
|
-
let _canton_network_core_wallet_store = require("@canton-network/core-wallet-store");
|
|
29
30
|
let pg = require("pg");
|
|
30
31
|
pg = __toESM(pg, 1);
|
|
31
32
|
let umzug = require("umzug");
|
|
@@ -36,16 +37,23 @@ const toIdp = (table) => {
|
|
|
36
37
|
switch (table.type) {
|
|
37
38
|
case "oauth":
|
|
38
39
|
if (!table.configUrl) throw new Error(`Missing configUrl for oauth IdP: ${table.id}`);
|
|
40
|
+
if (table.issuer === null) throw new Error(`Missing issuer for oauth IdP: ${table.id}`);
|
|
39
41
|
return {
|
|
40
42
|
id: table.id,
|
|
41
43
|
type: table.type,
|
|
42
44
|
issuer: table.issuer,
|
|
43
45
|
configUrl: table.configUrl
|
|
44
46
|
};
|
|
45
|
-
case "self_signed":
|
|
47
|
+
case "self_signed":
|
|
48
|
+
if (table.issuer === null) throw new Error(`Missing issuer for self_signed IdP: ${table.id}`);
|
|
49
|
+
return {
|
|
50
|
+
id: table.id,
|
|
51
|
+
type: table.type,
|
|
52
|
+
issuer: table.issuer
|
|
53
|
+
};
|
|
54
|
+
case "self_issued": return {
|
|
46
55
|
id: table.id,
|
|
47
|
-
type: table.type
|
|
48
|
-
issuer: table.issuer
|
|
56
|
+
type: table.type
|
|
49
57
|
};
|
|
50
58
|
}
|
|
51
59
|
};
|
|
@@ -61,7 +69,13 @@ const fromIdp = (idp) => {
|
|
|
61
69
|
id: idp.id,
|
|
62
70
|
type: idp.type,
|
|
63
71
|
issuer: idp.issuer,
|
|
64
|
-
configUrl:
|
|
72
|
+
configUrl: null
|
|
73
|
+
};
|
|
74
|
+
case "self_issued": return {
|
|
75
|
+
id: idp.id,
|
|
76
|
+
type: idp.type,
|
|
77
|
+
issuer: null,
|
|
78
|
+
configUrl: null
|
|
65
79
|
};
|
|
66
80
|
}
|
|
67
81
|
};
|
|
@@ -97,24 +111,25 @@ const toSession = (table) => {
|
|
|
97
111
|
id: table.id,
|
|
98
112
|
network: table.network,
|
|
99
113
|
origin: table.origin,
|
|
100
|
-
accessToken: table.accessToken,
|
|
114
|
+
...table.accessToken ? { accessToken: table.accessToken } : {},
|
|
101
115
|
userId: table.userId
|
|
102
116
|
};
|
|
103
117
|
};
|
|
104
118
|
const fromWallet = (wallet, userId) => {
|
|
105
|
-
const { externalTxId, topologyTransactions, rights, ...rest } = wallet;
|
|
119
|
+
const { externalTxId, topologyTransactions, rights, isAuthParty, ...rest } = wallet;
|
|
106
120
|
return {
|
|
107
121
|
...rest,
|
|
108
122
|
primary: wallet.primary ? 1 : 0,
|
|
109
123
|
userId,
|
|
110
124
|
disabled: wallet.disabled !== void 0 && wallet.disabled ? 1 : 0,
|
|
125
|
+
isAuthParty: isAuthParty ? 1 : 0,
|
|
111
126
|
reason: wallet.reason ?? null,
|
|
112
127
|
externalTxId: externalTxId && externalTxId !== "" ? externalTxId : null,
|
|
113
128
|
topologyTransactions: topologyTransactions && topologyTransactions !== "" ? topologyTransactions : null
|
|
114
129
|
};
|
|
115
130
|
};
|
|
116
131
|
const toWalletUpdateProperties = (params) => {
|
|
117
|
-
const { status, externalTxId, topologyTransactions, disabled, reason, primary, signingProviderId, publicKey, namespace } = params;
|
|
132
|
+
const { status, externalTxId, topologyTransactions, disabled, reason, primary, signingProviderId, publicKey, namespace, isAuthParty } = params;
|
|
118
133
|
return {
|
|
119
134
|
...status !== void 0 && { status },
|
|
120
135
|
...externalTxId !== void 0 && { externalTxId },
|
|
@@ -124,7 +139,8 @@ const toWalletUpdateProperties = (params) => {
|
|
|
124
139
|
...reason !== void 0 && { reason },
|
|
125
140
|
...signingProviderId !== void 0 && { signingProviderId },
|
|
126
141
|
...publicKey !== void 0 && { publicKey },
|
|
127
|
-
...namespace !== void 0 && { namespace }
|
|
142
|
+
...namespace !== void 0 && { namespace },
|
|
143
|
+
...isAuthParty !== void 0 && { isAuthParty: isAuthParty ? 1 : 0 }
|
|
128
144
|
};
|
|
129
145
|
};
|
|
130
146
|
const toWalletStatus = (status) => {
|
|
@@ -143,6 +159,7 @@ const toWallet = (table) => {
|
|
|
143
159
|
networkId: table.networkId,
|
|
144
160
|
signingProviderId: table.signingProviderId,
|
|
145
161
|
disabled: table.disabled === 1,
|
|
162
|
+
isAuthParty: Boolean(table.isAuthParty),
|
|
146
163
|
userId: table.userId,
|
|
147
164
|
...table.externalTxId !== null && { externalTxId: table.externalTxId },
|
|
148
165
|
...table.topologyTransactions !== null && { topologyTransactions: table.topologyTransactions },
|
|
@@ -241,7 +258,7 @@ const toApiKey = (apiKey) => {
|
|
|
241
258
|
};
|
|
242
259
|
};
|
|
243
260
|
//#endregion
|
|
244
|
-
//#region \0@oxc-project+runtime@0.
|
|
261
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
245
262
|
function _typeof(o) {
|
|
246
263
|
"@babel/helpers - typeof";
|
|
247
264
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -251,7 +268,7 @@ function _typeof(o) {
|
|
|
251
268
|
}, _typeof(o);
|
|
252
269
|
}
|
|
253
270
|
//#endregion
|
|
254
|
-
//#region \0@oxc-project+runtime@0.
|
|
271
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
255
272
|
function toPrimitive(t, r) {
|
|
256
273
|
if ("object" != _typeof(t) || !t) return t;
|
|
257
274
|
var e = t[Symbol.toPrimitive];
|
|
@@ -263,13 +280,13 @@ function toPrimitive(t, r) {
|
|
|
263
280
|
return ("string" === r ? String : Number)(t);
|
|
264
281
|
}
|
|
265
282
|
//#endregion
|
|
266
|
-
//#region \0@oxc-project+runtime@0.
|
|
283
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
267
284
|
function toPropertyKey(t) {
|
|
268
285
|
var i = toPrimitive(t, "string");
|
|
269
286
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
270
287
|
}
|
|
271
288
|
//#endregion
|
|
272
|
-
//#region \0@oxc-project+runtime@0.
|
|
289
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
273
290
|
function _defineProperty(e, r, t) {
|
|
274
291
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
275
292
|
value: t,
|
|
@@ -344,6 +361,13 @@ var StoreSql = class StoreSql {
|
|
|
344
361
|
rights: rightRows.map(({ right }) => fromPartyRight(right)).filter((right) => right !== void 0)
|
|
345
362
|
};
|
|
346
363
|
}
|
|
364
|
+
async getWalletByJwt(userId, partyId, audiences) {
|
|
365
|
+
const networks = (await this.db.selectFrom("networks").selectAll().execute()).map(toNetwork);
|
|
366
|
+
const network = (0, _canton_network_core_wallet_store.resolveSelfIssuedNetworkByAudiences)(networks, audiences);
|
|
367
|
+
if (!network) return;
|
|
368
|
+
const row = await this.db.selectFrom("wallets").selectAll().where("userId", "=", userId).where("partyId", "=", partyId).where("networkId", "=", network.id).executeTakeFirst();
|
|
369
|
+
return row ? toWallet(row) : void 0;
|
|
370
|
+
}
|
|
347
371
|
async getPrimaryWallet() {
|
|
348
372
|
return (await this.getWallets()).find((w) => w.primary === true);
|
|
349
373
|
}
|
|
@@ -456,15 +480,39 @@ var StoreSql = class StoreSql {
|
|
|
456
480
|
const userId = this.assertConnected();
|
|
457
481
|
if (!session.origin) throw new Error("Session origin is required");
|
|
458
482
|
await this.db.transaction().execute(async (trx) => {
|
|
459
|
-
|
|
460
|
-
|
|
483
|
+
if (session.accessToken) {
|
|
484
|
+
const deleted = await trx.deleteFrom("sessions").where((eb) => eb.and([
|
|
485
|
+
eb("userId", "=", userId),
|
|
486
|
+
eb("origin", "=", session.origin),
|
|
487
|
+
eb("accessToken", "is not", null)
|
|
488
|
+
])).execute();
|
|
489
|
+
this.logger.debug(deleted, "Deleted old session");
|
|
490
|
+
}
|
|
461
491
|
const inserted = await trx.insertInto("sessions").values({
|
|
462
492
|
...session,
|
|
493
|
+
accessToken: session.accessToken ?? null,
|
|
463
494
|
userId
|
|
464
495
|
}).execute();
|
|
465
496
|
this.logger.debug(inserted, "Inserted new session");
|
|
466
497
|
});
|
|
467
498
|
}
|
|
499
|
+
async getOnboardingSession(sessionId) {
|
|
500
|
+
const row = await this.db.selectFrom("sessions").selectAll().where("id", "=", sessionId).where("accessToken", "is", null).executeTakeFirst();
|
|
501
|
+
return row ? toSession(row) : void 0;
|
|
502
|
+
}
|
|
503
|
+
async upgradeOnboardingSession(sessionId, accessToken) {
|
|
504
|
+
const userId = this.assertConnected();
|
|
505
|
+
return this.db.transaction().execute(async (trx) => {
|
|
506
|
+
const row = await trx.selectFrom("sessions").selectAll().where("id", "=", sessionId).where("userId", "=", userId).where("accessToken", "is", null).executeTakeFirst();
|
|
507
|
+
if (!row) throw new Error("Onboarding session not found");
|
|
508
|
+
await trx.deleteFrom("sessions").where("userId", "=", userId).where("origin", "=", row.origin).where("id", "!=", sessionId).execute();
|
|
509
|
+
await trx.updateTable("sessions").set({ accessToken }).where("id", "=", sessionId).execute();
|
|
510
|
+
return toSession({
|
|
511
|
+
...row,
|
|
512
|
+
accessToken
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
468
516
|
async removeSession(accessToken) {
|
|
469
517
|
const userId = this.assertConnected();
|
|
470
518
|
await this.db.deleteFrom("sessions").where((eb) => eb.and([eb("userId", "=", userId), eb("accessToken", "=", accessToken)])).execute();
|
|
@@ -473,7 +521,7 @@ var StoreSql = class StoreSql {
|
|
|
473
521
|
* Lists all pending transactions across all users.
|
|
474
522
|
*/
|
|
475
523
|
async listAllPendingTransactions() {
|
|
476
|
-
return (await this.db.selectFrom("transactions").selectAll().where("status", "=", "pending").execute()).map((row) => toTransaction(row));
|
|
524
|
+
return (await this.db.selectFrom("transactions").selectAll().where((eb) => eb.or([eb("status", "=", "pending"), eb("status", "=", "awaiting-signature")])).execute()).map((row) => toTransaction(row));
|
|
477
525
|
}
|
|
478
526
|
async getIdp(idpId) {
|
|
479
527
|
const idps = await this.listIdps();
|
|
@@ -513,11 +561,13 @@ var StoreSql = class StoreSql {
|
|
|
513
561
|
return network;
|
|
514
562
|
}
|
|
515
563
|
async getCurrentNetwork() {
|
|
564
|
+
const userId = this.assertConnected();
|
|
516
565
|
const token = this.authContext?.accessToken;
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
566
|
+
const onboardingSessionId = this.authContext && !this.authContext.isApiKey ? this.authContext.sessionId : void 0;
|
|
567
|
+
if (!token && !onboardingSessionId) throw _canton_network_core_rpc_errors.providerErrors.unauthorized({ message: "No session found" });
|
|
568
|
+
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();
|
|
569
|
+
if (!sessionRow) throw _canton_network_core_rpc_errors.providerErrors.unauthorized({ message: "No session found" });
|
|
570
|
+
const networkId = toSession(sessionRow).network;
|
|
521
571
|
if (!networkId) throw new Error("No current network set in session");
|
|
522
572
|
const network = (await this.listNetworks()).find((n) => n.id === networkId);
|
|
523
573
|
if (!network) throw new Error(`Network "${networkId}" not found`);
|
|
@@ -540,6 +590,8 @@ var StoreSql = class StoreSql {
|
|
|
540
590
|
async updateNetwork(network) {
|
|
541
591
|
this.assertConnected();
|
|
542
592
|
await this.db.transaction().execute(async (trx) => {
|
|
593
|
+
const existing = (await trx.selectFrom("networks").selectAll().execute()).map(toNetwork);
|
|
594
|
+
(0, _canton_network_core_wallet_store.assertUniqueSelfIssuedAudience)(existing, network, network.id);
|
|
543
595
|
const networkEntry = fromNetwork(network, void 0);
|
|
544
596
|
this.logger.info(networkEntry, "Updating network table");
|
|
545
597
|
await trx.updateTable("networks").set(networkEntry).where("id", "=", network.id).execute();
|
|
@@ -550,7 +602,9 @@ var StoreSql = class StoreSql {
|
|
|
550
602
|
if (!(await this.listIdps()).find((idp) => idp.id === network.identityProviderId)) throw new Error(`Identity provider "${network.identityProviderId}" not found`);
|
|
551
603
|
await this.db.transaction().execute(async (trx) => {
|
|
552
604
|
if (await trx.selectFrom("networks").selectAll().where("id", "=", network.id).executeTakeFirst()) throw new Error(`Network ${network.id} already exists`);
|
|
553
|
-
|
|
605
|
+
const existing = (await trx.selectFrom("networks").selectAll().execute()).map(toNetwork);
|
|
606
|
+
(0, _canton_network_core_wallet_store.assertUniqueSelfIssuedAudience)(existing, network);
|
|
607
|
+
await trx.insertInto("networks").values(fromNetwork(network, userId)).execute();
|
|
554
608
|
});
|
|
555
609
|
}
|
|
556
610
|
async removeNetwork(networkId) {
|
|
@@ -566,6 +620,7 @@ var StoreSql = class StoreSql {
|
|
|
566
620
|
const payload = updates.payload ?? existing.payload;
|
|
567
621
|
const signedAt = updates.signedAt ?? existing.signedAt;
|
|
568
622
|
const externalTxId = updates.externalTxId ?? existing.externalTxId;
|
|
623
|
+
const failureReason = updates.failureReason ?? existing.failureReason;
|
|
569
624
|
return {
|
|
570
625
|
id: existing.id,
|
|
571
626
|
commandId: existing.commandId,
|
|
@@ -576,7 +631,8 @@ var StoreSql = class StoreSql {
|
|
|
576
631
|
...payload !== void 0 && { payload },
|
|
577
632
|
...existing.createdAt !== void 0 && { createdAt: existing.createdAt },
|
|
578
633
|
...signedAt !== void 0 && { signedAt },
|
|
579
|
-
...externalTxId !== void 0 && { externalTxId }
|
|
634
|
+
...externalTxId !== void 0 && { externalTxId },
|
|
635
|
+
...failureReason !== void 0 && { failureReason }
|
|
580
636
|
};
|
|
581
637
|
}
|
|
582
638
|
async setTransaction(transaction) {
|
|
@@ -584,23 +640,25 @@ var StoreSql = class StoreSql {
|
|
|
584
640
|
const network = await this.getCurrentNetwork();
|
|
585
641
|
await this.db.insertInto("transactions").values(fromTransaction(transaction, userId, network.id)).execute();
|
|
586
642
|
}
|
|
587
|
-
async setTransactionSigned(transactionId, signedAt, externalTxId) {
|
|
588
|
-
await this.setTransactionStatus(transactionId, "signed", {
|
|
643
|
+
async setTransactionSigned(transactionId, signedAt, externalTxId, opts) {
|
|
644
|
+
return await this.setTransactionStatus(transactionId, "signed", {
|
|
589
645
|
signedAt,
|
|
590
646
|
...externalTxId !== void 0 && { externalTxId }
|
|
591
|
-
});
|
|
647
|
+
}, opts);
|
|
592
648
|
}
|
|
593
|
-
async setTransactionStatus(transactionId, status, updates = {}) {
|
|
649
|
+
async setTransactionStatus(transactionId, status, updates = {}, opts) {
|
|
594
650
|
const userId = this.assertConnected();
|
|
595
651
|
const network = await this.getCurrentNetwork();
|
|
596
652
|
const existing = await this.getTransaction(transactionId);
|
|
597
653
|
if (!existing) throw new Error(`Transaction not found with id: ${transactionId}`);
|
|
654
|
+
if (opts?.expectedStatus && existing.status !== opts.expectedStatus) return false;
|
|
598
655
|
const updated = this.mergeTransactionStatusUpdate(existing, status, updates);
|
|
599
|
-
await this.db.updateTable("transactions").set(fromTransaction(updated, userId, network.id)).where((eb) => eb.and([
|
|
656
|
+
return (await this.db.updateTable("transactions").set(fromTransaction(updated, userId, network.id)).where((eb) => eb.and([
|
|
600
657
|
eb("id", "=", transactionId),
|
|
601
658
|
eb("userId", "=", userId),
|
|
602
|
-
eb("networkId", "=", network.id)
|
|
603
|
-
|
|
659
|
+
eb("networkId", "=", network.id),
|
|
660
|
+
...opts?.expectedStatus ? [eb("status", "=", opts.expectedStatus)] : []
|
|
661
|
+
])).executeTakeFirst()).numUpdatedRows > 0n;
|
|
604
662
|
}
|
|
605
663
|
async getTransaction(transactionId) {
|
|
606
664
|
const userId = this.assertConnected();
|