@poe-platform/safe-js 0.1.361 → 0.1.363

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-UPTA6E3T.js";
30
+ } from "./chunk-OTFEHCGJ.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-MGIF45X7.js.map
8252
+ //# sourceMappingURL=chunk-ADA4LH5C.js.map
@@ -6995,6 +6995,11 @@ function copyTypedArrayStorage(value, state) {
6995
6995
  }
6996
6996
  return new storage.Native(buffer, storage.byteOffset, storage.length);
6997
6997
  }
6998
+ function requireUint8Array(value) {
6999
+ if (!isNumericTypedArray(value) || typedArrayStorage(value).Native !== Uint8Array)
7000
+ throw new TypeError("Conversion requires a Uint8Array receiver.");
7001
+ return value;
7002
+ }
6998
7003
 
6999
7004
  // packages/safe-js/src/interp/date.ts
7000
7005
  import { types as types3 } from "node:util";
@@ -14638,6 +14643,272 @@ async function callSetMethod(target, methodName, args, options, stack = []) {
14638
14643
  }
14639
14644
  }
14640
14645
 
14646
+ // packages/safe-js/src/interp/globals/uint8-hex.ts
14647
+ var hexDigits = "0123456789abcdef";
14648
+ function installUint8Hex(budget, constructor, prototype) {
14649
+ const fromHex = createSandboxClosure({
14650
+ guest: true,
14651
+ sandbox: true,
14652
+ name: "fromHex",
14653
+ length: 1,
14654
+ call: ([text]) => {
14655
+ if (typeof text !== "string") throw new TypeError("Hex input must be a string.");
14656
+ if (text.length % 2 !== 0) throw new SyntaxError("Hex input must have an even length.");
14657
+ checkTypedArrayAllocation(text.length / 2, budget, 1);
14658
+ const value = new Uint8Array(text.length / 2);
14659
+ decodeHexInto(text, value, budget);
14660
+ setSandboxPrototype(value, prototype, budget);
14661
+ return value;
14662
+ }
14663
+ });
14664
+ Object.defineProperty(materializeFunctionProperties(constructor), "fromHex", {
14665
+ value: fromHex,
14666
+ writable: true,
14667
+ configurable: true
14668
+ });
14669
+ registerIntrinsicFunction(budget, fromHex);
14670
+ Object.defineProperties(prototype, {
14671
+ toHex: {
14672
+ writable: true,
14673
+ configurable: true,
14674
+ value: createSandboxClosure({
14675
+ guest: true,
14676
+ sandbox: true,
14677
+ name: "toHex",
14678
+ length: 0,
14679
+ call: (_args, context) => {
14680
+ const value = requireUint8Array(context?.thisValue);
14681
+ const { length } = typedArrayStorage(value, true);
14682
+ budget.provisionDataUsage(length * 2)();
14683
+ let result = "";
14684
+ for (let index = 0; index < length; index++) {
14685
+ budget.visitNode();
14686
+ const byte = value[index];
14687
+ result = budget.allocateString(result + hexDigits[byte >> 4] + hexDigits[byte & 15]);
14688
+ }
14689
+ return result;
14690
+ }
14691
+ })
14692
+ },
14693
+ setFromHex: {
14694
+ writable: true,
14695
+ configurable: true,
14696
+ value: createSandboxClosure({
14697
+ guest: true,
14698
+ sandbox: true,
14699
+ name: "setFromHex",
14700
+ length: 1,
14701
+ call: ([text], context) => {
14702
+ const value = requireUint8Array(context?.thisValue);
14703
+ if (typeof text !== "string") throw new TypeError("Hex input must be a string.");
14704
+ typedArrayStorage(value, true);
14705
+ const written = decodeHexInto(text, value, budget);
14706
+ return { read: written * 2, written };
14707
+ }
14708
+ })
14709
+ }
14710
+ });
14711
+ }
14712
+ function decodeHexInto(text, value, budget) {
14713
+ if (text.length % 2 !== 0) throw new SyntaxError("Hex input must have an even length.");
14714
+ const length = Math.min(text.length / 2, typedArrayStorage(value).length);
14715
+ for (let index = 0; index < length; index++) {
14716
+ budget.visitNode();
14717
+ const high = hexNibble(text.charCodeAt(index * 2));
14718
+ const low = hexNibble(text.charCodeAt(index * 2 + 1));
14719
+ if (high < 0 || low < 0) throw new SyntaxError("Invalid hexadecimal digit.");
14720
+ value[index] = high * 16 + low;
14721
+ }
14722
+ return length;
14723
+ }
14724
+ function hexNibble(code) {
14725
+ if (code >= 48 && code <= 57) return code - 48;
14726
+ if (code >= 65 && code <= 70) return code - 55;
14727
+ if (code >= 97 && code <= 102) return code - 87;
14728
+ return -1;
14729
+ }
14730
+
14731
+ // packages/safe-js/src/interp/globals/uint8-base64.ts
14732
+ var alphabets = {
14733
+ base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
14734
+ base64url: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
14735
+ };
14736
+ function installUint8Base64(budget, constructor, prototype) {
14737
+ const fromBase64 = createSandboxClosure({
14738
+ guest: true,
14739
+ sandbox: true,
14740
+ name: "fromBase64",
14741
+ length: 1,
14742
+ call: async ([text, options], context) => {
14743
+ if (typeof text !== "string") throw new TypeError("Base64 input must be a string.");
14744
+ const release = retainValues(budget, () => [text, options]);
14745
+ try {
14746
+ const { alphabet, mode } = await base64Options(options, false, budget, context);
14747
+ const result = decodeBase64(text, alphabet, mode, budget);
14748
+ if (result.error !== void 0) throw result.error;
14749
+ budget.provisionDataUsage(result.bytes.length * 2 + 3)();
14750
+ const value = new Uint8Array(result.bytes);
14751
+ setSandboxPrototype(value, prototype, budget);
14752
+ return value;
14753
+ } finally {
14754
+ release();
14755
+ }
14756
+ }
14757
+ });
14758
+ Object.defineProperty(materializeFunctionProperties(constructor), "fromBase64", {
14759
+ value: fromBase64,
14760
+ writable: true,
14761
+ configurable: true
14762
+ });
14763
+ registerIntrinsicFunction(budget, fromBase64);
14764
+ Object.defineProperties(prototype, {
14765
+ toBase64: {
14766
+ writable: true,
14767
+ configurable: true,
14768
+ value: createSandboxClosure({
14769
+ guest: true,
14770
+ sandbox: true,
14771
+ name: "toBase64",
14772
+ length: 0,
14773
+ call: async ([options], context) => {
14774
+ const value = requireUint8Array(context?.thisValue);
14775
+ const release = retainValues(budget, () => [value, options]);
14776
+ try {
14777
+ const { alphabet, omitPadding } = await base64Options(options, true, budget, context);
14778
+ const { length } = typedArrayStorage(value, true);
14779
+ budget.provisionDataUsage(omitPadding ? Math.ceil(length * 4 / 3) : Math.ceil(length / 3) * 4)();
14780
+ let result = "";
14781
+ for (let index = 0; index < length; index += 3) {
14782
+ budget.visitNode();
14783
+ const a = value[index], b = value[index + 1] ?? 0, c = value[index + 2] ?? 0;
14784
+ const chunk = alphabet[a >> 2] + alphabet[(a & 3) << 4 | b >> 4] + (index + 1 < length ? alphabet[(b & 15) << 2 | c >> 6] : omitPadding ? "" : "=") + (index + 2 < length ? alphabet[c & 63] : omitPadding ? "" : "=");
14785
+ result = budget.allocateString(result + chunk);
14786
+ }
14787
+ return result;
14788
+ } finally {
14789
+ release();
14790
+ }
14791
+ }
14792
+ })
14793
+ },
14794
+ setFromBase64: {
14795
+ writable: true,
14796
+ configurable: true,
14797
+ value: createSandboxClosure({
14798
+ guest: true,
14799
+ sandbox: true,
14800
+ name: "setFromBase64",
14801
+ length: 1,
14802
+ call: async ([text, options], context) => {
14803
+ const value = requireUint8Array(context?.thisValue);
14804
+ if (typeof text !== "string") throw new TypeError("Base64 input must be a string.");
14805
+ const release = retainValues(budget, () => [value, text, options]);
14806
+ try {
14807
+ const { alphabet, mode } = await base64Options(options, false, budget, context);
14808
+ const { length } = typedArrayStorage(value, true);
14809
+ const result = decodeBase64(text, alphabet, mode, budget, length);
14810
+ for (let index = 0; index < result.bytes.length; index++) value[index] = result.bytes[index];
14811
+ if (result.error !== void 0) throw result.error;
14812
+ return { read: result.read, written: result.bytes.length };
14813
+ } finally {
14814
+ release();
14815
+ }
14816
+ }
14817
+ })
14818
+ }
14819
+ });
14820
+ }
14821
+ async function base64Options(options, encode, budget, context) {
14822
+ if (options !== void 0 && (options === null || typeof options !== "object"))
14823
+ throw new TypeError("Base64 options must be an object.");
14824
+ const read = (key) => {
14825
+ if (options === void 0) return void 0;
14826
+ if (context?.getProperty !== void 0) return context.getProperty(options, key);
14827
+ const descriptor = getSandboxPropertyDescriptor(options, key, budget);
14828
+ return descriptor === void 0 ? void 0 : readPropertyDescriptor(descriptor, options, context);
14829
+ };
14830
+ const alphabet = await read("alphabet");
14831
+ if (alphabet !== void 0 && alphabet !== "base64" && alphabet !== "base64url")
14832
+ throw new TypeError("Invalid base64 alphabet.");
14833
+ const digits = alphabets[alphabet ?? "base64"];
14834
+ if (encode) return { alphabet: digits, omitPadding: Boolean(await read("omitPadding")), mode: "loose" };
14835
+ const mode = await read("lastChunkHandling");
14836
+ if (mode !== void 0 && mode !== "loose" && mode !== "strict" && mode !== "stop-before-partial")
14837
+ throw new TypeError("Invalid base64 lastChunkHandling.");
14838
+ return { alphabet: digits, omitPadding: false, mode: mode ?? "loose" };
14839
+ }
14840
+ function decodeBase64(text, alphabet, mode, budget, maxLength = Number.MAX_SAFE_INTEGER) {
14841
+ const bytes = [];
14842
+ const chunk = [];
14843
+ let read = 0, index = 0;
14844
+ const skipWhitespace2 = () => {
14845
+ while (index < text.length) {
14846
+ const code = text.charCodeAt(index);
14847
+ if (code !== 9 && code !== 10 && code !== 12 && code !== 13 && code !== 32) break;
14848
+ budget.visitNode();
14849
+ index++;
14850
+ }
14851
+ };
14852
+ const append = (strict) => {
14853
+ if (strict && (chunk.length === 2 && (chunk[1] & 15) !== 0 || chunk.length === 3 && (chunk[2] & 3) !== 0))
14854
+ throw new SyntaxError("Nonzero unused base64 bits.");
14855
+ const length = bytes.length + chunk.length - 1;
14856
+ budget.allocateArrayLength(length);
14857
+ budget.provisionDataUsage(length + 1)();
14858
+ bytes.push(chunk[0] << 2 | chunk[1] >> 4);
14859
+ if (chunk.length > 2) bytes.push((chunk[1] & 15) << 4 | chunk[2] >> 2);
14860
+ if (chunk.length > 3) bytes.push((chunk[2] & 3) << 6 | chunk[3]);
14861
+ };
14862
+ try {
14863
+ if (maxLength === 0) return { read, bytes };
14864
+ for (; ; ) {
14865
+ skipWhitespace2();
14866
+ if (index === text.length) {
14867
+ if (chunk.length > 0) {
14868
+ if (mode === "stop-before-partial") return { read, bytes };
14869
+ if (mode === "strict" || chunk.length === 1) throw new SyntaxError("Incomplete base64 chunk.");
14870
+ append(false);
14871
+ }
14872
+ return { read: index, bytes };
14873
+ }
14874
+ budget.visitNode();
14875
+ const char = text[index++];
14876
+ if (char === "=") {
14877
+ if (chunk.length < 2) throw new SyntaxError("Invalid base64 padding.");
14878
+ skipWhitespace2();
14879
+ if (chunk.length === 2) {
14880
+ if (index === text.length) {
14881
+ if (mode === "stop-before-partial") return { read, bytes };
14882
+ throw new SyntaxError("Incomplete base64 padding.");
14883
+ }
14884
+ if (text[index] === "=") {
14885
+ budget.visitNode();
14886
+ index++;
14887
+ skipWhitespace2();
14888
+ }
14889
+ }
14890
+ if (index < text.length) throw new SyntaxError("Unexpected input after base64 padding.");
14891
+ append(mode === "strict");
14892
+ return { read: index, bytes };
14893
+ }
14894
+ const digit = alphabet.indexOf(char);
14895
+ if (digit < 0) throw new SyntaxError("Invalid base64 character.");
14896
+ const remaining = maxLength - bytes.length;
14897
+ if (remaining === 1 && chunk.length === 2 || remaining === 2 && chunk.length === 3) return { read, bytes };
14898
+ chunk.push(digit);
14899
+ if (chunk.length === 4) {
14900
+ append(false);
14901
+ chunk.length = 0;
14902
+ read = index;
14903
+ if (bytes.length === maxLength) return { read, bytes };
14904
+ }
14905
+ }
14906
+ } catch (error) {
14907
+ if (!(error instanceof SyntaxError)) throw error;
14908
+ return { read, bytes, error };
14909
+ }
14910
+ }
14911
+
14641
14912
  // packages/safe-js/src/interp/globals/numeric-typed-array.ts
