bulletin-deploy 0.20.0 → 0.21.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 (66) hide show
  1. package/dist/auth/index.d.ts +4 -2
  2. package/dist/auth/index.js +6 -3
  3. package/dist/auth/vendor/allocations.d.ts +7 -40
  4. package/dist/auth/vendor/allocations.js +1 -1
  5. package/dist/auth/vendor/auth.d.ts +7 -4
  6. package/dist/auth/vendor/auth.js +3 -3
  7. package/dist/auth/vendor/index.d.ts +4 -3
  8. package/dist/auth/vendor/index.js +5 -3
  9. package/dist/auth/vendor/sessionSigner.d.ts +19 -22
  10. package/dist/auth/vendor/sessionSigner.js +5 -1
  11. package/dist/auth/vendor/signer.d.ts +1 -0
  12. package/dist/auth/vendor/types.d.ts +2 -1
  13. package/dist/auth/vendor/ui/index.d.ts +1 -0
  14. package/dist/auth/vendor/ui/status.d.ts +1 -0
  15. package/dist/auth-config.d.ts +10 -12
  16. package/dist/auth-config.js +5 -5
  17. package/dist/bug-report.js +4 -4
  18. package/dist/chain-health.js +3 -3
  19. package/dist/{chunk-7SXO544V.js → chunk-355BT3NW.js} +5 -6
  20. package/dist/{chunk-YLLTQM5Z.js → chunk-4FIMYLWV.js} +2 -2
  21. package/dist/{chunk-3BSPX4JN.js → chunk-7QQZ57E6.js} +5 -4
  22. package/dist/{chunk-26ZYMWSC.js → chunk-BDUL42WH.js} +1 -1
  23. package/dist/{chunk-IHC2QG2L.js → chunk-CQA3JPYX.js} +3 -3
  24. package/dist/{chunk-QBHUCTVT.js → chunk-E77HESGN.js} +2 -2
  25. package/dist/{chunk-EBYWI7FI.js → chunk-EWQ2QZ44.js} +20 -19
  26. package/dist/{chunk-IF3SANQR.js → chunk-GL7JKE7O.js} +19 -6
  27. package/dist/{chunk-LRRFXOLE.js → chunk-GLLLSFMA.js} +3 -3
  28. package/dist/chunk-IMCDXJ4G.js +66 -0
  29. package/dist/{chunk-YIVCOJAB.js → chunk-IOLWREZB.js} +5 -5
  30. package/dist/{chunk-DHHHYZTR.js → chunk-K57H4IRT.js} +1 -1
  31. package/dist/{chunk-BXDMEOLH.js → chunk-KOLWOUWP.js} +1 -1
  32. package/dist/{chunk-DT6ABL3J.js → chunk-LPG3QSOM.js} +10 -8
  33. package/dist/{chunk-GRPLHUYC.js → chunk-MRZL4IXT.js} +21 -19
  34. package/dist/{chunk-G7EH3XIW.js → chunk-PN5JKONF.js} +48 -28
  35. package/dist/{chunk-MTXFJTX6.js → chunk-UPENVZ7J.js} +1 -1
  36. package/dist/{chunk-6GHDPDZN.js → chunk-WYZUDE6I.js} +2 -2
  37. package/dist/chunk-probe.js +3 -3
  38. package/dist/commands/login.d.ts +1 -0
  39. package/dist/commands/login.js +25 -26
  40. package/dist/commands/logout.d.ts +1 -0
  41. package/dist/commands/logout.js +10 -10
  42. package/dist/commands/transfer.js +6 -6
  43. package/dist/commands/whoami.d.ts +1 -0
  44. package/dist/commands/whoami.js +5 -3
  45. package/dist/deploy-actors.d.ts +6 -4
  46. package/dist/deploy-actors.js +10 -11
  47. package/dist/deploy.js +17 -17
  48. package/dist/dotns.js +6 -6
  49. package/dist/index.js +18 -18
  50. package/dist/manifest/publish.js +18 -18
  51. package/dist/memory-report.js +2 -2
  52. package/dist/merkle.js +17 -17
  53. package/dist/personhood/bootstrap.js +6 -6
  54. package/dist/personhood/constants.d.ts +2 -2
  55. package/dist/personhood/people-client.js +6 -6
  56. package/dist/pool.js +5 -5
  57. package/dist/run-state.js +1 -1
  58. package/dist/sss-allowance-cache.js +5 -5
  59. package/dist/sss-allowance.d.ts +8 -1
  60. package/dist/sss-allowance.js +3 -1
  61. package/dist/storage-signer.js +17 -17
  62. package/dist/telemetry.js +2 -2
  63. package/dist/version-check.js +3 -3
  64. package/dist/ws.js +4 -4
  65. package/package.json +5 -4
  66. package/dist/chunk-S6CPT2TU.js +0 -94
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  preflightSssAllowance
3
- } from "./chunk-QBHUCTVT.js";
3
+ } from "./chunk-E77HESGN.js";
4
4
  import {
5
5
  statementSigningAccount
6
- } from "./chunk-GRPLHUYC.js";
6
+ } from "./chunk-MRZL4IXT.js";
7
7
  import {
8
8
  subnameNestingLevels
9
9
  } from "./chunk-HNJWIY55.js";
