@restatedev/restate-sdk 1.18.1 → 1.18.3

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 (36) hide show
  1. package/README.md +1 -0
  2. package/dist/common_api.d.cts.map +1 -1
  3. package/dist/common_api.d.ts.map +1 -1
  4. package/dist/context.d.cts +24 -0
  5. package/dist/context.d.cts.map +1 -1
  6. package/dist/context.d.ts +24 -0
  7. package/dist/context.d.ts.map +1 -1
  8. package/dist/context.js.map +1 -1
  9. package/dist/context_impl.cjs +23 -8
  10. package/dist/context_impl.js +24 -9
  11. package/dist/context_impl.js.map +1 -1
  12. package/dist/endpoint/connect/env.cjs +24 -22
  13. package/dist/endpoint/connect/env.js +24 -22
  14. package/dist/endpoint/connect/env.js.map +1 -1
  15. package/dist/endpoint/connect/key.cjs +41 -32
  16. package/dist/endpoint/connect/key.js +41 -32
  17. package/dist/endpoint/connect/key.js.map +1 -1
  18. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.cjs +10 -25
  19. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +10 -25
  20. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
  21. package/dist/endpoint/tunnel/types.d.cts +2 -3
  22. package/dist/endpoint/tunnel/types.d.cts.map +1 -1
  23. package/dist/endpoint/tunnel/types.d.ts +2 -3
  24. package/dist/endpoint/tunnel/types.d.ts.map +1 -1
  25. package/dist/package.cjs +1 -1
  26. package/dist/package.js +1 -1
  27. package/dist/package.js.map +1 -1
  28. package/dist/types/errors.cjs +2 -0
  29. package/dist/types/errors.d.cts +9 -0
  30. package/dist/types/errors.d.cts.map +1 -1
  31. package/dist/types/errors.d.ts +9 -0
  32. package/dist/types/errors.d.ts.map +1 -1
  33. package/dist/types/errors.js +2 -0
  34. package/dist/types/errors.js.map +1 -1
  35. package/dist/types/rpc.d.cts.map +1 -1
  36. package/package.json +2 -2
@@ -1,11 +1,14 @@
1
1
 
2
2
  //#region src/endpoint/connect/key.ts
3
- const BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;
4
- const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
3
+ /** The prefix every Restate Cloud key starts with. */
4
+ const CLOUD_KEY_PREFIX = "rstcloudv1_";
5
+ /** The shape shown in errors. */
6
+ const CLOUD_KEY_SHAPE = `${CLOUD_KEY_PREFIX}<base58>`;
7
+ const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
5
8
  /**
6
- * Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region
7
- * domain>/?…`). Throws an `Error` whose message starts with `what` (the variable
8
- * or option the value came from) when the string does not follow the grammar;
9
+ * Parse a Restate Cloud key (`rstcloudv1_<base58>`) into its query parameters,
10
+ * in order. Throws an `Error` whose message starts with `what` (the variable
11
+ * or option the value came from) when the string does not follow the format;
9
12
  * the message says what is wrong, shows the expected shape and links `help`.
10
13
  *
11
14
  * @param value the key string
@@ -14,39 +17,45 @@ const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
14
17
  */
