@fairmint/canton-node-sdk 0.0.277 → 0.0.279
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/README.md +197 -14
- package/build/src/utils/external-signing/index.d.ts +2 -0
- package/build/src/utils/external-signing/index.d.ts.map +1 -1
- package/build/src/utils/external-signing/index.js +2 -0
- package/build/src/utils/external-signing/index.js.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts +93 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.js +253 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.js.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership.d.ts +48 -0
- package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership.js +179 -0
- package/build/src/utils/external-signing/wallet-ownership.js.map +1 -0
- package/build/src/wallets/cip103.d.ts +100 -6
- package/build/src/wallets/cip103.d.ts.map +1 -1
- package/build/src/wallets/cip103.js +237 -107
- package/build/src/wallets/cip103.js.map +1 -1
- package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
- package/build/src/wallets/da-utilities/client.js +3 -0
- package/build/src/wallets/da-utilities/client.js.map +1 -1
- package/build/src/wallets/errors.d.ts +51 -0
- package/build/src/wallets/errors.d.ts.map +1 -1
- package/build/src/wallets/errors.js +68 -1
- package/build/src/wallets/errors.js.map +1 -1
- package/build/src/wallets/holdings.d.ts +25 -0
- package/build/src/wallets/holdings.d.ts.map +1 -1
- package/build/src/wallets/holdings.js +44 -0
- package/build/src/wallets/holdings.js.map +1 -1
- package/build/src/wallets/index.d.ts +14 -7
- package/build/src/wallets/index.d.ts.map +1 -1
- package/build/src/wallets/index.js +22 -3
- package/build/src/wallets/index.js.map +1 -1
- package/build/src/wallets/notify.d.ts +7 -0
- package/build/src/wallets/notify.d.ts.map +1 -0
- package/build/src/wallets/notify.js +21 -0
- package/build/src/wallets/notify.js.map +1 -0
- package/build/src/wallets/ownership.d.ts +156 -0
- package/build/src/wallets/ownership.d.ts.map +1 -0
- package/build/src/wallets/ownership.js +269 -0
- package/build/src/wallets/ownership.js.map +1 -0
- package/build/src/wallets/session.d.ts +107 -0
- package/build/src/wallets/session.d.ts.map +1 -0
- package/build/src/wallets/session.js +371 -0
- package/build/src/wallets/session.js.map +1 -0
- package/build/src/wallets/store.d.ts +138 -0
- package/build/src/wallets/store.d.ts.map +1 -0
- package/build/src/wallets/store.js +262 -0
- package/build/src/wallets/store.js.map +1 -0
- package/build/src/wallets/templates.d.ts +15 -0
- package/build/src/wallets/templates.d.ts.map +1 -1
- package/build/src/wallets/templates.js +33 -9
- package/build/src/wallets/templates.js.map +1 -1
- package/build/src/wallets/token-registry.d.ts +15 -2
- package/build/src/wallets/token-registry.d.ts.map +1 -1
- package/build/src/wallets/token-registry.js.map +1 -1
- package/build/src/wallets/token-standard-wallet.d.ts +94 -9
- package/build/src/wallets/token-standard-wallet.d.ts.map +1 -1
- package/build/src/wallets/token-standard-wallet.js +160 -19
- package/build/src/wallets/token-standard-wallet.js.map +1 -1
- package/build/src/wallets/token-wallet.d.ts +43 -7
- package/build/src/wallets/token-wallet.d.ts.map +1 -1
- package/build/src/wallets/token-wallet.js +113 -35
- package/build/src/wallets/token-wallet.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WALLET_OWNERSHIP_VERSION = exports.WALLET_OWNERSHIP_TITLE = void 0;
|
|
4
|
+
exports.isWalletOwnershipDomain = isWalletOwnershipDomain;
|
|
5
|
+
exports.isWalletOwnershipPartyId = isWalletOwnershipPartyId;
|
|
6
|
+
exports.buildWalletOwnershipMessage = buildWalletOwnershipMessage;
|
|
7
|
+
exports.parseWalletOwnershipMessage = parseWalletOwnershipMessage;
|
|
8
|
+
exports.proveWalletOwnership = proveWalletOwnership;
|
|
9
|
+
exports.requestWalletOwnershipVerdict = requestWalletOwnershipVerdict;
|
|
10
|
+
/**
|
|
11
|
+
* Proof that the user controls a wallet's party, not just its party id: the wallet signs a canonical, human-readable
|
|
12
|
+
* message (CIP-0103 `signMessage`) built from a challenge the dApp's server issued, and the server verifies it with
|
|
13
|
+
* `verifyWalletOwnership` (Node only, exported from the package root). A check in the browser proves nothing: anyone
|
|
14
|
+
* can call this code with a made-up provider, so only the server's verification counts.
|
|
15
|
+
*
|
|
16
|
+
* The message is plain text with a fixed first line and a statement that it is not a transaction, so a dApp cannot use
|
|
17
|
+
* it to get a transaction hash (34 binary bytes) signed. Wallets sign the raw message bytes with the party's key (Loop:
|
|
18
|
+
* Ed25519 over the UTF-8 bytes; the CIP-0103 reference wallet: the same), so the text form is the only protection. The
|
|
19
|
+
* nonce must come from the server, be random, and be accepted once.
|
|
20
|
+
*
|
|
21
|
+
* The `Network:` line is a label, not proof: a party id is derived from its key and is the same on every network, so a
|
|
22
|
+
* verified proof says nothing about the party existing or being hosted on that network. `proveWalletOwnership` refuses
|
|
23
|
+
* a wallet that reports another network as a guard against mistakes; a server that needs the network proven must look
|
|
24
|
+
* the party up on that network (its Scan or ledger party and topology APIs).
|
|
25
|
+
*/
|
|
26
|
+
const cip103_1 = require("./cip103");
|
|
27
|
+
const errors_1 = require("./errors");
|
|
28
|
+
const json_1 = require("./json");
|
|
29
|
+
/** The first line of every ownership message. */
|
|
30
|
+
exports.WALLET_OWNERSHIP_TITLE = 'Canton wallet ownership proof';
|
|
31
|
+
/** The message format version, its `Version:` line. */
|
|
32
|
+
exports.WALLET_OWNERSHIP_VERSION = '1';
|
|
33
|
+
const DOMAIN_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?(?::[0-9]{1,5})?$/;
|
|
34
|
+
const NONCE_PATTERN = /^[A-Za-z0-9._~-]{16,512}$/;
|
|
35
|
+
/** Printable ASCII without spaces. */
|
|
36
|
+
const TOKEN_PATTERN = /^[!-~]+$/;
|
|
37
|
+
const ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
38
|
+
/** Whether `value` may be a message's domain: a host name, optionally with a port. */
|
|
39
|
+
function isWalletOwnershipDomain(value) {
|
|
40
|
+
return typeof value === 'string' && DOMAIN_PATTERN.test(value);
|
|
41
|
+
}
|
|
42
|
+
/** Whether `value` may be a message's party: a Canton party id (`hint::namespace`) of printable ASCII. */
|
|
43
|
+
function isWalletOwnershipPartyId(value) {
|
|
44
|
+
return (typeof value === 'string' && value.length <= 512 && TOKEN_PATTERN.test(value) && value.split('::').length === 2);
|
|
45
|
+
}
|
|
46
|
+
/** The reason a field is not valid in a message, or null. */
|
|
47
|
+
function fieldProblem(fields) {
|
|
48
|
+
if (!isWalletOwnershipDomain(fields.domain)) {
|
|
49
|
+
return 'domain must be a host name, optionally with a port';
|
|
50
|
+
}
|
|
51
|
+
if (typeof fields.nonce !== 'string' || !NONCE_PATTERN.test(fields.nonce)) {
|
|
52
|
+
return 'nonce must be 16-512 characters of letters, digits and . _ ~ -';
|
|
53
|
+
}
|
|
54
|
+
if (!isWalletOwnershipPartyId(fields.partyId)) {
|
|
55
|
+
return 'partyId must be a Canton party id (hint::namespace)';
|
|
56
|
+
}
|
|
57
|
+
if (fields.network !== undefined &&
|
|
58
|
+
(typeof fields.network !== 'string' || fields.network.length > 128 || !TOKEN_PATTERN.test(fields.network))) {
|
|
59
|
+
return 'network must be 1-128 printable characters without spaces';
|
|
60
|
+
}
|
|
61
|
+
for (const key of ['issuedAt', 'expiresAt']) {
|
|
62
|
+
const value = fields[key];
|
|
63
|
+
// An out-of-range date (month 13) is an Invalid Date, whose toISOString() throws: check it first.
|
|
64
|
+
if (typeof value !== 'string' ||
|
|
65
|
+
!ISO_PATTERN.test(value) ||
|
|
66
|
+
Number.isNaN(Date.parse(value)) ||
|
|
67
|
+
new Date(value).toISOString() !== value) {
|
|
68
|
+
return `${key} must be an ISO-8601 UTC time with milliseconds (Date.toISOString())`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (Date.parse(fields.expiresAt) <= Date.parse(fields.issuedAt)) {
|
|
72
|
+
return 'expiresAt must be after issuedAt';
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The canonical message for these fields. Throws `TypeError` on a field that is not valid. The same fields always give
|
|
78
|
+
* the same text, so the server rebuilds it from the fields it parses and refuses anything else.
|
|
79
|
+
*/
|
|
80
|
+
function buildWalletOwnershipMessage(fields) {
|
|
81
|
+
const problem = fieldProblem(fields);
|
|
82
|
+
if (problem !== null)
|
|
83
|
+
throw new TypeError(`Invalid wallet ownership message: ${problem}`);
|
|
84
|
+
return [
|
|
85
|
+
exports.WALLET_OWNERSHIP_TITLE,
|
|
86
|
+
`Sign this message only to prove to ${fields.domain} that you control the Canton party below. It is not a transaction: it moves no assets and authorizes nothing on the ledger.`,
|
|
87
|
+
'',
|
|
88
|
+
`Version: ${exports.WALLET_OWNERSHIP_VERSION}`,
|
|
89
|
+
`Domain: ${fields.domain}`,
|
|
90
|
+
`Party: ${fields.partyId}`,
|
|
91
|
+
...(fields.network !== undefined ? [`Network: ${fields.network}`] : []),
|
|
92
|
+
`Nonce: ${fields.nonce}`,
|
|
93
|
+
`Issued At: ${fields.issuedAt}`,
|
|
94
|
+
`Expiration Time: ${fields.expiresAt}`,
|
|
95
|
+
].join('\n');
|
|
96
|
+
}
|
|
97
|
+
const FIELD_LINES = new Map([
|
|
98
|
+
['Version', 'version'],
|
|
99
|
+
['Domain', 'domain'],
|
|
100
|
+
['Party', 'partyId'],
|
|
101
|
+
['Network', 'network'],
|
|
102
|
+
['Nonce', 'nonce'],
|
|
103
|
+
['Issued At', 'issuedAt'],
|
|
104
|
+
['Expiration Time', 'expiresAt'],
|
|
105
|
+
]);
|
|
106
|
+
/**
|
|
107
|
+
* The fields of a canonical ownership message, or null for any text that is not exactly what
|
|
108
|
+
* {@link buildWalletOwnershipMessage} gives for its fields (another version, an extra line or space, a reordered
|
|
109
|
+
* field).
|
|
110
|
+
*/
|
|
111
|
+
function parseWalletOwnershipMessage(message) {
|
|
112
|
+
if (typeof message !== 'string' || message.length > 4096)
|
|
113
|
+
return null;
|
|
114
|
+
const lines = message.split('\n');
|
|
115
|
+
if (lines[0] !== exports.WALLET_OWNERSHIP_TITLE)
|
|
116
|
+
return null;
|
|
117
|
+
const found = {};
|
|
118
|
+
for (const line of lines.slice(3)) {
|
|
119
|
+
const separator = line.indexOf(': ');
|
|
120
|
+
const key = separator > 0 ? FIELD_LINES.get(line.slice(0, separator)) : undefined;
|
|
121
|
+
if (key === undefined || found[key] !== undefined)
|
|
122
|
+
return null;
|
|
123
|
+
found[key] = line.slice(separator + 2);
|
|
124
|
+
}
|
|
125
|
+
const { version, domain, partyId, network, nonce, issuedAt, expiresAt } = found;
|
|
126
|
+
if (version !== exports.WALLET_OWNERSHIP_VERSION ||
|
|
127
|
+
domain === undefined ||
|
|
128
|
+
partyId === undefined ||
|
|
129
|
+
nonce === undefined ||
|
|
130
|
+
issuedAt === undefined ||
|
|
131
|
+
expiresAt === undefined) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const fields = {
|
|
135
|
+
domain,
|
|
136
|
+
partyId,
|
|
137
|
+
nonce,
|
|
138
|
+
issuedAt,
|
|
139
|
+
expiresAt,
|
|
140
|
+
...(network !== undefined && { network }),
|
|
141
|
+
};
|
|
142
|
+
if (fieldProblem(fields) !== null)
|
|
143
|
+
return null;
|
|
144
|
+
return buildWalletOwnershipMessage(fields) === message ? fields : null;
|
|
145
|
+
}
|
|
146
|
+
/** The signature from a `signMessage` result: `{signature}` (CIP-0103) or a bare string (some wallets). */
|
|
147
|
+
function readSignature(raw) {
|
|
148
|
+
if (typeof raw === 'string')
|
|
149
|
+
return (0, json_1.nonEmptyString)(raw);
|
|
150
|
+
return (0, json_1.isRecord)(raw) ? (0, json_1.nonEmptyString)(raw['signature']) : undefined;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Ask the wallet to sign the ownership message for the challenge, as its primary account. Returns what the server needs
|
|
154
|
+
* to verify; it is not itself proof of anything until the server verified it (`verifyWalletOwnership`).
|
|
155
|
+
*/
|
|
156
|
+
async function proveWalletOwnership(provider, options) {
|
|
157
|
+
const account = await (0, cip103_1.primaryAccount)(provider);
|
|
158
|
+
if (options.partyId !== undefined && options.partyId !== account.partyId) {
|
|
159
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The wallet's primary account is ${account.partyId}, not ${options.partyId}; switch accounts in the wallet first`);
|
|
160
|
+
}
|
|
161
|
+
if (account.publicKey === undefined) {
|
|
162
|
+
throw new errors_1.WalletReadError('The wallet returned a primary account without publicKey, so ownership cannot be proven');
|
|
163
|
+
}
|
|
164
|
+
const { challenge } = options;
|
|
165
|
+
// A guard against signing for the wrong network, not proof: the wallet reports its network itself.
|
|
166
|
+
if (challenge.network !== undefined && account.networkId !== undefined && account.networkId !== challenge.network) {
|
|
167
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The wallet is on ${account.networkId}, not ${challenge.network}; switch networks in the wallet first`);
|
|
168
|
+
}
|
|
169
|
+
let message;
|
|
170
|
+
try {
|
|
171
|
+
message = buildWalletOwnershipMessage({
|
|
172
|
+
domain: challenge.domain,
|
|
173
|
+
partyId: account.partyId,
|
|
174
|
+
nonce: challenge.nonce,
|
|
175
|
+
issuedAt: challenge.issuedAt,
|
|
176
|
+
expiresAt: challenge.expiresAt,
|
|
177
|
+
...(challenge.network !== undefined && { network: challenge.network }),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw new errors_1.WalletSignError('invalid-challenge', error instanceof Error ? error.message : String(error));
|
|
182
|
+
}
|
|
183
|
+
const now = (options.now ?? (() => new Date()))().getTime();
|
|
184
|
+
if (!(now < Date.parse(challenge.expiresAt))) {
|
|
185
|
+
throw new errors_1.WalletSignError('invalid-challenge', 'The ownership challenge has expired; ask the server for a new one');
|
|
186
|
+
}
|
|
187
|
+
let raw;
|
|
188
|
+
try {
|
|
189
|
+
raw = await provider.request({ method: 'signMessage', params: { message } });
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
const code = (0, cip103_1.cip103ErrorCode)(error);
|
|
193
|
+
if (code === cip103_1.CIP103_ERROR_CODES.userRejected) {
|
|
194
|
+
throw new errors_1.WalletSignError('rejected-by-user', `The user declined to sign the ownership message: ${(0, cip103_1.describeError)(error)}`, code);
|
|
195
|
+
}
|
|
196
|
+
throw new errors_1.WalletSignError('failed', `The wallet did not sign the ownership message: ${(0, cip103_1.describeError)(error)}`, code);
|
|
197
|
+
}
|
|
198
|
+
const signature = readSignature(raw);
|
|
199
|
+
if (signature === undefined) {
|
|
200
|
+
throw new errors_1.WalletSignError('failed', 'The wallet answered signMessage without a signature');
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
partyId: account.partyId,
|
|
204
|
+
publicKey: account.publicKey,
|
|
205
|
+
...(account.namespace !== undefined && { namespace: account.namespace }),
|
|
206
|
+
message,
|
|
207
|
+
signature,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Whether `value` is a whole verdict: a verified one names `partyId`, a refused one gives its reason and message. */
|
|
211
|
+
function isWalletOwnershipVerdict(value, partyId) {
|
|
212
|
+
if (!(0, json_1.isRecord)(value))
|
|
213
|
+
return false;
|
|
214
|
+
if (value['verified'] === true) {
|
|
215
|
+
const { claimedNetwork } = value;
|
|
216
|
+
return (value['partyId'] === partyId &&
|
|
217
|
+
typeof value['publicKeyFingerprint'] === 'string' &&
|
|
218
|
+
typeof value['verifiedAt'] === 'string' &&
|
|
219
|
+
(claimedNetwork === null || typeof claimedNetwork === 'string'));
|
|
220
|
+
}
|
|
221
|
+
return value['verified'] === false && typeof value['reason'] === 'string' && typeof value['message'] === 'string';
|
|
222
|
+
}
|
|
223
|
+
/** POST `body` as JSON and return the response's `data`; throws on a non-2xx answer or one without `data`. */
|
|
224
|
+
async function postForData(fetch, url, body) {
|
|
225
|
+
const response = await fetch(url, {
|
|
226
|
+
method: 'POST',
|
|
227
|
+
headers: { 'content-type': 'application/json' },
|
|
228
|
+
body: JSON.stringify(body),
|
|
229
|
+
});
|
|
230
|
+
let json;
|
|
231
|
+
try {
|
|
232
|
+
json = JSON.parse(await response.text());
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
json = undefined;
|
|
236
|
+
}
|
|
237
|
+
const record = (0, json_1.isRecord)(json) ? json : {};
|
|
238
|
+
if (!response.ok || !('data' in record)) {
|
|
239
|
+
const error = (0, json_1.nonEmptyString)(record['error']) ?? `HTTP ${response.status}`;
|
|
240
|
+
throw new Error(`The server refused the ownership check: ${error}`);
|
|
241
|
+
}
|
|
242
|
+
return record['data'];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The browser half of an ownership check, against a server that uses the SDK's challenger (or the same wire format: a
|
|
246
|
+
* 2xx answer is `{ data }`, any other `{ error: string }`): POST `challengeUrl` with `{ network, partyId }`, have the
|
|
247
|
+
* wallet sign the challenge (`proveWalletOwnership`), POST `verifyUrl` with `{ token, proof }`, and return the server's
|
|
248
|
+
* verdict. Throws when no verdict was reached: the server refused (a non-2xx answer, or one without `data`), or the
|
|
249
|
+
* wallet did not sign (`WalletSignError`).
|
|
250
|
+
*/
|
|
251
|
+
async function requestWalletOwnershipVerdict(provider, options) {
|
|
252
|
+
const { partyId, network } = options;
|
|
253
|
+
const issued = await postForData(options.fetch, options.challengeUrl, { network, partyId });
|
|
254
|
+
if (!(0, json_1.isRecord)(issued) || !(0, json_1.isRecord)(issued['challenge']) || typeof issued['token'] !== 'string') {
|
|
255
|
+
throw new Error('The server answered the ownership challenge request without { challenge, token }');
|
|
256
|
+
}
|
|
257
|
+
// proveWalletOwnership checks every field before anything is signed.
|
|
258
|
+
const challenge = issued['challenge'];
|
|
259
|
+
if (challenge.network !== (0, cip103_1.cip103NetworkId)(network)) {
|
|
260
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The server issued a challenge for ${String(challenge.network)}, not ${(0, cip103_1.cip103NetworkId)(network)}`);
|
|
261
|
+
}
|
|
262
|
+
const proof = await proveWalletOwnership(provider, { challenge, partyId });
|
|
263
|
+
const verdict = await postForData(options.fetch, options.verifyUrl, { token: issued['token'], proof });
|
|
264
|
+
if (!isWalletOwnershipVerdict(verdict, partyId)) {
|
|
265
|
+
throw new Error('The server answered the ownership proof without a well-formed verdict for the party');
|
|
266
|
+
}
|
|
267
|
+
return verdict;
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=ownership.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership.js","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,qCAOkB;AAElB,qCAA4D;AAC5D,iCAAkD;AAElD,iDAAiD;AACpC,QAAA,sBAAsB,GAAG,+BAA+B,CAAC;AACtE,uDAAuD;AAC1C,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAmC5C,MAAM,cAAc,GAAG,mEAAmE,CAAC;AAC3F,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,sCAAsC;AACtC,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,WAAW,GAAG,+CAA+C,CAAC;AAEpE,sFAAsF;AACtF,iCAAwC,KAAc;IACpD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAED,0GAA0G;AAC1G,kCAAyC,KAAc;IACrD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC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C,YAAY,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,IAAI,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC/F,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;IACtG,CAAC;IACD,qEAAqE;IACrE,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAwC,CAAC;IAC7E,IAAI,SAAS,CAAC,OAAO,KAAK,IAAA,wBAAe,EAAC,OAAO,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,wBAAe,CACvB,mBAAmB,EACnB,qCAAqC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,IAAA,wBAAe,EAAC,OAAO,CAAC,EAAE,CAClG,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACvG,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type Cip103Provider } from './cip103';
|
|
2
|
+
import type { DaNetwork } from './da-utilities/client';
|
|
3
|
+
import { type WalletErrorDescription } from './errors';
|
|
4
|
+
/** A connected wallet. Each session is one object: compare by identity to tell a live session from an ended one. */
|
|
5
|
+
export interface ConnectedWallet {
|
|
6
|
+
readonly provider: Cip103Provider;
|
|
7
|
+
readonly partyId: string;
|
|
8
|
+
/**
|
|
9
|
+
* Unique per `ConnectedWallet` object within its session: use it as a UI key (React `key`), so a new session of the
|
|
10
|
+
* same party (another provider or network) remounts what the previous one rendered.
|
|
11
|
+
*/
|
|
12
|
+
readonly key: string;
|
|
13
|
+
/** What the dApp connected for; lets `createTokenWalletStore` build DA's registry client itself. */
|
|
14
|
+
readonly network?: DaNetwork;
|
|
15
|
+
}
|
|
16
|
+
export type Cip103SessionState = {
|
|
17
|
+
readonly status: 'disconnected';
|
|
18
|
+
/**
|
|
19
|
+
* `user`: the dApp disconnected. `wallet`: the wallet rejected or ended the session. `null`: never connected, or
|
|
20
|
+
* a failure (`error`).
|
|
21
|
+
*/
|
|
22
|
+
readonly endedBy: 'user' | 'wallet' | null;
|
|
23
|
+
/** Why the last connect, party lookup or wallet setup failed. */
|
|
24
|
+
readonly error: WalletErrorDescription | null;
|
|
25
|
+
} | {
|
|
26
|
+
readonly status: 'connecting';
|
|
27
|
+
} | {
|
|
28
|
+
readonly status: 'connected';
|
|
29
|
+
readonly wallet: ConnectedWallet;
|
|
30
|
+
};
|
|
31
|
+
export interface Cip103ConnectContext {
|
|
32
|
+
/**
|
|
33
|
+
* The network the dApp connects for, carried on the `ConnectedWallet`. A wallet whose primary account reports the
|
|
34
|
+
* CIP-0103 `networkId` of another DA network (`canton:mainnet` when connecting for `devnet`, and the reverse) is
|
|
35
|
+
* refused: the session stays disconnected with an error. CIP-0103 does not fix how a wallet spells its network id, so
|
|
36
|
+
* an id the session does not recognise, or none, is accepted rather than locking every user out.
|
|
37
|
+
*/
|
|
38
|
+
readonly network?: DaNetwork;
|
|
39
|
+
}
|
|
40
|
+
export interface Cip103Session {
|
|
41
|
+
subscribe(listener: () => void): () => void;
|
|
42
|
+
/** The current state; the same object until it changes (for `useSyncExternalStore`). */
|
|
43
|
+
getSnapshot(): Cip103SessionState;
|
|
44
|
+
/**
|
|
45
|
+
* The wallet reports a live session (its accept callback, or a session it restored): reads the primary account
|
|
46
|
+
* (`getPrimaryAccount`) and connects as its party.
|
|
47
|
+
*
|
|
48
|
+
* - A reply that a newer call, `end()`, `fail()` or `dispose()` superseded is dropped. Of overlapping party lookups the
|
|
49
|
+
* most recently started one decides. A `connected()` lookup supersedes older ones only once it has an answer it
|
|
50
|
+
* acts on, so one whose failure is ignored (below) leaves a pending `connect()` or `accountsChanged` lookup to
|
|
51
|
+
* decide.
|
|
52
|
+
* - The same provider, party and network keep the same `ConnectedWallet` object, so a repeated callback changes
|
|
53
|
+
* nothing.
|
|
54
|
+
* - Ignored after `end()` until `connect()` runs again (wallets can repeat a connect callback after a disconnect).
|
|
55
|
+
* - With `ifConnected: true` it first asks CIP-0103 `isConnected` and does nothing unless the wallet answers `{
|
|
56
|
+
* isConnected: true }` (4200, any other failure or another answer count as not connected). Of overlapping restores,
|
|
57
|
+
* the most recently started one decides, whichever answers first: an older one is dropped, also once its party
|
|
58
|
+
* lookup has started (a newer restore that finds no session drops it, so it cannot connect after it). A restore is
|
|
59
|
+
* also dropped when anything else started a party lookup or changed the session while it waited. While it waits it
|
|
60
|
+
* supersedes nothing: only an `isConnected: true` answer starts its lookup, which then supersedes older ones, so a
|
|
61
|
+
* restore that finds no session never cancels a pending `connect()` or `accountsChanged` lookup.
|
|
62
|
+
* - A failed account read, or an account on the other DA network, leaves the session disconnected with `error`;
|
|
63
|
+
* `connect()` recovers from it. While a wallet is connected, such a failure is ignored instead: a stale callback,
|
|
64
|
+
* or another wallet that cannot be read, never drops a healthy session. The exception is the connected wallet's own
|
|
65
|
+
* provider answering with an account on the other DA network: the wallet switched networks, so the session ends
|
|
66
|
+
* with `error`. While a `connect()` is pending (`connecting`), every such failure is ignored: that `connect()`
|
|
67
|
+
* reads the account itself and reports the outcome.
|
|
68
|
+
*/
|
|
69
|
+
connected(provider: Cip103Provider, context?: Cip103ConnectContext & {
|
|
70
|
+
readonly ifConnected?: boolean;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* The user asked to connect: sends CIP-0103 `disconnect` (best-effort) to any other wallet the session is on (a
|
|
74
|
+
* wallet switch), sets `connecting`, waits for a disconnect of this wallet still in flight, then re-arms
|
|
75
|
+
* `connected()` and sends CIP-0103 `connect` (the wallet's own sign-in); wallet callbacks before that are ignored. It
|
|
76
|
+
* then always reads the primary account again, also when the wallet answers that it was already connected, so a
|
|
77
|
+
* failed or lost party lookup recovers without a reload. A failure becomes `error` (4001: declined). Resolves when it
|
|
78
|
+
* settled; superseded by a newer `connect()`, `end()`, `fail()` or `dispose()`.
|
|
79
|
+
*/
|
|
80
|
+
connect(provider: Cip103Provider, context?: Cip103ConnectContext): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* The session ended. `user`: the dApp disconnected, and CIP-0103 `disconnect` is sent best-effort to the providers
|
|
83
|
+
* the session is on (the connected wallet's, and the one a pending `connect()` signs in to; failures are ignored),
|
|
84
|
+
* before the new state is published. A `connect()` to such a provider waits for its disconnects to settle before it
|
|
85
|
+
* sends `connect`, so a disconnect cannot land after the new sign-in, also a `connect()` that sending the disconnect
|
|
86
|
+
* sets off (then that `connect()` owns the state, and `end()` publishes nothing). It waits for each disconnect at
|
|
87
|
+
* most until three seconds after that disconnect was sent, also when a later disconnect of the same wallet is chained
|
|
88
|
+
* to it, so a disconnect that never answers delays no `connect()` past three seconds after it was sent, however many
|
|
89
|
+
* `connect()` and `end('user')` calls follow it. A nested `end()` or `fail()` that sending the disconnect sets off
|
|
90
|
+
* does not take the state over: `end('user')` still publishes `endedBy: 'user'`. `wallet`: the wallet rejected or
|
|
91
|
+
* ended the session; nothing is sent. Either way `connected()` is ignored until `connect()` runs again.
|
|
92
|
+
*/
|
|
93
|
+
end(by: 'user' | 'wallet'): void;
|
|
94
|
+
/** The wallet's own setup failed (e.g. Loop's `init`): disconnected with `error`. */
|
|
95
|
+
fail(error: unknown): void;
|
|
96
|
+
/** Whether `wallet` is still this session's connected wallet. */
|
|
97
|
+
isCurrent(wallet: ConnectedWallet): boolean;
|
|
98
|
+
/** Stop: listeners are removed, pending replies dropped and no further state is published. */
|
|
99
|
+
dispose(): void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A CIP-0103 wallet session. While connected it listens on the provider: `accountsChanged` reads the primary account
|
|
103
|
+
* again (another party becomes a new `ConnectedWallet`), and a `statusChanged` whose `connection.isConnected` is false
|
|
104
|
+
* ends the session (`wallet`). A wallet that never emits these events loses nothing.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createCip103Session(): Cip103Session;
|
|
107
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/wallets/session.ts"],"names":[],"mappings":"AAQA,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAwC,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAG7F,oHAAoH;AACpH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oGAAoG;IACpG,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC;CAC9B;AAED,MAAM,MAAM,kBAAkB,GAC1B;IACE,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAC3C,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC/C,GACD;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE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