@@ -31,24 +31,32 @@ import {
31
31
  classifyFile,
32
32
  parseManifest
33
33
  } from "./chunk-H44LXDQJ.js";
34
+ import {
35
+ STALE_SESSION_DEPLOY_MESSAGE,
36
+ getPeopleChainEndpoints,
37
+ hasPersistedSession
38
+ } from "./chunk-GL7JKE7O.js";
34
39
  import {
35
40
  setDeployContext
36
- } from "./chunk-LRRFXOLE.js";
41
+ } from "./chunk-GLLLSFMA.js";
37
42
  import {
38
43
  getBestBlockNumber,
39
44
  probeChunks,
40
45
  probeFinalityGap
41
- } from "./chunk-DHHHYZTR.js";
46
+ } from "./chunk-K57H4IRT.js";
42
47
  import {
43
48
  packSection
44
49
  } from "./chunk-C2TS5MER.js";
45
50
  import {
46
51
  resolveStorageSigner
47
- } from "./chunk-DT6ABL3J.js";
52
+ } from "./chunk-LPG3QSOM.js";
48
53
  import {
49
54
  createSlotAccountSigner,
50
55
  requestResourceAllocation
51
- } from "./chunk-7SXO544V.js";
56
+ } from "./chunk-355BT3NW.js";
57
+ import {
58
+ SESSION_EXPIRED_MESSAGE
59
+ } from "./chunk-IMCDXJ4G.js";
52
60
  import {
53
61
  AUTO_MAP_RENT_HEADROOM,
54
62
  DEFAULT_TLD,
@@ -62,7 +70,7 @@ import {
62
70
  popStatusName,
63
71
  topUpTargetFor,
64
72
  verifyNonceAdvanced
65
- } from "./chunk-YIVCOJAB.js";
73
+ } from "./chunk-IOLWREZB.js";
66
74
  import {
67
75
  mnemonicConflictNotice,
68
76
  resolveEffectiveMnemonic
@@ -76,16 +84,11 @@ import {
76
84
  readAccountAuthorization,
77
85
  resolvePoolMnemonic,
78
86
  selectAccount
79
- } from "./chunk-26ZYMWSC.js";
87
+ } from "./chunk-BDUL42WH.js";
80
88
  import {
81
89
  getWsProvider,
82
90
  resetMalformedFrames
83
- } from "./chunk-6GHDPDZN.js";
84
- import {
85
- STALE_SESSION_DEPLOY_MESSAGE,
86
- getPeopleChainEndpoints,
87
- hasPersistedSession
88
- } from "./chunk-IF3SANQR.js";
91
+ } from "./chunk-WYZUDE6I.js";
89
92
  import {
90
93
  DEFAULT_ENV_ID,
91
94
  describeContractSources,
@@ -95,7 +98,7 @@ import {
95
98
  } from "./chunk-3NR3T7US.js";
96
99
  import {
97
100
  ChainHealthSampler
98
- } from "./chunk-MTXFJTX6.js";
101
+ } from "./chunk-UPENVZ7J.js";
99
102
  import {
100
103
  VERSION,
101
104
  captureWarning,
@@ -110,7 +113,7 @@ import {
110
113
  truncateAddress,
111
114
  withDeploySpan,
112
115
  withSpan
113
- } from "./chunk-YLLTQM5Z.js";
116
+ } from "./chunk-4FIMYLWV.js";
114
117
  import {
115
118
  NonRetryableError
116
119
  } from "./chunk-SH2LG52Z.js";