14642
14913
  var constructors = /* @__PURE__ */ new WeakMap();
14643
14914
  function createNumericTypedArrayGlobal(budget, nativePrototype = false, Native = Float32Array) {
@@ -14903,8 +15174,12 @@ function createNumericTypedArrayPrototypes(budget, bindings) {
14903
15174
  setSandboxPrototype(constructor, typedArray);
14904
15175
  setSandboxPrototype(prototype, shared);
14905
15176
  prototypes2.set(Native, prototype);
14906
- registerIntrinsicFunction(budget, constructor);
14907
- registerIntrinsicObject(budget, prototype);
15177
+ }
15178
+ installUint8Hex(budget, bindings.Uint8Array, prototypes2.get(Uint8Array));
15179
+ installUint8Base64(budget, bindings.Uint8Array, prototypes2.get(Uint8Array));
15180
+ for (const [name, Native] of Object.entries(numericTypedArrayConstructors)) {
15181
+ registerIntrinsicFunction(budget, bindings[name]);
15182
+ registerIntrinsicObject(budget, prototypes2.get(Native));
14908
15183
  }
14909
15184
  Object.defineProperty(shared, "constructor", { value: typedArray, writable: true, configurable: true });
14910
15185
  setSandboxPrototype(shared, getSandboxPrototype(/* @__PURE__ */ Object.create(null), budget));
@@ -42828,4 +43103,4 @@ export {
42828
43103
  FileSnapshotBackend,
42829
43104
  run
42830
43105
  };
42831
- //# sourceMappingURL=chunk-UPTA6E3T.js.map
43106
+ //# sourceMappingURL=chunk-OTFEHCGJ.js.map