15
18
  function parseCloudKey(value, what, help) {
16
19
  const fail = (reason) => {
17
- throw new Error(`${what} is not a Restate Cloud key (${reason}); expected restate://<api key>@<environment id>.env.<region domain>/ — copy it again from ${help}`);
20
+ throw new Error(`${what} is not a Restate Cloud key (${reason}); expected ${CLOUD_KEY_SHAPE} — copy it again from ${help}`);
18
21
  };
19
- let url;
22
+ const trimmed = value.trim();
23
+ if (!trimmed.startsWith(CLOUD_KEY_PREFIX)) return fail(`it does not start with ${CLOUD_KEY_PREFIX}`);
24
+ const encoded = trimmed.slice(11);
25
+ const corrupted = () => fail("it is truncated or corrupted");
26
+ if (encoded === "") return corrupted();
27
+ let query;
20
28
  try {
21
- url = new URL(value.trim());
29
+ query = new TextDecoder("utf-8", { fatal: true }).decode(base58Decode(encoded));
22
30
  } catch {
23
- return fail("not a URL");
31
+ return corrupted();
24
32
  }
25
- if (url.protocol !== "restate:") return fail(`the scheme is ${JSON.stringify(url.protocol.replace(/:$/, ""))}, not restate`);
26
- if (url.port !== "") return fail("the host must not carry a port");
27
- if (url.pathname !== "" && url.pathname !== "/") return fail("the path must be empty");
28
- if (url.hash !== "") return fail("a fragment is not allowed");
29
- const host = url.hostname.toLowerCase();
30
- const marker = host.indexOf(".env.");
31
- const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : "";
32
- const regionDomain = marker > 0 ? host.slice(marker + 5) : "";
33
- if (!BARE_ENVIRONMENT_ID.test(bareEnvironmentId) || bareEnvironmentId.startsWith("env_") || !DOMAIN.test(regionDomain)) return fail("the host must be <environment id>.env.<region domain>");
34
- let apiKey;
35
- if (url.username !== "" || url.password !== "") {
36
- const raw = url.password === "" ? url.username : `${url.username}:${url.password}`;
37
- try {
38
- apiKey = decodeURIComponent(raw);
39
- } catch {
40
- return fail("the API key is not valid percent-encoding");
33
+ if (!/^[\x21-\x7e]+$/.test(query)) return corrupted();
34
+ const params = [...new URLSearchParams(query).entries()];
35
+ if (params.some(([name]) => name === "")) return corrupted();
36
+ return params;
37
+ }
38
+ /** Decode base58 (Bitcoin alphabet); throws on a character outside it. */
39
+ function base58Decode(text) {
40
+ const digits = [];
41
+ for (const char of text) {
42
+ let carry = BASE58_ALPHABET.indexOf(char);
43
+ if (carry < 0) throw new Error(`not base58: ${JSON.stringify(char)}`);
44
+ for (let i = 0; i < digits.length; i++) {
45
+ carry += digits[i] * 58;
46
+ digits[i] = carry & 255;
47
+ carry >>= 8;
48
+ }
49
+ while (carry > 0) {
50
+ digits.push(carry & 255);
51
+ carry >>= 8;
41
52
  }
42
53
  }
43
- return {
44
- apiKey,
45
- host,
46
- environmentId: `env_${bareEnvironmentId}`,
47
- regionDomain,
48
- params: [...url.searchParams.entries()]
49
- };
54
+ let zeros = 0;
55
+ while (zeros < text.length && text[zeros] === "1") zeros++;
56
+ const out = new Uint8Array(zeros + digits.length);
57
+ for (let i = 0; i < digits.length; i++) out[zeros + i] = digits[digits.length - 1 - i];
58
+ return out;
50
59
  }
51
60
 
52
61
  //#endregion
@@ -1,10 +1,13 @@
1
1
  //#region src/endpoint/connect/key.ts
2
- const BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;
3
- const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
2
+ /** The prefix every Restate Cloud key starts with. */
3
+ const CLOUD_KEY_PREFIX = "rstcloudv1_";
4
+ /** The shape shown in errors. */
5
+ const CLOUD_KEY_SHAPE = `${CLOUD_KEY_PREFIX}<base58>`;
6
+ const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
4
7
  /**
5
- * Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region
6
- * domain>/?…`). Throws an `Error` whose message starts with `what` (the variable
7
- * or option the value came from) when the string does not follow the grammar;
8
+ * Parse a Restate Cloud key (`rstcloudv1_<base58>`) into its query parameters,
9
+ * in order. Throws an `Error` whose message starts with `what` (the variable
10
+ * or option the value came from) when the string does not follow the format;
8
11
  * the message says what is wrong, shows the expected shape and links `help`.
9
12
  *
10
13
  * @param value the key string
@@ -13,39 +16,45 @@ const DOMAIN = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
13
16
  */
14
17
  function parseCloudKey(value, what, help) {
15
18
  const fail = (reason) => {
16
- throw new Error(`${what} is not a Restate Cloud key (${reason}); expected restate://<api key>@<environment id>.env.<region domain>/ — copy it again from ${help}`);
19
+ throw new Error(`${what} is not a Restate Cloud key (${reason}); expected ${CLOUD_KEY_SHAPE} — copy it again from ${help}`);
17
20
  };
18
- let url;
21
+ const trimmed = value.trim();
22
+ if (!trimmed.startsWith(CLOUD_KEY_PREFIX)) return fail(`it does not start with ${CLOUD_KEY_PREFIX}`);
23
+ const encoded = trimmed.slice(11);
24
+ const corrupted = () => fail("it is truncated or corrupted");
25
+ if (encoded === "") return corrupted();
26
+ let query;
19
27
  try {
20
- url = new URL(value.trim());
28
+ query = new TextDecoder("utf-8", { fatal: true }).decode(base58Decode(encoded));
21
29
  } catch {
22
- return fail("not a URL");
30
+ return corrupted();
23
31
  }
24
- if (url.protocol !== "restate:") return fail(`the scheme is ${JSON.stringify(url.protocol.replace(/:$/, ""))}, not restate`);
25
- if (url.port !== "") return fail("the host must not carry a port");
26
- if (url.pathname !== "" && url.pathname !== "/") return fail("the path must be empty");
27
- if (url.hash !== "") return fail("a fragment is not allowed");
28
- const host = url.hostname.toLowerCase();
29
- const marker = host.indexOf(".env.");
30
- const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : "";
31
- const regionDomain = marker > 0 ? host.slice(marker + 5) : "";
32
- if (!BARE_ENVIRONMENT_ID.test(bareEnvironmentId) || bareEnvironmentId.startsWith("env_") || !DOMAIN.test(regionDomain)) return fail("the host must be <environment id>.env.<region domain>");
33
- let apiKey;
34
- if (url.username !== "" || url.password !== "") {
35
- const raw = url.password === "" ? url.username : `${url.username}:${url.password}`;
36
- try {
37
- apiKey = decodeURIComponent(raw);
38
- } catch {
39
- return fail("the API key is not valid percent-encoding");
32
+ if (!/^[\x21-\x7e]+$/.test(query)) return corrupted();
33
+ const params = [...new URLSearchParams(query).entries()];
34
+ if (params.some(([name]) => name === "")) return corrupted();
35
+ return params;
36
+ }
37
+ /** Decode base58 (Bitcoin alphabet); throws on a character outside it. */
38
+ function base58Decode(text) {
39
+ const digits = [];
40
+ for (const char of text) {
41
+ let carry = BASE58_ALPHABET.indexOf(char);
42
+ if (carry < 0) throw new Error(`not base58: ${JSON.stringify(char)}`);
43
+ for (let i = 0; i < digits.length; i++) {
44
+ carry += digits[i] * 58;
45
+ digits[i] = carry & 255;
46
+ carry >>= 8;
47
+ }
48
+ while (carry > 0) {
49
+ digits.push(carry & 255);
50
+ carry >>= 8;
40
51
  }
41
52
  }
42
- return {
43
- apiKey,
44
- host,
45
- environmentId: `env_${bareEnvironmentId}`,
46
- regionDomain,
47
- params: [...url.searchParams.entries()]
48
- };
53
+ let zeros = 0;
54
+ while (zeros < text.length && text[zeros] === "1") zeros++;
55
+ const out = new Uint8Array(zeros + digits.length);
56
+ for (let i = 0; i < digits.length; i++) out[zeros + i] = digits[digits.length - 1 - i];
57
+ return out;
49
58
  }
50
59
 
51
60
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"key.js","names":["url: URL","apiKey: string | undefined"],"sources":["../../../src/endpoint/connect/key.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n// The Restate Cloud key grammar (`RESTATE_CONNECT_KEY`; `RESTATE_INGRESS_KEY`\n// in @restatedev/restate-sdk-clients shares it, with its own trimmed parser):\n//\n// restate://<api key>@<bare environment id>.env.<region domain>/?<params>\n//\n// URL-shaped on purpose: standard-library parsers everywhere, the secret in\n// the userinfo slot that log redactors already mask, and query parameters for\n// forward-compatible extras. The host is the environment's own hostname, so\n// the environment id (`env_` + first label), the region domain (after\n// `.env.`) and the ingress URL (`https://<host>:8080`) all derive from it.\n\n/** A parsed Restate Cloud key, see {@link parseCloudKey}. */\nexport interface CloudKey {\n /** The API key from the userinfo slot, `undefined` when the key has none. */\n apiKey: string | undefined;\n /** `<bare environment id>.env.<region domain>`: the environment's hostname. */\n host: string;\n /** The environment id, `env_` + the host's first label. */\n environmentId: string;\n /** The part of the host after `.env.` (e.g. `eu.restate.cloud`). */\n regionDomain: string;\n /** The query parameters, in order; the caller decides which ones it knows. */\n params: Array<[name: string, value: string]>;\n}\n\nconst BARE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]+$/;\nconst DOMAIN = /^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/;\n\n/**\n * Parse a Restate Cloud key (`restate://<api key>@<environment id>.env.<region\n * domain>/?…`). Throws an `Error` whose message starts with `what` (the variable\n * or option the value came from) when the string does not follow the grammar;\n * the message says what is wrong, shows the expected shape and links `help`.\n *\n * @param value the key string\n * @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`\n * @param help where to get a fresh key, linked in every error\n */\nexport function parseCloudKey(\n value: string,\n what: string,\n help: string\n): CloudKey {\n // Reasons never echo parts of the value: a key pasted with a lost `@` or a\n // stray `/` would otherwise put the credential in the error message.\n const fail = (reason: string): never => {\n throw new Error(\n `${what} is not a Restate Cloud key (${reason}); expected restate://<api key>@<environment id>.env.<region domain>/ — copy it again from ${help}`\n );\n };\n let url: URL;\n try {\n url = new URL(value.trim());\n } catch {\n return fail(\"not a URL\");\n }\n if (url.protocol !== \"restate:\") {\n return fail(\n `the scheme is ${JSON.stringify(url.protocol.replace(/:$/, \"\"))}, not restate`\n );\n }\n if (url.port !== \"\") return fail(\"the host must not carry a port\");\n // The path is not echoed: a key pasted with a stray `/` would put part of\n // the credential in the error message.\n if (url.pathname !== \"\" && url.pathname !== \"/\") {\n return fail(\"the path must be empty\");\n }\n if (url.hash !== \"\") return fail(\"a fragment is not allowed\");\n\n // Hosts are case-insensitive; a non-special scheme keeps the pasted case.\n const host = url.hostname.toLowerCase();\n const marker = host.indexOf(\".env.\");\n const bareEnvironmentId = marker > 0 ? host.slice(0, marker) : \"\";\n const regionDomain = marker > 0 ? host.slice(marker + \".env.\".length) : \"\";\n if (\n !BARE_ENVIRONMENT_ID.test(bareEnvironmentId) ||\n bareEnvironmentId.startsWith(\"env_\") ||\n !DOMAIN.test(regionDomain)\n ) {\n return fail(\"the host must be <environment id>.env.<region domain>\");\n }\n\n // The userinfo slot: `username[:password]`, percent-decoded. API keys carry\n // no `:` today, but a key is opaque to us, so a password part is re-joined.\n let apiKey: string | undefined;\n if (url.username !== \"\" || url.password !== \"\") {\n const raw =\n url.password === \"\" ? url.username : `${url.username}:${url.password}`;\n try {\n apiKey = decodeURIComponent(raw);\n } catch {\n return fail(\"the API key is not valid percent-encoding\");\n }\n }\n\n return {\n apiKey,\n host,\n environmentId: `env_${bareEnvironmentId}`,\n regionDomain,\n params: [...url.searchParams.entries()],\n };\n}\n"],"mappings":";AAoCA,MAAM,sBAAsB;AAC5B,MAAM,SAAS;;;;;;;;;;;AAYf,SAAgB,cACd,OACA,MACA,MACU;CAGV,MAAM,QAAQ,WAA0B;AACtC,QAAM,IAAI,MACR,GAAG,KAAK,+BAA+B,OAAO,6FAA6F,OAC5I;;CAEH,IAAIA;AACJ,KAAI;AACF,QAAM,IAAI,IAAI,MAAM,MAAM,CAAC;SACrB;AACN,SAAO,KAAK,YAAY;;AAE1B,KAAI,IAAI,aAAa,WACnB,QAAO,KACL,iBAAiB,KAAK,UAAU,IAAI,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,eACjE;AAEH,KAAI,IAAI,SAAS,GAAI,QAAO,KAAK,iCAAiC;AAGlE,KAAI,IAAI,aAAa,MAAM,IAAI,aAAa,IAC1C,QAAO,KAAK,yBAAyB;AAEvC,KAAI,IAAI,SAAS,GAAI,QAAO,KAAK,4BAA4B;CAG7D,MAAM,OAAO,IAAI,SAAS,aAAa;CACvC,MAAM,SAAS,KAAK,QAAQ,QAAQ;CACpC,MAAM,oBAAoB,SAAS,IAAI,KAAK,MAAM,GAAG,OAAO,GAAG;CAC/D,MAAM,eAAe,SAAS,IAAI,KAAK,MAAM,SAAS,EAAe,GAAG;AACxE,KACE,CAAC,oBAAoB,KAAK,kBAAkB,IAC5C,kBAAkB,WAAW,OAAO,IACpC,CAAC,OAAO,KAAK,aAAa,CAE1B,QAAO,KAAK,wDAAwD;CAKtE,IAAIC;AACJ,KAAI,IAAI,aAAa,MAAM,IAAI,aAAa,IAAI;EAC9C,MAAM,MACJ,IAAI,aAAa,KAAK,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI;AAC9D,MAAI;AACF,YAAS,mBAAmB,IAAI;UAC1B;AACN,UAAO,KAAK,4CAA4C;;;AAI5D,QAAO;EACL;EACA;EACA,eAAe,OAAO;EACtB;EACA,QAAQ,CAAC,GAAG,IAAI,aAAa,SAAS,CAAC;EACxC"}
1
+ {"version":3,"file":"key.js","names":["query: string","digits: number[]"],"sources":["../../../src/endpoint/connect/key.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2026 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\n// INTERNAL: the Restate Cloud key format. To users the key is opaque: public\n// docs and error messages only ever say \"copy it again from the Cloud UI\";\n// this comment is the one place in restate-sdk that spells the format out\n// (`RESTATE_INGRESS_KEY` in @restatedev/restate-sdk-clients shares it, with\n// its own trimmed parser).\n//\n// rstcloudv1_<base58>\n//\n// The base58 part (Bitcoin alphabet, no padding) encodes a UTF-8 query string\n// (`application/x-www-form-urlencoded`), for a connect key\n//\n// envid=env_201k…&apikey=key_01abc.5Kd…&region=eu.restate.cloud&signingkey=publickeyv1_…\n//\n// and for an ingress key the same without `signingkey`. Every value is made\n// of unreserved characters, so nothing in it is percent-encoded. One opaque\n// word: a double click selects it, every shell and secret store copies it\n// intact, and expanding it takes one line anywhere\n// (`new URLSearchParams(utf8(base58decode(rest)))`). The caller decides which\n// parameters it knows; the only derivations are the tunnel SRV name\n// (`tunnel.<region>`) and the ingress URL\n// (`https://<envid minus env_>.env.<region>:8080`).\n\n/** The prefix every Restate Cloud key starts with. */\nexport const CLOUD_KEY_PREFIX = \"rstcloudv1_\";\n\n/** The shape shown in errors. */\nexport const CLOUD_KEY_SHAPE = `${CLOUD_KEY_PREFIX}<base58>`;\n\nconst BASE58_ALPHABET =\n \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n\n/**\n * Parse a Restate Cloud key (`rstcloudv1_<base58>`) into its query parameters,\n * in order. Throws an `Error` whose message starts with `what` (the variable\n * or option the value came from) when the string does not follow the format;\n * the message says what is wrong, shows the expected shape and links `help`.\n *\n * @param value the key string\n * @param what how to call the value in errors, e.g. `RESTATE_CONNECT_KEY`\n * @param help where to get a fresh key, linked in every error\n */\nexport function parseCloudKey(\n value: string,\n what: string,\n help: string\n): Array<[name: string, value: string]> {\n // Reasons never echo parts of the value (the whole thing is a credential)\n // and never describe the encoding: a user only needs to know whether they\n // pasted something else or lost part of the key.\n const fail = (reason: string): never => {\n throw new Error(\n `${what} is not a Restate Cloud key (${reason}); expected ${CLOUD_KEY_SHAPE} — copy it again from ${help}`\n );\n };\n const trimmed = value.trim();\n if (!trimmed.startsWith(CLOUD_KEY_PREFIX)) {\n return fail(`it does not start with ${CLOUD_KEY_PREFIX}`);\n }\n const encoded = trimmed.slice(CLOUD_KEY_PREFIX.length);\n const corrupted = () => fail(\"it is truncated or corrupted\");\n if (encoded === \"\") return corrupted();\n let query: string;\n try {\n query = new TextDecoder(\"utf-8\", { fatal: true }).decode(\n base58Decode(encoded)\n );\n } catch {\n return corrupted();\n }\n // `URLSearchParams` accepts anything; demand the shape we produce: printable\n // ASCII, non-empty, every entry with a name.\n if (!/^[\\x21-\\x7e]+$/.test(query)) return corrupted();\n const params = [...new URLSearchParams(query).entries()];\n if (params.some(([name]) => name === \"\")) return corrupted();\n return params;\n}\n\n/** Decode base58 (Bitcoin alphabet); throws on a character outside it. */\nfunction base58Decode(text: string): Uint8Array {\n // Little-endian base-256 digits, multiplied up one base58 digit at a time.\n const digits: number[] = [];\n for (const char of text) {\n let carry = BASE58_ALPHABET.indexOf(char);\n if (carry < 0) throw new Error(`not base58: ${JSON.stringify(char)}`);\n for (let i = 0; i < digits.length; i++) {\n carry += digits[i]! * 58;\n digits[i] = carry & 0xff;\n carry >>= 8;\n }\n while (carry > 0) {\n digits.push(carry & 0xff);\n carry >>= 8;\n }\n }\n // Each leading `1` is a leading zero byte.\n let zeros = 0;\n while (zeros < text.length && text[zeros] === \"1\") zeros++;\n const out = new Uint8Array(zeros + digits.length);\n for (let i = 0; i < digits.length; i++) {\n out[zeros + i] = digits[digits.length - 1 - i]!;\n }\n return out;\n}\n"],"mappings":";;AAkCA,MAAa,mBAAmB;;AAGhC,MAAa,kBAAkB,GAAG,iBAAiB;AAEnD,MAAM,kBACJ;;;;;;;;;;;AAYF,SAAgB,cACd,OACA,MACA,MACsC;CAItC,MAAM,QAAQ,WAA0B;AACtC,QAAM,IAAI,MACR,GAAG,KAAK,+BAA+B,OAAO,cAAc,gBAAgB,wBAAwB,OACrG;;CAEH,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,CAAC,QAAQ,WAAW,iBAAiB,CACvC,QAAO,KAAK,0BAA0B,mBAAmB;CAE3D,MAAM,UAAU,QAAQ,MAAM,GAAwB;CACtD,MAAM,kBAAkB,KAAK,+BAA+B;AAC5D,KAAI,YAAY,GAAI,QAAO,WAAW;CACtC,IAAIA;AACJ,KAAI;AACF,UAAQ,IAAI,YAAY,SAAS,EAAE,OAAO,MAAM,CAAC,CAAC,OAChD,aAAa,QAAQ,CACtB;SACK;AACN,SAAO,WAAW;;AAIpB,KAAI,CAAC,iBAAiB,KAAK,MAAM,CAAE,QAAO,WAAW;CACrD,MAAM,SAAS,CAAC,GAAG,IAAI,gBAAgB,MAAM,CAAC,SAAS,CAAC;AACxD,KAAI,OAAO,MAAM,CAAC,UAAU,SAAS,GAAG,CAAE,QAAO,WAAW;AAC5D,QAAO;;;AAIT,SAAS,aAAa,MAA0B;CAE9C,MAAMC,SAAmB,EAAE;AAC3B,MAAK,MAAM,QAAQ,MAAM;EACvB,IAAI,QAAQ,gBAAgB,QAAQ,KAAK;AACzC,MAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,eAAe,KAAK,UAAU,KAAK,GAAG;AACrE,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,YAAS,OAAO,KAAM;AACtB,UAAO,KAAK,QAAQ;AACpB,aAAU;;AAEZ,SAAO,QAAQ,GAAG;AAChB,UAAO,KAAK,QAAQ,IAAK;AACzB,aAAU;;;CAId,IAAI,QAAQ;AACZ,QAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,IAAK;CACnD,MAAM,MAAM,IAAI,WAAW,QAAQ,OAAO,OAAO;AACjD,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,QAAQ,KAAK,OAAO,OAAO,SAAS,IAAI;AAE9C,QAAO"}