@@ -2410,9 +2413,7 @@ async function deploy(content, domainName = null, options = {}) {
2410
2413
  }
2411
2414
  const allowed = await preflightSssAllowance(statementAccount, () => getPeopleChainEndpoints(envId));
2412
2415
  if (allowed === false) {
2413
- throw new NonRetryableError(
2414
- `Session signing allowance has expired (~2-3 days after login). Run \`${CLI_NAME} logout\`, then \`${CLI_NAME} login\`, to renew (login alone won't refresh a stale session).`
2415
- );
2416
+ throw new NonRetryableError(SESSION_EXPIRED_MESSAGE);
2416
2417
  }
2417
2418
  } catch (e) {
2418
2419
  if (e instanceof NonRetryableError) throw e;
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-3NR3T7US.js";
4
4
  import {
5
5
  VERSION
6
- } from "./chunk-YLLTQM5Z.js";
6
+ } from "./chunk-4FIMYLWV.js";
7
7
  import {
8
8
  CLI_NAME
9
9
  } from "./chunk-DNXE3Q5D.js";
@@ -13,7 +13,6 @@ import { existsSync, readdirSync } from "fs";
13
13
  import { homedir } from "os";
14
14
  import { join } from "path";
15
15
  var DOT_DAPP_ID = "polkadot-app-deploy";
16
- var DOT_PRODUCT_ID = DOT_DAPP_ID;
17
16
  var DOT_DERIVATION_INDEX = 0;
18
17
  var DOT_HOST_NAME = "polkadot-app-deploy";
19
18
  var STALE_SESSION_MESSAGE = `Stored login session could not be read \u2014 it may have been written by an older version. Run "${CLI_NAME} logout", then "${CLI_NAME} login" to pair again.`;
@@ -28,7 +27,7 @@ function hasPersistedSession() {
28
27
  return false;
29
28
  }
30
29
  }
