@metamask/utils 5.0.2 → 6.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/__fixtures__/json.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,KAAK,EAAE;QACL,IAAI;QACJ,EAAE,CAAC,EAAE,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC;QACd,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KACzC;IACD,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;CACrE,CAAC;AAEW,QAAA,8BAA8B,GAAG;IAC5C,KAAK,EAAE;QACL;YACE,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;SACjB;QACD;YACE,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE;gBACN,GAAG,EAAE,KAAK;aACX;SACF;QACD;YACE,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,CAAC,KAAK,CAAC;SAChB;KACF;IACD,OAAO,EAAE;QACP,EAAE;QACF,EAAE;QACF,IAAI;QACJ,KAAK;QACL,IAAI;QACJ,SAAS;QACT,CAAC;QACD,KAAK;QACL;YACE,EAAE,EAAE,CAAC;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;SACjB;QACD;YACE,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,QAAQ;SACjB;QACD;YACE,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,QAAQ;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AAE,CAAC,EAAE,oBAAoB,CAAC,KAAK,EAAE,EAAE;QAC/C,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE;YACL,IAAI,GAAG;gBACL,MAAM,IAAI,KAAK,EAAE,CAAC;YACpB,CAAC;SACF;QACD,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE,+BAA+B;QACtC,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE,iCAAiC;QACxC,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE,gCAAgC;QACvC,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;IACD;QACE,KAAK,EAAE,kCAAkC;QACzC,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,CAAC;KACR;CACF,CAAC","sourcesContent":["export const JSON_FIXTURES = {\n valid: [\n null,\n { a: 1 },\n ['a', 2, null],\n [{ a: null, b: 2, c: [{ foo: 'bar' }] }],\n ],\n invalid: [undefined, Symbol('bar'), () => 'foo', [{ a: undefined }]],\n};\n\nexport const JSON_RPC_NOTIFICATION_FIXTURES = {\n valid: [\n {\n jsonrpc: '2.0',\n method: 'notify',\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: {\n foo: 'bar',\n },\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: ['foo'],\n },\n ],\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n },\n {\n jsonrpc: '1.0',\n method: 'notify',\n },\n {\n jsonrpc: 2.0,\n method: 'notify',\n },\n {\n jsonrpc: '2.0',\n method: {},\n },\n {\n jsonrpc: '2.0',\n method: [],\n },\n {\n jsonrpc: '2.0',\n method: true,\n },\n {\n jsonrpc: '2.0',\n method: false,\n },\n {\n jsonrpc: '2.0',\n method: null,\n },\n {\n jsonrpc: '2.0',\n method: undefined,\n },\n {\n jsonrpc: '2.0',\n method: 1,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: true,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: false,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: null,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: 1,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n params: '',\n },\n ],\n};\n\nexport const JSON_RPC_REQUEST_FIXTURES = {\n valid: [\n {\n jsonrpc: '2.0',\n method: 'notify',\n id: 1,\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n id: '1',\n params: {\n foo: 'bar',\n },\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n id: 'foo',\n params: ['foo'],\n },\n {\n jsonrpc: '2.0',\n method: 'notify',\n id: null,\n },\n ],\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n id: 1,\n jsonrpc: '1.0',\n method: 'notify',\n },\n {\n id: 1,\n jsonrpc: 2.0,\n method: 'notify',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: {},\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: [],\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: true,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: false,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: null,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: undefined,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 1,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n params: true,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n params: false,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n params: null,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n params: 1,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n method: 'notify',\n params: '',\n },\n ],\n};\n\nexport const JSON_RPC_SUCCESS_FIXTURES = {\n valid: [\n {\n id: 1,\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: '1',\n jsonrpc: '2.0',\n result: {\n foo: 'bar',\n },\n },\n {\n id: 'foo',\n jsonrpc: '2.0',\n result: null,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n result: [\n {\n foo: 'bar',\n },\n ],\n },\n ],\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: 1,\n result: 'foo',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n },\n {\n id: 1,\n jsonrpc: '1.0',\n result: 'foo',\n },\n {\n id: 1,\n jsonrpc: 2.0,\n result: 'foo',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n result: undefined,\n },\n {\n id: {},\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: [],\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: true,\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: false,\n jsonrpc: '2.0',\n result: 'foo',\n },\n {\n id: undefined,\n jsonrpc: '2.0',\n result: 'foo',\n },\n ],\n};\n\nexport const JSON_RPC_FAILURE_FIXTURES = {\n valid: [\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: '1',\n jsonrpc: '2.0',\n error: {\n code: -32001,\n message: 'Internal error',\n data: {\n foo: 'bar',\n },\n },\n },\n {\n id: 'foo',\n jsonrpc: '2.0',\n error: {\n code: -32002,\n message: 'Internal error',\n data: ['foo'],\n stack: 'bar',\n },\n },\n {\n id: 'foo',\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n data: 'foo',\n },\n },\n {\n id: 'foo',\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n data: 1,\n },\n },\n ],\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n },\n {\n id: {},\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: [],\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: true,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: false,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: undefined,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '1.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: 2.0,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: {},\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: [],\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: true,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: false,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: null,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: undefined,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: [],\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {},\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: true,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: false,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: null,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: undefined,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: 'foo',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: 1,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: {},\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: [],\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: true,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: false,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: null,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: undefined,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: 'foo',\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: {},\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: [],\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: true,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: false,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: null,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: undefined,\n },\n },\n ],\n};\n\nexport const JSON_RPC_ERROR_FIXTURES = {\n valid: JSON_RPC_FAILURE_FIXTURES.valid.map((fixture) => fixture.error),\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n code: {},\n message: 'Internal error',\n },\n {\n code: [],\n message: 'Internal error',\n },\n {\n code: true,\n message: 'Internal error',\n },\n {\n code: false,\n message: 'Internal error',\n },\n {\n code: null,\n message: 'Internal error',\n },\n {\n code: undefined,\n message: 'Internal error',\n },\n {\n code: 'foo',\n message: 'Internal error',\n },\n {\n code: -32000,\n message: {},\n },\n {\n code: -32000,\n message: [],\n },\n {\n code: -32000,\n message: true,\n },\n {\n code: -32000,\n message: false,\n },\n {\n code: -32000,\n message: null,\n },\n {\n code: -32000,\n message: undefined,\n },\n {\n code: -32000.5,\n message: undefined,\n },\n ],\n};\n\nexport const JSON_RPC_RESPONSE_FIXTURES = {\n valid: [\n ...JSON_RPC_SUCCESS_FIXTURES.valid,\n ...JSON_RPC_FAILURE_FIXTURES.valid,\n ],\n invalid: [\n ...JSON_RPC_SUCCESS_FIXTURES.invalid,\n ...JSON_RPC_FAILURE_FIXTURES.invalid,\n ],\n};\n\nexport const JSON_RPC_PENDING_RESPONSE_FIXTURES = {\n valid: [\n ...JSON_RPC_SUCCESS_FIXTURES.valid,\n ...JSON_RPC_FAILURE_FIXTURES.valid,\n {\n id: 1,\n jsonrpc: '2.0',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: undefined,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n result: undefined,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n result: undefined,\n error: undefined,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n result: {\n foo: 'bar',\n },\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n ],\n invalid: [\n {},\n [],\n true,\n false,\n null,\n undefined,\n 1,\n 'foo',\n {\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: {},\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: [],\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: true,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: false,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: undefined,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '1.0',\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: 2.0,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: {},\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: [],\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: true,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: false,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: null,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: undefined,\n error: {\n code: -32000,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: [],\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {},\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: true,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: false,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: null,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: 'foo',\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: 1,\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: {},\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: [],\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: true,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: false,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: null,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: undefined,\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: 'foo',\n message: 'Internal error',\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: {},\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: [],\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: true,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: false,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: null,\n },\n },\n {\n id: 1,\n jsonrpc: '2.0',\n error: {\n code: -32000,\n message: undefined,\n },\n },\n ],\n};\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const CHARACTER_MAP = {\n '\"': '\\\\\"',\n '\\\\': '\\\\\\\\',\n '\\x00': '\\\\u0000',\n '\\x01': '\\\\u0001',\n '\\x02': '\\\\u0002',\n '\\x03': '\\\\u0003',\n '\\x04': '\\\\u0004',\n '\\x05': '\\\\u0005',\n '\\x06': '\\\\u0006',\n '\\x07': '\\\\u0007',\n '\\x08': '\\\\b',\n '\\x09': '\\\\t',\n '\\x0A': '\\\\n',\n '\\x0B': '\\\\u000b',\n '\\x0C': '\\\\f',\n '\\x0D': '\\\\r',\n '\\x0E': '\\\\u000e',\n '\\x0F': '\\\\u000f',\n '\\x10': '\\\\u0010',\n '\\x11': '\\\\u0011',\n '\\x12': '\\\\u0012',\n '\\x13': '\\\\u0013',\n '\\x14': '\\\\u0014',\n '\\x15': '\\\\u0015',\n '\\x16': '\\\\u0016',\n '\\x17': '\\\\u0017',\n '\\x18': '\\\\u0018',\n '\\x19': '\\\\u0019',\n '\\x1A': '\\\\u001a',\n '\\x1B': '\\\\u001b',\n '\\x1C': '\\\\u001c',\n '\\x1D': '\\\\u001d',\n '\\x1E': '\\\\u001e',\n '\\x1F': '\\\\u001f',\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nconst DIRECT_CIRCULAR_REFERENCE_ARRAY: unknown[] = [];\nDIRECT_CIRCULAR_REFERENCE_ARRAY.push(DIRECT_CIRCULAR_REFERENCE_ARRAY);\n\nconst INDIRECT_CIRCULAR_REFERENCE_ARRAY: unknown[] = [];\nINDIRECT_CIRCULAR_REFERENCE_ARRAY.push([[INDIRECT_CIRCULAR_REFERENCE_ARRAY]]);\n\nconst DIRECT_CIRCULAR_REFERENCE_OBJECT: Record<string, unknown> = {};\nDIRECT_CIRCULAR_REFERENCE_OBJECT.prop = DIRECT_CIRCULAR_REFERENCE_OBJECT;\n\nconst INDIRECT_CIRCULAR_REFERENCE_OBJECT: Record<string, unknown> = {\n p1: {\n p2: {\n get p3() {\n return INDIRECT_CIRCULAR_REFERENCE_OBJECT;\n },\n },\n },\n};\n\nconst TO_JSON_CIRCULAR_REFERENCE = {\n toJSON() {\n return {};\n },\n};\n\nconst CIRCULAR_REFERENCE = { prop: TO_JSON_CIRCULAR_REFERENCE };\nTO_JSON_CIRCULAR_REFERENCE.toJSON = function () {\n return CIRCULAR_REFERENCE;\n};\n\nconst DUPLICATE_DATE = new Date();\nconst DUPLICATE_OBJECT = {\n value: 'foo',\n};\n\nconst DUPLICATE_REFERENCE = {\n a: DUPLICATE_DATE,\n b: DUPLICATE_DATE,\n c: DUPLICATE_DATE,\n testOne: DUPLICATE_OBJECT,\n testTwo: DUPLICATE_OBJECT,\n testThree: {\n nestedObjectTest: {\n multipleTimes: {\n valueOne: DUPLICATE_OBJECT,\n valueTwo: DUPLICATE_OBJECT,\n valueThree: DUPLICATE_OBJECT,\n valueFour: DUPLICATE_OBJECT,\n valueFive: DUPLICATE_DATE,\n valueSix: {},\n },\n },\n },\n testFour: {},\n testFive: {\n something: null,\n somethingElse: null,\n anotherValue: null,\n somethingAgain: DUPLICATE_OBJECT,\n anotherOne: {\n nested: {\n multipleTimes: {\n valueOne: DUPLICATE_OBJECT,\n },\n },\n },\n },\n};\n\nconst REVOKED_ARRAY_PROXY = Proxy.revocable([], {});\nREVOKED_ARRAY_PROXY.revoke();\n\nconst REVOKED_OBJECT_PROXY = Proxy.revocable({}, {});\nREVOKED_OBJECT_PROXY.revoke();\n\nexport const JSON_VALIDATION_FIXTURES = [\n {\n value: {\n a: 'bc',\n },\n valid: true,\n size: 10,\n },\n {\n value: {\n a: 1234,\n },\n valid: true,\n size: 10,\n },\n {\n value: {\n a: 'bcšečf',\n },\n valid: true,\n size: 16,\n },\n {\n value: [\n -5e-11, 5e-9, 0.000000000001, -0.00000000009, 100000.00000008, -100.88888,\n 0.333, 1000000000000,\n ],\n valid: true,\n size: 73,\n },\n {\n value: {\n data: {\n account: {\n /* eslint-disable @typescript-eslint/naming-convention */\n __typename: 'Account',\n registrations: [\n {\n __typename: 'Registration',\n domain: {\n __typename: 'Domain',\n isMigrated: true,\n labelName: 'mycrypto',\n labelhash:\n '0x9a781ca0d227debc3ee76d547c960b0803a6c9f58c6d3b4722f12ede7e6ef7c9',\n name: 'mycrypto.eth',\n parent: { __typename: 'Domain', name: 'eth' },\n },\n expiryDate: '1754111315',\n },\n ],\n /* eslint-enable @typescript-eslint/naming-convention */\n },\n moreComplexity: {\n numbers: [\n -5e-11, 5e-9, 0.000000000001, -0.00000000009, 100000.00000008,\n -100.88888, 0.333, 1000000000000,\n ],\n moreNestedObjects: {\n nestedAgain: {\n nestedAgain: {\n andAgain: {\n andAgain: {\n value: true,\n again: {\n value: false,\n },\n },\n },\n },\n },\n },\n differentEncodings: {\n ascii:\n '!\"#$%&\\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~',\n utf8: 'šđćčžЀЂЇЄЖФћΣΩδλ',\n mixed: 'ABCDEFGHIJ KLMNOPQRST UVWXYZšđćč žЀЂЇЄЖФћΣΩδλ',\n specialCharacters: '\"\\\\\\n\\r\\t',\n stringWithSpecialEscapedCharacters:\n \"this\\nis\\nsome\\\"'string\\r\\nwith\\tspecial\\\\escaped\\tcharacters'\",\n },\n specialObjectsTypesAndValues: {\n t: [true, true, true],\n f: [false, false, false],\n nulls: [null, null, null],\n undef: null,\n mixed: [\n null,\n null,\n null,\n null,\n null,\n true,\n null,\n false,\n null,\n null,\n ],\n inObject: {\n valueOne: null,\n valueTwo: null,\n t: true,\n f: false,\n },\n dates: {\n someDate: new Date(),\n someOther: new Date(2022, 0, 2, 15, 4, 5),\n invalidDate: new Date('bad-date-format'),\n },\n },\n },\n },\n },\n valid: true,\n size: 1288,\n },\n {\n value: {\n dates: {\n someDate: new Date(),\n someOther: new Date(2022, 0, 2, 15, 4, 5),\n invalidDate: new Date('bad-date-format'),\n },\n },\n valid: true,\n size: 107,\n },\n {\n value: ['foo', 'bar', null, ['foo', 'bar', null]],\n valid: true,\n size: 37,\n },\n {\n value: null,\n valid: true,\n size: 4,\n },\n {\n value: true,\n valid: true,\n size: 4,\n },\n {\n value: false,\n valid: true,\n size: 5,\n },\n {\n value: 'str',\n valid: true,\n size: 5,\n },\n {\n value: 123,\n valid: true,\n size: 3,\n },\n\n {\n value: {\n a: undefined,\n },\n valid: false,\n size: 0,\n },\n {\n value: {\n levelOne: {\n levelTwo: {\n levelThree: {\n levelFour: {\n levelFive: () => {\n return 'anything';\n },\n },\n },\n },\n },\n },\n valid: false,\n size: 0,\n },\n {\n value: {\n mySymbol: Symbol('MySymbol'),\n },\n valid: false,\n size: 0,\n },\n {\n value: [\n function () {\n return 'whatever';\n },\n ],\n valid: false,\n size: 0,\n },\n\n // These tests are taken from ECMA TC39 (test262) test scenarios used for\n // testing the `JSON.stringify` function.\n // https://github.com/tc39/test262/tree/main/test/built-ins/JSON/stringify\n /* eslint-disable no-new-wrappers */\n {\n value: new Boolean(true),\n valid: true,\n size: 4,\n },\n {\n value: { key: new Boolean(false) },\n valid: true,\n size: 13,\n },\n {\n value: new Boolean(false),\n valid: true,\n size: 5,\n },\n {\n value: new Number(3.14),\n valid: true,\n size: 4,\n },\n {\n value: new String('str'),\n valid: true,\n size: 5,\n },\n /* eslint-enable no-new-wrappers */\n {\n value: -0,\n valid: true,\n size: 1,\n },\n {\n value: ['-0', 0, -0],\n valid: true,\n size: 10,\n },\n {\n value: { key: -0 },\n valid: true,\n size: 9,\n },\n {\n value: Infinity,\n valid: false,\n size: 0,\n },\n {\n value: { key: -Infinity },\n valid: false,\n size: 0,\n },\n {\n value: CHARACTER_MAP,\n valid: true,\n size: 593,\n },\n {\n value: Object.keys(CHARACTER_MAP).join(''),\n valid: true,\n size: 178,\n },\n {\n value: Object.keys(CHARACTER_MAP).reverse().join(''),\n valid: true,\n size: 178,\n },\n {\n value: Object.values(CHARACTER_MAP).join(''),\n valid: true,\n size: 214,\n },\n {\n value: Object.values(CHARACTER_MAP).reverse().join(''),\n valid: true,\n size: 214,\n },\n {\n value: {\n toJSON: null,\n },\n valid: true,\n size: 15,\n },\n {\n value: { toJSON: false },\n valid: true,\n size: 16,\n },\n {\n value: { toJSON: [] },\n valid: true,\n size: 13,\n },\n {\n value: DUPLICATE_REFERENCE,\n valid: true,\n size: 552,\n },\n {\n value: { a: { b: REVOKED_OBJECT_PROXY.proxy } },\n valid: false,\n size: 0,\n },\n {\n value: {\n get key() {\n throw new Error();\n },\n },\n valid: false,\n size: 0,\n },\n {\n value: undefined,\n valid: false,\n size: 0,\n },\n {\n value: DIRECT_CIRCULAR_REFERENCE_ARRAY,\n valid: false,\n size: 0,\n },\n {\n value: INDIRECT_CIRCULAR_REFERENCE_ARRAY,\n valid: false,\n size: 0,\n },\n {\n value: DIRECT_CIRCULAR_REFERENCE_OBJECT,\n valid: false,\n size: 0,\n },\n {\n value: INDIRECT_CIRCULAR_REFERENCE_OBJECT,\n valid: false,\n size: 0,\n },\n];\n"]}
@@ -0,0 +1,5 @@
1
+ export declare const NUMBER_VALUES: {
2
+ number: number;
3
+ bigint: bigint;
4
+ hexadecimal: string;
5
+ }[];
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NUMBER_VALUES = void 0;
4
+ exports.NUMBER_VALUES = [
5
+ {
6
+ number: 0,
7
+ bigint: BigInt(0),
8
+ hexadecimal: '0x0',
9
+ },
10
+ {
11
+ number: 1,
12
+ bigint: BigInt(1),
13
+ hexadecimal: '0x1',
14
+ },
15
+ {
16
+ number: 16,
17
+ bigint: BigInt(16),
18
+ hexadecimal: '0x10',
19
+ },
20
+ {
21
+ number: 255,
22
+ bigint: BigInt(255),
23
+ hexadecimal: '0xff',
24
+ },
25
+ {
26
+ number: 256,
27
+ bigint: BigInt(256),
28
+ hexadecimal: '0x100',
29
+ },
30
+ {
31
+ number: 65535,
32
+ bigint: BigInt(65535),
33
+ hexadecimal: '0xffff',
34
+ },
35
+ {
36
+ number: 65536,
37
+ bigint: BigInt(65536),
38
+ hexadecimal: '0x10000',
39
+ },
40
+ {
41
+ number: 4294967295,
42
+ bigint: BigInt(4294967295),
43
+ hexadecimal: '0xffffffff',
44
+ },
45
+ {
46
+ number: 4294967296,
47
+ bigint: BigInt(4294967296),
48
+ hexadecimal: '0x100000000',
49
+ },
50
+ {
51
+ number: 9007199254740991,
52
+ bigint: BigInt(9007199254740991),
53
+ hexadecimal: '0x1fffffffffffff',
54
+ },
55
+ ];
56
+ //# sourceMappingURL=numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/__fixtures__/numbers.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B;QACE,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACjB,WAAW,EAAE,KAAK;KACnB;IACD;QACE,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACjB,WAAW,EAAE,KAAK;KACnB;IACD;QACE,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;QAClB,WAAW,EAAE,MAAM;KACpB;IACD;QACE,MAAM,EAAE,GAAG;QACX,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;QACnB,WAAW,EAAE,MAAM;KACpB;IACD;QACE,MAAM,EAAE,GAAG;QACX,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC;QACnB,WAAW,EAAE,OAAO;KACrB;IACD;QACE,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;QACrB,WAAW,EAAE,QAAQ;KACtB;IACD;QACE,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;QACrB,WAAW,EAAE,SAAS;KACvB;IACD;QACE,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;QAC1B,WAAW,EAAE,YAAY;KAC1B;IACD;QACE,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;QAC1B,WAAW,EAAE,aAAa;KAC3B;IACD;QACE,MAAM,EAAE,gBAAgB;QACxB,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC;QAChC,WAAW,EAAE,kBAAkB;KAChC;CACF,CAAC","sourcesContent":["export const NUMBER_VALUES = [\n {\n number: 0,\n bigint: BigInt(0),\n hexadecimal: '0x0',\n },\n {\n number: 1,\n bigint: BigInt(1),\n hexadecimal: '0x1',\n },\n {\n number: 16,\n bigint: BigInt(16),\n hexadecimal: '0x10',\n },\n {\n number: 255,\n bigint: BigInt(255),\n hexadecimal: '0xff',\n },\n {\n number: 256,\n bigint: BigInt(256),\n hexadecimal: '0x100',\n },\n {\n number: 65535,\n bigint: BigInt(65535),\n hexadecimal: '0xffff',\n },\n {\n number: 65536,\n bigint: BigInt(65536),\n hexadecimal: '0x10000',\n },\n {\n number: 4294967295,\n bigint: BigInt(4294967295),\n hexadecimal: '0xffffffff',\n },\n {\n number: 4294967296,\n bigint: BigInt(4294967296),\n hexadecimal: '0x100000000',\n },\n {\n number: 9007199254740991,\n bigint: BigInt(9007199254740991),\n hexadecimal: '0x1fffffffffffff',\n },\n];\n"]}
package/dist/assert.js CHANGED
@@ -20,9 +20,8 @@ function isErrorWithMessage(error) {
20
20
  * @returns `true` if the value is a constructor, or `false` otherwise.
21
21
  */
22
22
  function isConstructable(fn) {
23
- var _a, _b;
24
23
  /* istanbul ignore next */
25
- return Boolean(typeof ((_b = (_a = fn === null || fn === void 0 ? void 0 : fn.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) === 'string');
24
+ return Boolean(typeof fn?.prototype?.constructor?.name === 'string');
26
25
  }
27
26
  /**
28
27
  * Get the error message from an unknown error object. If the error object has
@@ -1 +1 @@
1
- {"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";;;AAAA,6CAAkE;AAMlE;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CACtB,EAA6B;;IAE7B,0BAA0B;IAC1B,OAAO,OAAO,CAAC,OAAO,CAAA,MAAA,MAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,SAAS,0CAAE,WAAW,0CAAE,IAAI,CAAA,KAAK,QAAQ,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,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,CAAC,GAAG,CAAC,CAAC;KAC5E;AACH,CAAC;AAZD,oCAYC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,gBAAgB,CAAC,OAAc;IAC7C,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;AACJ,CAAC;AAJD,4CAIC","sourcesContent":["import { assert as assertSuperstruct, Struct } from 'superstruct';\n\nexport type AssertionErrorConstructor =\n | (new (args: { message: string }) => Error)\n | ((args: { message: string }) => Error);\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `message` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns True or false, depending on the result.\n */\nfunction isErrorWithMessage(error: unknown): error is { message: string } {\n return typeof error === 'object' && error !== null && 'message' in error;\n}\n\n/**\n * Check if a value is a constructor, i.e., a function that can be called with\n * the `new` keyword.\n *\n * @param fn - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nfunction isConstructable(\n fn: AssertionErrorConstructor,\n): fn is new (args: { message: string }) => Error {\n /* istanbul ignore next */\n return Boolean(typeof fn?.prototype?.constructor?.name === 'string');\n}\n\n/**\n * Get the error message from an unknown error object. If the error object has\n * a `message` property, that property is returned. Otherwise, the stringified\n * error object is returned.\n *\n * @param error - The error object to get the message from.\n * @returns The error message.\n */\nfunction getErrorMessage(error: unknown): string {\n const message = isErrorWithMessage(error) ? error.message : String(error);\n\n // If the error ends with a period, remove it, as we'll add our own period.\n if (message.endsWith('.')) {\n return message.slice(0, -1);\n }\n\n return message;\n}\n\n/**\n * Initialise an {@link AssertionErrorConstructor} error.\n *\n * @param ErrorWrapper - The error class to use.\n * @param message - The error message.\n * @returns The error object.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction getError(ErrorWrapper: AssertionErrorConstructor, message: string) {\n if (isConstructable(ErrorWrapper)) {\n return new ErrorWrapper({\n message,\n });\n }\n return ErrorWrapper({\n message,\n });\n}\n\n/**\n * The default error class that is thrown if an assertion fails.\n */\nexport class AssertionError extends Error {\n readonly code = 'ERR_ASSERTION';\n\n constructor(options: { message: string }) {\n super(options.message);\n }\n}\n\n/**\n * Same as Node.js assert.\n * If the value is falsy, throws an error, does nothing otherwise.\n *\n * @throws {@link AssertionError} If value is falsy.\n * @param value - The test that should be truthy to pass.\n * @param message - Message to be passed to {@link AssertionError} or an\n * {@link Error} instance to throw.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}. If a custom error class is provided for\n * the `message` argument, this argument is ignored.\n */\nexport function assert(\n value: any,\n message: string | Error = 'Assertion failed.',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value {\n if (!value) {\n if (message instanceof Error) {\n throw message;\n }\n\n throw getError(ErrorWrapper, message);\n }\n}\n\n/**\n * Assert a value against a Superstruct struct.\n *\n * @param value - The value to validate.\n * @param struct - The struct to validate against.\n * @param errorPrefix - A prefix to add to the error message. Defaults to\n * \"Assertion failed\".\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the value is not valid.\n */\nexport function assertStruct<T, S>(\n value: unknown,\n struct: Struct<T, S>,\n errorPrefix = 'Assertion failed',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value is T {\n try {\n assertSuperstruct(value, struct);\n } catch (error) {\n throw getError(ErrorWrapper, `${errorPrefix}: ${getErrorMessage(error)}.`);\n }\n}\n\n/**\n * Use in the default case of a switch that you want to be fully exhaustive.\n * Using this function forces the compiler to enforce exhaustivity during\n * compile-time.\n *\n * @example\n * ```\n * const number = 1;\n * switch (number) {\n * case 0:\n * ...\n * case 1:\n * ...\n * default:\n * assertExhaustive(snapPrefix);\n * }\n * ```\n * @param _object - The object on which the switch is being operated.\n */\nexport function assertExhaustive(_object: never): never {\n throw new Error(\n 'Invalid branch reached. Should be detected during compilation.',\n );\n}\n"]}
1
+ {"version":3,"file":"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V,UAA0B,mBAAmB;AAC7C,gEAAgE;AAChE,eAA0C,cAAc;IAExD,IAAI,CAAC,KAAK,EAAE;QACV,IAAI,OAAO,YAAY,KAAK,EAAE;YAC5B,MAAM,OAAO,CAAC;SACf;QAED,MAAM,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;KACvC;AACH,CAAC;AAbD,wBAaC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAC1B,KAAc,EACd,MAAoB,EACpB,WAAW,GAAG,kBAAkB;AAChC,gEAAgE;AAChE,eAA0C,cAAc;IAExD,IAAI;QACF,IAAA,oBAAiB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAClC;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,QAAQ,CAAC,YAAY,EAAE,GAAG,WAAW,KAAK,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KAC5E;AACH,CAAC;AAZD,oCAYC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,gBAAgB,CAAC,OAAc;IAC7C,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;AACJ,CAAC;AAJD,4CAIC","sourcesContent":["import { assert as assertSuperstruct, Struct } from 'superstruct';\n\nexport type AssertionErrorConstructor =\n | (new (args: { message: string }) => Error)\n | ((args: { message: string }) => Error);\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `message` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns True or false, depending on the result.\n */\nfunction isErrorWithMessage(error: unknown): error is { message: string } {\n return typeof error === 'object' && error !== null && 'message' in error;\n}\n\n/**\n * Check if a value is a constructor, i.e., a function that can be called with\n * the `new` keyword.\n *\n * @param fn - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nfunction isConstructable(\n fn: AssertionErrorConstructor,\n): fn is new (args: { message: string }) => Error {\n /* istanbul ignore next */\n return Boolean(typeof fn?.prototype?.constructor?.name === 'string');\n}\n\n/**\n * Get the error message from an unknown error object. If the error object has\n * a `message` property, that property is returned. Otherwise, the stringified\n * error object is returned.\n *\n * @param error - The error object to get the message from.\n * @returns The error message.\n */\nfunction getErrorMessage(error: unknown): string {\n const message = isErrorWithMessage(error) ? error.message : String(error);\n\n // If the error ends with a period, remove it, as we'll add our own period.\n if (message.endsWith('.')) {\n return message.slice(0, -1);\n }\n\n return message;\n}\n\n/**\n * Initialise an {@link AssertionErrorConstructor} error.\n *\n * @param ErrorWrapper - The error class to use.\n * @param message - The error message.\n * @returns The error object.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction getError(ErrorWrapper: AssertionErrorConstructor, message: string) {\n if (isConstructable(ErrorWrapper)) {\n return new ErrorWrapper({\n message,\n });\n }\n return ErrorWrapper({\n message,\n });\n}\n\n/**\n * The default error class that is thrown if an assertion fails.\n */\nexport class AssertionError extends Error {\n readonly code = 'ERR_ASSERTION';\n\n constructor(options: { message: string }) {\n super(options.message);\n }\n}\n\n/**\n * Same as Node.js assert.\n * If the value is falsy, throws an error, does nothing otherwise.\n *\n * @throws {@link AssertionError} If value is falsy.\n * @param value - The test that should be truthy to pass.\n * @param message - Message to be passed to {@link AssertionError} or an\n * {@link Error} instance to throw.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}. If a custom error class is provided for\n * the `message` argument, this argument is ignored.\n */\nexport function assert(\n value: any,\n message: string | Error = 'Assertion failed.',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value {\n if (!value) {\n if (message instanceof Error) {\n throw message;\n }\n\n throw getError(ErrorWrapper, message);\n }\n}\n\n/**\n * Assert a value against a Superstruct struct.\n *\n * @param value - The value to validate.\n * @param struct - The struct to validate against.\n * @param errorPrefix - A prefix to add to the error message. Defaults to\n * \"Assertion failed\".\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the value is not valid.\n */\nexport function assertStruct<T, S>(\n value: unknown,\n struct: Struct<T, S>,\n errorPrefix = 'Assertion failed',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value is T {\n try {\n assertSuperstruct(value, struct);\n } catch (error) {\n throw getError(ErrorWrapper, `${errorPrefix}: ${getErrorMessage(error)}.`);\n }\n}\n\n/**\n * Use in the default case of a switch that you want to be fully exhaustive.\n * Using this function forces the compiler to enforce exhaustivity during\n * compile-time.\n *\n * @example\n * ```\n * const number = 1;\n * switch (number) {\n * case 0:\n * ...\n * case 1:\n * ...\n * default:\n * assertExhaustive(snapPrefix);\n * }\n * ```\n * @param _object - The object on which the switch is being operated.\n */\nexport function assertExhaustive(_object: never): never {\n throw new Error(\n 'Invalid branch reached. Should be detected during compilation.',\n );\n}\n"]}
package/dist/base64.js CHANGED
@@ -11,9 +11,8 @@ const assert_1 = require("./assert");
11
11
  * @returns A superstruct validating base64.
12
12
  */
13
13
  const base64 = (struct, options = {}) => {
14
- var _a, _b;
15
- const paddingRequired = (_a = options.paddingRequired) !== null && _a !== void 0 ? _a : false;
16
- const characterSet = (_b = options.characterSet) !== null && _b !== void 0 ? _b : 'base64';
14
+ const paddingRequired = options.paddingRequired ?? false;
15
+ const characterSet = options.characterSet ?? 'base64';
17
16
  let letters;
18
17
  if (characterSet === 'base64') {
19
18
  letters = String.raw `[A-Za-z0-9+\/]`;
@@ -1 +1 @@
1
- {"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAE9C,qCAAkC;AAmBlC;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CACpB,MAAoB,EACpB,UAAyB,EAAE,EAC3B,EAAE;;IACF,MAAM,eAAe,GAAG,MAAA,OAAO,CAAC,eAAe,mCAAI,KAAK,CAAC;IACzD,MAAM,YAAY,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,QAAQ,CAAC;IAEtD,IAAI,OAAe,CAAC;IACpB,IAAI,YAAY,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,gBAAgB,CAAC;KACtC;SAAM;QACL,IAAA,eAAM,EAAC,YAAY,KAAK,WAAW,CAAC,CAAC;QACrC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,eAAe,CAAC;KACrC;IAED,IAAI,EAAU,CAAC;IACf,IAAI,eAAe,EAAE;QACnB,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,QAAQ,OAAO,UAAU,EACzD,GAAG,CACJ,CAAC;KACH;SAAM;QACL,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,SAAS,OAAO,QAAQ,OAAO,UAAU,EACzE,GAAG,CACJ,CAAC;KACH;IAED,OAAO,IAAA,qBAAO,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC,CAAC;AA7BW,QAAA,MAAM,UA6BjB","sourcesContent":["import { pattern, Struct } from 'superstruct';\n\nimport { assert } from './assert';\n\nexport type Base64Options = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param options - Optional options to specialize base64 validation. See {@link Base64Options} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <T extends string, S>(\n struct: Struct<T, S>,\n options: Base64Options = {},\n) => {\n const paddingRequired = options.paddingRequired ?? false;\n const characterSet = options.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n"]}
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAE9C,qCAAkC;AAmBlC;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CACpB,MAAoB,EACpB,UAAyB,EAAE,EAC3B,EAAE;IACF,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;IACzD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,QAAQ,CAAC;IAEtD,IAAI,OAAe,CAAC;IACpB,IAAI,YAAY,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,gBAAgB,CAAC;KACtC;SAAM;QACL,IAAA,eAAM,EAAC,YAAY,KAAK,WAAW,CAAC,CAAC;QACrC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,eAAe,CAAC;KACrC;IAED,IAAI,EAAU,CAAC;IACf,IAAI,eAAe,EAAE;QACnB,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,QAAQ,OAAO,UAAU,EACzD,GAAG,CACJ,CAAC;KACH;SAAM;QACL,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,SAAS,OAAO,QAAQ,OAAO,UAAU,EACzE,GAAG,CACJ,CAAC;KACH;IAED,OAAO,IAAA,qBAAO,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC,CAAC;AA7BW,QAAA,MAAM,UA6BjB","sourcesContent":["import { pattern, Struct } from 'superstruct';\n\nimport { assert } from './assert';\n\nexport type Base64Options = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param options - Optional options to specialize base64 validation. See {@link Base64Options} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <T extends string, S>(\n struct: Struct<T, S>,\n options: Base64Options = {},\n) => {\n const paddingRequired = options.paddingRequired ?? false;\n const characterSet = options.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n"]}
package/dist/bytes.js CHANGED
@@ -156,9 +156,8 @@ exports.bytesToString = bytesToString;
156
156
  * @returns The bytes as `Uint8Array`.
157
157
  */
158
158
  function hexToBytes(value) {
159
- var _a;
160
159
  // "0x" is often used as empty byte array.
161
- if (((_a = value === null || value === void 0 ? void 0 : value.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(value)) === '0x') {
160
+ if (value?.toLowerCase?.() === '0x') {
162
161
  return new Uint8Array();
163
162
  }
164
163
  (0, hex_1.assertIsHexString)(value);
package/dist/bytes.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,+BAAgE;AAEhE,2BAA2B;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5D,gEAAgE;QAChE,uEAAuE;QACvE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;KACtC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,kCAqBC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAAC,KAAiB;IAC9C,4EAA4E;IAC5E,qEAAqE;IACrE,eAAe;IACf,iDAAiD;IACjD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,KAAK,YAAY,MAAM,EAAE;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAC/B,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAC;QAEF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC;AAfD,wCAeC","sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString, Hex, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n"]}
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,+BAAgE;AAEhE,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAIhC;;;;;;;;;;;;;GAaG;AACH,SAAS,8BAA8B;IACrC,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,eAAe;IACf,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAA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,CAAC,MAAM,CAAC,KAAK,CAC/B,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CACpC,CAAC;QAEF,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC;AAfD,wCAeC","sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString, Hex, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tsd_1 = require("tsd");
4
+ // Valid hex strings:
5
+ (0, tsd_1.expectAssignable)('0x');
6
+ (0, tsd_1.expectAssignable)('0x0');
7
+ (0, tsd_1.expectAssignable)('0x😀');
8
+ const embeddedString = 'test';
9
+ (0, tsd_1.expectAssignable)(`0x${embeddedString}`);
10
+ // Not valid hex strings:
11
+ (0, tsd_1.expectNotAssignable)(`0X${embeddedString}`);
12
+ (0, tsd_1.expectNotAssignable)(`1x${embeddedString}`);
13
+ (0, tsd_1.expectNotAssignable)(0);
14
+ (0, tsd_1.expectNotAssignable)('0');
15
+ (0, tsd_1.expectNotAssignable)('🙃');
16
+ //# sourceMappingURL=hex.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.test-d.js","sourceRoot":"","sources":["../src/hex.test-d.ts"],"names":[],"mappings":";;AAAA,6BAA4D;AAI5D,qBAAqB;AAErB,IAAA,sBAAgB,EAAM,IAAI,CAAC,CAAC;AAE5B,IAAA,sBAAgB,EAAM,KAAK,CAAC,CAAC;AAE7B,IAAA,sBAAgB,EAAM,MAAM,CAAC,CAAC;AAE9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,IAAA,sBAAgB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAE7C,yBAAyB;AAEzB,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,CAAC,CAAC,CAAC;AAE5B,IAAA,yBAAmB,EAAM,GAAG,CAAC,CAAC;AAE9B,IAAA,yBAAmB,EAAM,IAAI,CAAC,CAAC","sourcesContent":["import { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport { Hex } from '.';\n\n// Valid hex strings:\n\nexpectAssignable<Hex>('0x');\n\nexpectAssignable<Hex>('0x0');\n\nexpectAssignable<Hex>('0x😀');\n\nconst embeddedString = 'test';\nexpectAssignable<Hex>(`0x${embeddedString}`);\n\n// Not valid hex strings:\n\nexpectNotAssignable<Hex>(`0X${embeddedString}`);\n\nexpectNotAssignable<Hex>(`1x${embeddedString}`);\n\nexpectNotAssignable<Hex>(0);\n\nexpectNotAssignable<Hex>('0');\n\nexpectNotAssignable<Hex>('🙃');\n"]}
package/dist/json.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare const UnsafeJsonStruct: Struct<Json>;
18
18
  * This struct sanitizes the value before validating it, so that it is safe to
19
19
  * use with untrusted input.
20
20
  */
21
- export declare const JsonStruct: Struct<Json, null>;
21
+ export declare const JsonStruct: Struct<Json, unknown>;
22
22
  /**
23
23
  * Check if the given value is a valid {@link Json} value, i.e., a value that is
24
24
  * serializable to JSON.
@@ -27,6 +27,19 @@ export declare const JsonStruct: Struct<Json, null>;
27
27
  * @returns Whether the value is a valid {@link Json} value.
28
28
  */
29
29
  export declare function isValidJson(value: unknown): value is Json;
30
+ /**
31
+ * Validate and return sanitized JSON.
32
+ *
33
+ * Note:
34
+ * This function uses sanitized JsonStruct for validation
35
+ * that applies stringify and then parse of a value provided
36
+ * to ensure that there are no getters which can have side effects
37
+ * that can cause security issues.
38
+ *
39
+ * @param value - JSON structure to be processed.
40
+ * @returns Sanitized JSON structure.
41
+ */
42
+ export declare function getSafeJson<Type extends Json = Json>(value: unknown): Type;
30
43
  /**
31
44
  * Get the size of a JSON value in bytes. This also validates the value.
32
45
  *
@@ -60,7 +73,7 @@ export declare const JsonRpcErrorStruct: Struct<{
60
73
  }, {
61
74
  code: Struct<number, null>;
62
75
  message: Struct<string, null>;
63
- data: Struct<Json | undefined, null>;
76
+ data: Struct<Json | undefined, unknown>;
64
77
  stack: Struct<string | undefined, null>;
65
78
  }>;
66
79
  /**
@@ -166,7 +179,7 @@ export declare const PendingJsonRpcResponseStruct: Struct<{
166
179
  } | undefined, {
167
180
  code: Struct<number, null>;
168
181
  message: Struct<string, null>;
169
- data: Struct<Json | undefined, null>;
182
+ data: Struct<Json | undefined, unknown>;
170
183
  stack: Struct<string | undefined, null>;
171
184
  }>;
172
185
  }>;
@@ -183,7 +196,7 @@ export declare const JsonRpcSuccessStruct: Struct<{
183
196
  }, {
184
197
  id: Struct<string | number | null, null>;
185
198
  jsonrpc: Struct<"2.0", "2.0">;
186
- result: Struct<Json, null>;
199
+ result: Struct<Json, unknown>;
187
200
  }>;
188
201
  /**
189
202
  * A successful JSON-RPC response object.
package/dist/json.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJsonRpcIdValidator = exports.assertIsJsonRpcError = exports.isJsonRpcError = exports.assertIsJsonRpcFailure = exports.isJsonRpcFailure = exports.assertIsJsonRpcSuccess = exports.isJsonRpcSuccess = exports.assertIsJsonRpcResponse = exports.isJsonRpcResponse = exports.assertIsPendingJsonRpcResponse = exports.isPendingJsonRpcResponse = exports.JsonRpcResponseStruct = exports.JsonRpcFailureStruct = exports.JsonRpcSuccessStruct = exports.PendingJsonRpcResponseStruct = exports.assertIsJsonRpcRequest = exports.isJsonRpcRequest = exports.assertIsJsonRpcNotification = exports.isJsonRpcNotification = exports.JsonRpcNotificationStruct = exports.JsonRpcRequestStruct = exports.JsonRpcParamsStruct = exports.JsonRpcErrorStruct = exports.JsonRpcIdStruct = exports.JsonRpcVersionStruct = exports.jsonrpc2 = exports.getJsonSize = exports.isValidJson = exports.JsonStruct = exports.UnsafeJsonStruct = void 0;
3
+ exports.getJsonRpcIdValidator = exports.assertIsJsonRpcError = exports.isJsonRpcError = exports.assertIsJsonRpcFailure = exports.isJsonRpcFailure = exports.assertIsJsonRpcSuccess = exports.isJsonRpcSuccess = exports.assertIsJsonRpcResponse = exports.isJsonRpcResponse = exports.assertIsPendingJsonRpcResponse = exports.isPendingJsonRpcResponse = exports.JsonRpcResponseStruct = exports.JsonRpcFailureStruct = exports.JsonRpcSuccessStruct = exports.PendingJsonRpcResponseStruct = exports.assertIsJsonRpcRequest = exports.isJsonRpcRequest = exports.assertIsJsonRpcNotification = exports.isJsonRpcNotification = exports.JsonRpcNotificationStruct = exports.JsonRpcRequestStruct = exports.JsonRpcParamsStruct = exports.JsonRpcErrorStruct = exports.JsonRpcIdStruct = exports.JsonRpcVersionStruct = exports.jsonrpc2 = exports.getJsonSize = exports.getSafeJson = exports.isValidJson = exports.JsonStruct = exports.UnsafeJsonStruct = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
5
  const assert_1 = require("./assert");
6
6
  /**
@@ -32,48 +32,9 @@ exports.UnsafeJsonStruct = (0, superstruct_1.union)([
32
32
  * This struct sanitizes the value before validating it, so that it is safe to
33
33
  * use with untrusted input.
34
34
  */
35
- exports.JsonStruct = (0, superstruct_1.define)('Json', (value, context) => {
36
- /**
37
- * Helper function that runs the given struct validator and returns the
38
- * validation errors, if any. If the value is valid, it returns `true`.
39
- *
40
- * @param innerValue - The value to validate.
41
- * @param struct - The struct to use for validation.
42
- * @returns The validation errors, or `true` if the value is valid.
43
- */
44
- function checkStruct(innerValue, struct) {
45
- const iterator = struct.validator(innerValue, context);
46
- const errors = [...iterator];
47
- if (errors.length > 0) {
48
- return errors;
49
- }
50
- return true;
51
- }
52
- try {
53
- // The plain value must be a valid JSON value, but it may be altered in the
54
- // process of JSON serialization, so we need to validate it again after
55
- // serialization. This has the added benefit that the returned error messages
56
- // will be more helpful, as they will point to the exact location of the
57
- // invalid value.
58
- //
59
- // This seems overcomplicated, but without checking the plain value first,
60
- // there are some cases where the validation passes, even though the value is
61
- // not valid JSON. For example, `undefined` is not valid JSON, but serializing
62
- // it will remove it from the object, so the validation will pass.
63
- const unsafeResult = checkStruct(value, exports.UnsafeJsonStruct);
64
- if (unsafeResult !== true) {
65
- return unsafeResult;
66
- }
67
- // JavaScript engines are highly optimized for this specific use case of
68
- // JSON parsing and stringifying, so there should be no performance impact.
69
- return checkStruct(JSON.parse(JSON.stringify(value)), exports.UnsafeJsonStruct);
70
- }
71
- catch (error) {
72
- if (error instanceof RangeError) {
73
- return 'Circular reference detected';
74
- }
75
- return false;
76
- }
35
+ exports.JsonStruct = (0, superstruct_1.coerce)(exports.UnsafeJsonStruct, (0, superstruct_1.any)(), (value) => {
36
+ (0, assert_1.assertStruct)(value, exports.UnsafeJsonStruct);
37
+ return JSON.parse(JSON.stringify(value));
77
38
  });
78
39
  /**
79
40
  * Check if the given value is a valid {@link Json} value, i.e., a value that is
@@ -83,9 +44,31 @@ exports.JsonStruct = (0, superstruct_1.define)('Json', (value, context) => {
83
44
  * @returns Whether the value is a valid {@link Json} value.
84
45
  */
85
46
  function isValidJson(value) {
86
- return (0, superstruct_1.is)(value, exports.JsonStruct);
47
+ try {
48
+ getSafeJson(value);
49
+ return true;
50
+ }
51
+ catch {
52
+ return false;
53
+ }
87
54
  }
88
55
  exports.isValidJson = isValidJson;
56
+ /**
57
+ * Validate and return sanitized JSON.
58
+ *
59
+ * Note:
60
+ * This function uses sanitized JsonStruct for validation
61
+ * that applies stringify and then parse of a value provided
62
+ * to ensure that there are no getters which can have side effects
63
+ * that can cause security issues.
64
+ *
65
+ * @param value - JSON structure to be processed.
66
+ * @returns Sanitized JSON structure.
67
+ */
68
+ function getSafeJson(value) {
69
+ return (0, superstruct_1.create)(value, exports.JsonStruct);
70
+ }
71
+ exports.getSafeJson = getSafeJson;
89
72
  /**
90
73
  * Get the size of a JSON value in bytes. This also validates the value.
91
74
  *
@@ -333,7 +316,12 @@ exports.assertIsJsonRpcError = assertIsJsonRpcError;
333
316
  * @returns The JSON-RPC ID validator function.
334
317
  */
335
318
  function getJsonRpcIdValidator(options) {
336
- const { permitEmptyString, permitFractions, permitNull } = Object.assign({ permitEmptyString: true, permitFractions: false, permitNull: true }, options);
319
+ const { permitEmptyString, permitFractions, permitNull } = {
320
+ permitEmptyString: true,
321
+ permitFractions: false,
322
+ permitNull: true,
323
+ ...options,
324
+ };
337
325
  /**
338
326
  * Type guard for {@link JsonRpcId}.
339
327
  *