31
- function buildAuthConfig(doc, envId) {
30
+ function buildAuthConfig(doc, envId, networkSuffix) {
32
31
  const peopleChain = doc.chains.find((c) => c.id === "people");
33
32
  if (!peopleChain) {
34
33
  throw new Error(
@@ -42,9 +41,10 @@ function buildAuthConfig(doc, envId) {
42
41
  );
43
42
  }
44
43
  const peopleEndpoints = Array.isArray(endpoint.wss) ? endpoint.wss : [endpoint.wss];
44
+ const tld = doc.environments.find((e) => e.id === envId)?.tld ?? networkSuffix ?? "dot";
45
45
  return {
46
46
  dappId: DOT_DAPP_ID,
47
- productId: DOT_PRODUCT_ID,
47
+ productId: `${DOT_DAPP_ID}.${tld}`,
48
48
  derivationIndex: DOT_DERIVATION_INDEX,
49
49
  hostName: DOT_HOST_NAME,
50
50
  hostVersion: VERSION,
@@ -62,15 +62,27 @@ async function getPeopleChainEndpoints(envId) {
62
62
  const config = buildAuthConfig(doc, envId);
63
63
  return config.peopleEndpoints;
64
64
  }
65
+ async function readNetworkSuffix(peopleEndpoints) {
66
+ const { Storage, str } = await import("@polkadot-api/substrate-bindings");
67
+ const { readStorageValue } = await import("./sss-allowance.js");
68
+ const value = await readStorageValue(Storage("NetworkSuffix")("NetworkSuffix").enc(), peopleEndpoints);
69
+ if (!value) return null;
70
+ try {
71
+ return str.dec(value) || null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
65
76
  async function getAuthClient(envId) {
66
77
  const { createAuthClient } = await import("./auth/index.js");
67
78
  const { doc } = await loadEnvironments();
68
- return createAuthClient(buildAuthConfig(doc, envId));
79
+ const config = buildAuthConfig(doc, envId);
80
+ if (doc.environments.find((e) => e.id === envId)?.tld) return createAuthClient(config);
81
+ return createAuthClient(buildAuthConfig(doc, envId, await readNetworkSuffix(config.peopleEndpoints)));
69
82
  }
70
83
 
71
84
  export {
72
85
  DOT_DAPP_ID,
73
- DOT_PRODUCT_ID,
74
86
  DOT_DERIVATION_INDEX,
75
87
  DOT_HOST_NAME,
76
88
  STALE_SESSION_MESSAGE,
@@ -79,5 +91,6 @@ export {
79
91
  buildAuthConfig,
80
92
  resolveBulletinEndpoints,
81
93
  getPeopleChainEndpoints,
94
+ readNetworkSuffix,
82
95
  getAuthClient
83
96
  };
@@ -2,15 +2,15 @@ import {
2
2
  classifyErrorArea,
3
3
  isInteractive,
4
4
  promptYesNo
5
- } from "./chunk-BXDMEOLH.js";
5
+ } from "./chunk-KOLWOUWP.js";
6
6
  import {
7
7
  VERSION,
8
8
  getCurrentSentryTraceId,
9
9
  resolveIssueRepoSlug
10
- } from "./chunk-YLLTQM5Z.js";
10
+ } from "./chunk-4FIMYLWV.js";
11
11
  import {
12
12
  package_default
13
- } from "./chunk-3BSPX4JN.js";
13
+ } from "./chunk-7QQZ57E6.js";
14
14
 
15
15
  // src/bug-report.ts
16
16
  import { execSync, execFileSync } from "child_process";
@@ -0,0 +1,66 @@
1
+ import {
2
+ NonRetryableError
3
+ } from "./chunk-SH2LG52Z.js";
4
+ import {
5
+ CLI_NAME
6
+ } from "./chunk-DNXE3Q5D.js";
7
+
8
+ // src/auth/vendor/sessionSigner.ts
9
+ import {
10
+ AllowanceExpiredError,
11
+ createSessionSignerForAccount,
12
+ deriveProductPublicKey as sdkDeriveProductPublicKey
13
+ } from "@parity/product-sdk-terminal";
14
+ import { INCOMPLETE_SESSION_MESSAGE, sessionRootPublicKey } from "@parity/product-sdk-terminal";
15
+ var SESSION_EXPIRED_MESSAGE = `Session signing allowance has expired (~2-3 days after login). Run \`${CLI_NAME} logout\`, then \`${CLI_NAME} login\`, to renew (login alone won't refresh a stale session).`;
16
+ var SUBTREE_TIMEOUT_MS = 6e4;
17
+ async function deriveProductPublicKey(session, ref, options) {
18
+ let timer;
19
+ try {
20
+ return await Promise.race([
21
+ sdkDeriveProductPublicKey(session, ref, options),
22
+ new Promise((_, reject) => {
23
+ timer = setTimeout(
24
+ () => reject(new Error(`no reply within ${SUBTREE_TIMEOUT_MS / 1e3}s`)),
25
+ SUBTREE_TIMEOUT_MS
26
+ );
27
+ })
28
+ ]);
29
+ } catch (err) {
30
+ const reason = err instanceof Error ? err.message : String(err);
31
+ throw new NonRetryableError(
32
+ `The phone did not return the account key for "${ref.productId}" (${reason}). Keep the Polkadot app open and check that it is on the same network as this command.`
33
+ );
34
+ } finally {
35
+ clearTimeout(timer);
36
+ }
37
+ }
38
+ async function createSessionSigner(session, ref, options) {
39
+ const signer = await createSessionSignerForAccount(session, ref, options);
40
+ return {
41
+ publicKey: signer.publicKey,
42
+ signTx: withExpiredAllowanceHint(signer.signTx),
43
+ signBytes: withExpiredAllowanceHint(signer.signBytes)
44
+ };
45
+ }
46
+ function withExpiredAllowanceHint(fn) {
47
+ return async (...args) => {
48
+ try {
49
+ return await fn(...args);
50
+ } catch (err) {
51
+ if (err instanceof AllowanceExpiredError) {
52
+ throw new NonRetryableError(SESSION_EXPIRED_MESSAGE);
53
+ }
54
+ throw err;
55
+ }
56
+ };
57
+ }
58
+
59
+ export {
60
+ SESSION_EXPIRED_MESSAGE,
61
+ SUBTREE_TIMEOUT_MS,
62
+ deriveProductPublicKey,
63
+ createSessionSigner,
64
+ INCOMPLETE_SESSION_MESSAGE,
65
+ sessionRootPublicKey
66
+ };
@@ -8,11 +8,11 @@ import {
8
8
  import {
9
9
  isTestnetSpecName,
10
10
  testnetFromNetworkField
11
- } from "./chunk-26ZYMWSC.js";
11
+ } from "./chunk-BDUL42WH.js";
12
12
  import {
13
13
  getWsProvider,
14
14
  parseRpcFrame
15
- } from "./chunk-6GHDPDZN.js";
15
+ } from "./chunk-WYZUDE6I.js";
16
16
  import {
17
17
  HIGHEST_VERIFIED_DOTNS_RELEASE,
18
18
  POP_CONTROLLER_PROBE_ABI,
@@ -27,7 +27,7 @@ import {
27
27
  } from "./chunk-3NR3T7US.js";
28
28
  import {
29
29
  ChainHealthSampler
30
- } from "./chunk-MTXFJTX6.js";
30
+ } from "./chunk-UPENVZ7J.js";
31
31
  import {
32
32
  captureWarning,
33
33
  markCodePath,
@@ -35,13 +35,13 @@ import {
35
35
  setDeploySentryTag,
36
36
  truncateAddress,
37
37
  withSpan
38
- } from "./chunk-YLLTQM5Z.js";
38
+ } from "./chunk-4FIMYLWV.js";
39
39
  import {
40
40
  FALLBACK_MAX_COMMITMENT_AGE_SECONDS,
41
41
  clearCommitmentRecord,
42
42
  loadCommitmentRecord,
43
43
  writeCommitmentRecord
44
- } from "./chunk-3BSPX4JN.js";
44
+ } from "./chunk-7QQZ57E6.js";
45
45
  import {
46
46
  NonRetryableError
47
47
  } from "./chunk-SH2LG52Z.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  captureWarning
3
- } from "./chunk-YLLTQM5Z.js";
3
+ } from "./chunk-4FIMYLWV.js";
4
4
 
5
5
  // src/chunk-probe.ts
6
6
  import { Twox128, Blake2128Concat, decAnyMetadata, unifyMetadata } from "@polkadot-api/substrate-bindings";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-YLLTQM5Z.js";
3
+ } from "./chunk-4FIMYLWV.js";
4
4
 
5
5
  // src/version-check.ts
6
6
  import { execSync, execFileSync } from "child_process";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  BULLETIN_RESOURCE
3
- } from "./chunk-7SXO544V.js";
3
+ } from "./chunk-355BT3NW.js";
4
4
  import {
5
5
  SignerNotAvailableError,
6
6
  resolveSigner
7
7
  } from "./chunk-2C6SLLBI.js";
8
8
  import {
9
9
  DEFAULT_MNEMONIC
10
- } from "./chunk-YIVCOJAB.js";
10
+ } from "./chunk-IOLWREZB.js";
11
11
  import {
12
- DOT_PRODUCT_ID
13
- } from "./chunk-IF3SANQR.js";
12
+ NonRetryableError
13
+ } from "./chunk-SH2LG52Z.js";
14
14
 
15
15
  // src/deploy-actors.ts
16
16
  var DEFAULT_WORKER_SURI = DEFAULT_MNEMONIC;
@@ -29,7 +29,8 @@ async function resolveDeployActors(authClient, { suri, transferEnabled, isTestne
29
29
  let handle = null;
30
30
  try {
31
31
  handle = await authClient.getSessionSigner();
32
- } catch {
32
+ } catch (e) {
33
+ if (e instanceof NonRetryableError) throw e;
33
34
  handle = null;
34
35
  }
35
36
  if (!handle) {
@@ -46,9 +47,9 @@ async function resolveDeployActors(authClient, { suri, transferEnabled, isTestne
46
47
  }
47
48
  async function resolveStorageSigner(session, deps) {
48
49
  if (!session?.userSession || !session?.adapter) return null;
49
- const { userSession, adapter } = session;
50
+ const { userSession, adapter, productId } = session;
50
51
  try {
51
- const signerResult = await deps.getBulletinSigner(userSession.id, DOT_PRODUCT_ID, adapter);
52
+ const signerResult = await deps.getBulletinSigner(userSession.id, productId, adapter);
52
53
  if (signerResult.isOk() && signerResult.value) {
53
54
  const signer = signerResult.value;
54
55
  const slotAddress = deps.ss58Encode(signer.publicKey);
@@ -62,6 +63,7 @@ async function resolveStorageSigner(session, deps) {
62
63
  const outcomes = await deps.requestResourceAllocation(
63
64
  userSession,
64
65
  adapter,
66
+ productId,
65
67
  [BULLETIN_RESOURCE]
66
68
  );
67
69
  const outcome = outcomes[0];
@@ -69,7 +71,7 @@ async function resolveStorageSigner(session, deps) {
69
71
  return null;
70
72
  }
71
73
  if (deps.createSlotAccountSigner) {
72
- const slotSigner = await deps.createSlotAccountSigner(adapter, BULLETIN_RESOURCE);
74
+ const slotSigner = await deps.createSlotAccountSigner(adapter, BULLETIN_RESOURCE, productId);
73
75
  if (slotSigner) {
74
76
  const slotAddress = deps.ss58Encode(slotSigner.publicKey);
75
77
  return { signer: slotSigner, slotAddress, owned: true };
@@ -17,11 +17,21 @@ function sssStorageKey(pubkey) {
17
17
  full.set(pubkey, SSS_PREFIX.length);
18
18
  return "0x" + Buffer.from(full).toString("hex");
19
19
  }
20
- function checkSSSAllowance(pubkey, peopleEndpoints, timeoutMs = 5e3) {
20
+ async function checkSSSAllowance(pubkey, peopleEndpoints, timeoutMs = 5e3) {
21
+ let storageKey;
22
+ try {
23
+ storageKey = sssStorageKey(pubkey);
24
+ } catch {
25
+ return null;
26
+ }
27
+ const value = await readStorageValue(storageKey, peopleEndpoints, timeoutMs);
28
+ return value === void 0 ? null : value !== null;
29
+ }
30
+ function readStorageValue(storageKey, endpoints, timeoutMs = 5e3) {
21
31
  return new Promise((resolve) => {
22
- const endpoint = peopleEndpoints[0];
32
+ const endpoint = endpoints[0];
23
33
  if (!endpoint) {
24
- resolve(null);
34
+ resolve(void 0);
25
35
  return;
26
36
  }
27
37
  let settled = false;
@@ -40,19 +50,12 @@ function checkSSSAllowance(pubkey, peopleEndpoints, timeoutMs = 5e3) {
40
50
  try {
41
51
  ws = new WebSocket(endpoint);
42
52
  } catch {
43
- resolve(null);
53
+ resolve(void 0);
44
54
  return;
45
55
  }
46
- timer = setTimeout(() => done(null), timeoutMs);
47
- ws.on("error", () => done(null));
56
+ timer = setTimeout(() => done(void 0), timeoutMs);
57
+ ws.on("error", () => done(void 0));
48
58
  ws.on("open", () => {
49
- let storageKey;
50
- try {
51
- storageKey = sssStorageKey(pubkey);
52
- } catch {
53
- done(null);
54
- return;
55
- }
56
59
  const request = JSON.stringify({
57
60
  jsonrpc: "2.0",
58
61
  id: 1,
@@ -60,17 +63,15 @@ function checkSSSAllowance(pubkey, peopleEndpoints, timeoutMs = 5e3) {
60
63
  params: [storageKey]
61
64
  });
62
65
  ws.send(request, (err) => {
63
- if (err) done(null);
66
+ if (err) done(void 0);
64
67
  });
65
68
  });
66
69
  ws.on("message", (data) => {
67
70
  try {
68
71
  const msg = JSON.parse(data.toString());
69
- const result = msg.result;
70
- const present = result != null && result !== "0x";
71
- done(present);
72
+ done(msg.result && msg.result !== "0x" ? msg.result : null);
72
73
  } catch {
73
- done(null);
74
+ done(void 0);
74
75
  }
75
76
  });
76
77
  });
@@ -79,5 +80,6 @@ function checkSSSAllowance(pubkey, peopleEndpoints, timeoutMs = 5e3) {
79
80
  export {
80
81
  statementSigningAccount,
81
82
  sssStorageKey,
82
- checkSSSAllowance
83
+ checkSSSAllowance,
84
+ readStorageValue
83
85
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DEFAULT_RESOURCES,
3
3
  requestResourceAllocation
4
- } from "./chunk-7SXO544V.js";
4
+ } from "./chunk-355BT3NW.js";
5
5
  import {
6
6
  createSessionSigner,
7
7
  deriveProductPublicKey,
8
8
  sessionRootPublicKey
9
- } from "./chunk-S6CPT2TU.js";
9
+ } from "./chunk-IMCDXJ4G.js";
10
10
 
11
11
  // src/auth/vendor/auth.ts
12
12
  import { readdir, unlink } from "fs/promises";
@@ -21,6 +21,7 @@ import {
21
21
  var QR_TIMEOUT_MS = 6e4;
22
22
  function createAuthClient(config) {
23
23
  const ref = { productId: config.productId, derivationIndex: config.derivationIndex };
24
+ const subtreeOptions = { appId: config.dappId };
24
25
  function createAdapter() {
25
26
  return createTerminalAdapter({
26
27
  appId: config.dappId,
@@ -33,38 +34,43 @@ function createAuthClient(config) {
33
34
  }
34
35
  });
35
36
  }
36
- function deriveSessionAddresses(session) {
37
+ async function deriveSessionAccount(session) {
37
38
  const rootBytes = sessionRootPublicKey(session);
38
- const productPubkey = deriveProductPublicKey(rootBytes, ref);
39
+ const publicKey = await deriveProductPublicKey(session, ref, subtreeOptions);
39
40
  return {
40
- rootAddress: ss58Encode(rootBytes),
41
- productAddress: ss58Encode(productPubkey),
42
- productH160: deriveH160(productPubkey)
41
+ publicKey,
42
+ addresses: {
43
+ rootAddress: ss58Encode(rootBytes),
44
+ productAddress: ss58Encode(publicKey),
45
+ productH160: deriveH160(publicKey)
46
+ }
43
47
  };
44
48
  }
45
- function createSigner(session) {
46
- return createSessionSigner(session, ref);
47
- }
48
49
  function sessionRemoteAddress(session) {
49
50
  const raw = session.remoteAccount?.accountId;
50
51
  const accountId = raw ? new Uint8Array(raw) : new Uint8Array();
51
52
  return accountId.length === 32 ? ss58Encode(accountId) : null;
52
53
  }
53
- function sessionLogoutAddress(session) {
54
+ async function sessionLogoutAddress(session) {
55
+ const fallback = sessionRemoteAddress(session) ?? "(stored session)";
56
+ const timeout = new Promise((resolve) => setTimeout(() => resolve(fallback), 5e3).unref());
54
57
  try {
55
- return deriveSessionAddresses(session).productAddress;
58
+ return await Promise.race([deriveSessionAccount(session).then((a) => a.addresses.productAddress), timeout]);
56
59
  } catch {
57
- return sessionRemoteAddress(session) ?? "(stored session)";
60
+ return fallback;
58
61
  }
59
62
  }
60
63
  async function connect() {
61
64
  const adapter = createAdapter();
62
65
  const sessions = await waitForSessions(adapter);
63
66
  if (sessions.length > 0) {
64
- const addresses = deriveSessionAddresses(sessions[0]);
65
- adapter.destroy().catch(() => {
66
- });
67
- return { kind: "existing", address: addresses.productAddress, addresses };
67
+ try {
68
+ const { addresses } = await deriveSessionAccount(sessions[0]);
69
+ return { kind: "existing", address: addresses.productAddress, addresses };
70
+ } finally {
71
+ adapter.destroy().catch(() => {
72
+ });
73
+ }
68
74
  }
69
75
  const authPromise = adapter.sso.authenticate();
70
76
  try {
@@ -128,9 +134,16 @@ function createAuthClient(config) {
128
134
  if (authenticated) {
129
135
  const sessions = await waitForSessions(adapter, 3e3);
130
136
  if (sessions.length > 0) {
131
- handle = buildSessionHandle(adapter, sessions[0]);
132
- const { address, addresses } = handle;
133
- onStatus({ step: "success", address, addresses });
137
+ try {
138
+ handle = await buildSessionHandle(adapter, sessions[0]);
139
+ const { address, addresses } = handle;
140
+ onStatus({ step: "success", address, addresses });
141
+ } catch (err) {
142
+ await Promise.resolve(adapter.sessions.disconnect(sessions[0])).catch(() => {
143
+ });
144
+ await clearLocalAppStorage();
145
+ onStatus({ step: "error", message: err instanceof Error ? err.message : String(err) });
146
+ }
134
147
  } else {
135
148
  onStatus({
136
149
  step: "error",
@@ -143,9 +156,9 @@ function createAuthClient(config) {
143
156
  }
144
157
  return handle;
145
158
  }
146
- function buildSessionHandle(adapter, session) {
147
- const signer = createSigner(session);
148
- const addresses = deriveSessionAddresses(session);
159
+ async function buildSessionHandle(adapter, session) {
160
+ const { publicKey, addresses } = await deriveSessionAccount(session);
161
+ const signer = await createSessionSigner(session, { ...ref, publicKey }, subtreeOptions);
149
162
  let destroyed = false;
150
163
  const destroy = () => {
151
164
  if (destroyed) return;
@@ -156,6 +169,7 @@ function createAuthClient(config) {
156
169
  return {
157
170
  address: addresses.productAddress,
158
171
  addresses,
172
+ productId: config.productId,
159
173
  signer,
160
174
  userSession: session,
161
175
  adapter,
@@ -170,10 +184,16 @@ function createAuthClient(config) {
170
184
  });
171
185
  return null;
172
186
  }
173
- return buildSessionHandle(adapter, sessions[0]);
187
+ try {
188
+ return await buildSessionHandle(adapter, sessions[0]);
189
+ } catch (err) {
190
+ adapter.destroy().catch(() => {
191
+ });
192
+ throw err;
193
+ }
174
194
  }
175
195
  async function requestAllocation(session, adapter, resources = DEFAULT_RESOURCES, onExisting = "Ignore") {
176
- return requestResourceAllocation(session, adapter, resources, onExisting);
196
+ return requestResourceAllocation(session, adapter, config.productId, resources, onExisting);
177
197
  }
178
198
  async function findSession() {
179
199
  const adapter = createAdapter();
@@ -186,7 +206,7 @@ function createAuthClient(config) {
186
206
  return null;
187
207
  }
188
208
  const session = sessions[0];
189
- const address = sessionLogoutAddress(session);
209
+ const address = await sessionLogoutAddress(session);
190
210
  return { adapter, address, session };
191
211
  }
192
212
  async function waitForLogout(handle, onStatus) {
@@ -227,9 +247,9 @@ function createAuthClient(config) {
227
247
  } catch {
228
248
  return;
229
249
  }
230
- const prefix = `${config.dappId}_`;
250
+ const prefixes = [`${config.dappId}_`, `${config.dappId}.`];
231
251
  await Promise.all(
232
- entries.filter((entry) => entry.isFile() && entry.name.startsWith(prefix)).map(
252
+ entries.filter((entry) => entry.isFile() && prefixes.some((p) => entry.name.startsWith(p))).map(
233
253
  (entry) => unlink(join(dir, entry.name)).catch(() => {
234
254
  })
235
255
  )
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  emitIntervalSpan,
3
3
  setDeployAttribute
4
- } from "./chunk-YLLTQM5Z.js";
4
+ } from "./chunk-4FIMYLWV.js";
5
5
 
6
6
  // src/chain-health.ts
7
7
  var DEFAULT_WINDOW_BLOCKS = 10;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  endpointHost
3
- } from "./chunk-MTXFJTX6.js";
3
+ } from "./chunk-UPENVZ7J.js";
4
4
  import {
5
5
  captureWarning
6
- } from "./chunk-YLLTQM5Z.js";
6
+ } from "./chunk-4FIMYLWV.js";
7
7
 
8
8
  // src/ws.ts
9
9
  import { getWsProvider as papiGetWsProvider } from "polkadot-api/ws";
@@ -9,9 +9,9 @@ import {
9
9
  getBestBlockNumber,
10
10
  probeChunks,
11
11
  probeFinalityGap
12
- } from "./chunk-DHHHYZTR.js";
13
- import "./chunk-YLLTQM5Z.js";
14
- import "./chunk-3BSPX4JN.js";
12
+ } from "./chunk-K57H4IRT.js";
13
+ import "./chunk-4FIMYLWV.js";
14
+ import "./chunk-7QQZ57E6.js";
15
15
  import "./chunk-SH2LG52Z.js";
16
16
  export {
17
17
  ChainProbeCrossValidationError,
@@ -1,6 +1,7 @@
1
1
  import { AllocationSummary } from '../auth/vendor/allocations.js';
2
2
  import 'polkadot-api';
3
3
  import '@parity/product-sdk-terminal';
4
+ import '@parity/product-sdk-terminal/host';
4
5
 
5
6
  /**
6
7
  * login — QR/mobile sign-in command.