@loaders.gl/crypto 4.1.0-alpha.2 → 4.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crypto-worker.js +1 -1
- package/dist/crypto-worker.js.map +3 -3
- package/dist/dist.dev.js +28 -26
- package/dist/index.cjs +27 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/algorithms/crc32.d.ts.map +1 -1
- package/dist/lib/algorithms/crc32.js +1 -1
- package/dist/lib/algorithms/crc32.js.map +1 -1
- package/dist/lib/algorithms/crc32c.d.ts.map +1 -1
- package/dist/lib/algorithms/crc32c.js.map +1 -1
- package/dist/lib/algorithms/md5-wasm.d.ts.map +1 -1
- package/dist/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/lib/crc32-hash.d.ts +0 -1
- package/dist/lib/crc32-hash.d.ts.map +1 -1
- package/dist/lib/crc32-hash.js +7 -8
- package/dist/lib/crc32-hash.js.map +1 -1
- package/dist/lib/crc32c-hash.d.ts +0 -1
- package/dist/lib/crc32c-hash.d.ts.map +1 -1
- package/dist/lib/crc32c-hash.js +7 -8
- package/dist/lib/crc32c-hash.js.map +1 -1
- package/dist/lib/crypto-hash.d.ts +3 -1
- package/dist/lib/crypto-hash.d.ts.map +1 -1
- package/dist/lib/crypto-hash.js +13 -11
- package/dist/lib/crypto-hash.js.map +1 -1
- package/dist/lib/hash.d.ts.map +1 -1
- package/dist/lib/hash.js.map +1 -1
- package/dist/lib/md5-hash.d.ts.map +1 -1
- package/dist/lib/md5-hash.js.map +1 -1
- package/dist/lib/node-hash.d.ts.map +1 -1
- package/dist/lib/node-hash.js.map +1 -1
- package/dist/lib/sha256-hash.d.ts.map +1 -1
- package/dist/lib/sha256-hash.js.map +1 -1
- package/dist/lib/utils/base64-utils.d.ts.map +1 -1
- package/dist/lib/utils/base64-utils.js.map +1 -1
- package/dist/lib/utils/digest-utils.d.ts.map +1 -1
- package/dist/lib/utils/digest-utils.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/workers/crypto-worker.d.ts.map +1 -1
- package/dist/workers/crypto-worker.js.map +1 -1
- package/dist/workers/cryptojs-worker.ts.disabled +2 -1
- package/package.json +4 -4
- package/src/index.ts +2 -1
- package/src/lib/algorithms/crc32.ts +10 -3
- package/src/lib/algorithms/crc32c.ts +2 -1
- package/src/lib/algorithms/md5-wasm.ts +2 -1
- package/src/lib/crc32-hash.ts +9 -9
- package/src/lib/crc32c-hash.ts +9 -9
- package/src/lib/crypto-hash.ts +20 -11
- package/src/lib/hash.ts +2 -1
- package/src/lib/md5-hash.ts +2 -1
- package/src/lib/node-hash.ts +2 -1
- package/src/lib/sha256-hash.ts +2 -1
- package/src/lib/utils/base64-utils.ts +2 -1
- package/src/lib/utils/digest-utils.ts +2 -1
- package/src/types.ts +2 -1
- package/src/workers/crypto-worker.ts +2 -1
- package/src/workers/cryptojs-worker.ts.disabled +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-hash.d.ts","sourceRoot":"","sources":["../../src/lib/node-hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-hash.d.ts","sourceRoot":"","sources":["../../src/lib/node-hash.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAE5B,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE;QACN,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAAG,CAAC;KACzC,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,qBAAa,QAAS,SAAQ,IAAI;IAChC,QAAQ,CAAC,IAAI,MAAC;IACd,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;gBAEtB,OAAO,EAAE,eAAe;IASpC;;;OAGG;IACG,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAG5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-hash.js","names":["Hash","NodeHash","constructor","options","name","globalThis","loaders","Error","hash","input","encoding"],"sources":["../../src/lib/node-hash.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"node-hash.js","names":["Hash","NodeHash","constructor","options","name","globalThis","loaders","Error","hash","input","encoding"],"sources":["../../src/lib/node-hash.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {Hash} from './hash';\n\ntype NodeHashOptions = {\n crypto: {\n algorithm: string;\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\n/**\n * A transform that calculates Cryptographic Hash using Node's Crypto library\n * @deprecated Only available in Node.js\n */\nexport class NodeHash extends Hash {\n readonly name;\n readonly options: NodeHashOptions;\n\n constructor(options: NodeHashOptions) {\n super();\n this.options = options;\n if (!globalThis.loaders.NodeHash) {\n throw new Error('install @loaders.gl/crypto on Node.js to use NodeHash');\n }\n return new globalThis.loaders.NodeHash(options);\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string> {\n throw new Error('Not implemented');\n }\n}\n"],"mappings":"SAIQA,IAAI;AAaZ,OAAO,MAAMC,QAAQ,SAASD,IAAI,CAAC;EAIjCE,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAAC,CAAC;IAAC,KAJDC,IAAI;IAAA,KACJD,OAAO;IAId,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACE,UAAU,CAACC,OAAO,CAACL,QAAQ,EAAE;MAChC,MAAM,IAAIM,KAAK,CAAC,uDAAuD,CAAC;IAC1E;IACA,OAAO,IAAIF,UAAU,CAACC,OAAO,CAACL,QAAQ,CAACE,OAAO,CAAC;EACjD;EAMA,MAAMK,IAAIA,CAACC,KAAkB,EAAEC,QAA0B,EAAmB;IAC1E,MAAM,IAAIH,KAAK,CAAC,iBAAiB,CAAC;EACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha256-hash.d.ts","sourceRoot":"","sources":["../../src/lib/sha256-hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sha256-hash.d.ts","sourceRoot":"","sources":["../../src/lib/sha256-hash.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACrC,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC,KAAK,GAAG,CAAC;KACzC,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,qBAAa,UAAW,SAAQ,UAAU;gBAC5B,OAAO,EAAE,iBAAiB;CAGvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha256-hash.js","names":["CryptoHash","SHA256Hash","constructor","options","crypto","algorithm"],"sources":["../../src/lib/sha256-hash.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"sha256-hash.js","names":["CryptoHash","SHA256Hash","constructor","options","crypto","algorithm"],"sources":["../../src/lib/sha256-hash.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {CryptoHash} from './crypto-hash';\n\ntype CryptoHashOptions = {\n modules: {[moduleName: string]: any};\n crypto?: {\n onEnd?: (result: {hash: string}) => any;\n };\n};\n\n/**\n * A transform that calculates Cryptographic Hash\n */\nexport class SHA256Hash extends CryptoHash {\n constructor(options: CryptoHashOptions) {\n super({...options, crypto: {...options.crypto, algorithm: 'SHA256'}});\n }\n}\n"],"mappings":"SAIQA,UAAU;AAYlB,OAAO,MAAMC,UAAU,SAASD,UAAU,CAAC;EACzCE,WAAWA,CAACC,OAA0B,EAAE;IACtC,KAAK,CAAC;MAAC,GAAGA,OAAO;MAAEC,MAAM,EAAE;QAAC,GAAGD,OAAO,CAACC,MAAM;QAAEC,SAAS,EAAE;MAAQ;IAAC,CAAC,CAAC;EACvE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/base64-utils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkC3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4ElD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-utils.js","names":["asciiToBase64","string","i","length","charCodeAt","out","groupsOfSix","undefined","j","btoaLookup","base64ToAscii","data","replace","test","output","buffer","accumulatedBits","atobLookup","String","fromCharCode","keystr","chr","index","indexOf","idx"],"sources":["../../../src/lib/utils/base64-utils.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"base64-utils.js","names":["asciiToBase64","string","i","length","charCodeAt","out","groupsOfSix","undefined","j","btoaLookup","base64ToAscii","data","replace","test","output","buffer","accumulatedBits","atobLookup","String","fromCharCode","keystr","chr","index","indexOf","idx"],"sources":["../../../src/lib/utils/base64-utils.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/**\n * `btoa()` polyfill as defined by the HTML and Infra specs, which mostly just references\n * RFC 4648.\n */\nexport function asciiToBase64(string: string): string | null {\n // String conversion as required by Web IDL.\n string = `${string}`;\n // \"The btoa() method must throw an \"InvalidCharacterError\" DOMException if\n // data contains any character whose code point is greater than U+00FF.\"\n for (let i = 0; i < string.length; i++) {\n if (string.charCodeAt(i) > 255) {\n return null;\n }\n }\n let out = '';\n for (let i = 0; i < string.length; i += 3) {\n /** @type {Array[4]} */\n const groupsOfSix: (number | undefined)[] = [undefined, undefined, undefined, undefined];\n groupsOfSix[0] = string.charCodeAt(i) >> 2;\n groupsOfSix[1] = (string.charCodeAt(i) & 0x03) << 4;\n if (string.length > i + 1) {\n groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;\n groupsOfSix[2] = (string.charCodeAt(i + 1) & 0x0f) << 2;\n }\n if (string.length > i + 2) {\n // @ts-expect-error\n groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;\n groupsOfSix[3] = string.charCodeAt(i + 2) & 0x3f;\n }\n for (let j = 0; j < groupsOfSix.length; j++) {\n if (typeof groupsOfSix[j] === 'undefined') {\n out += '=';\n } else {\n out += btoaLookup(groupsOfSix[j]);\n }\n }\n }\n return out;\n}\n\n/**\n * Implementation of atob() according to the HTML and Infra specs, except that\n * instead of throwing INVALID_CHARACTER_ERR we return null.\n *\n * @note Forked from https://github.com/jsdom/abab under BSD 3 clause license\n */\nexport function base64ToAscii(data: string): string {\n // Web IDL requires DOMStrings to just be converted using ECMAScript\n // ToString, which in our case amounts to using a template literal.\n data = `${data}`;\n // \"Remove all ASCII whitespace from data.\"\n data = data.replace(/[ \\t\\n\\f\\r]/g, '');\n // \"If data's code point length divides by 4 leaving no remainder, then: if data ends\n // with one or two U+003D (=) code points, then remove them from data.\"\n if (data.length % 4 === 0) {\n data = data.replace(/[=]=?$/, '');\n }\n // \"If data's code point length divides by 4 leaving a remainder of 1, then return\n // failure.\"\n //\n // \"If data contains a code point that is not one of\n //\n // U+002B (+)\n // U+002F (/)\n // ASCII alphanumeric\n //\n // then return failure.\"\n if (data.length % 4 === 1 || /[^+/0-9A-Za-z]/.test(data)) {\n return '';\n }\n // \"Let output be an empty byte sequence.\"\n let output = '';\n // \"Let buffer be an empty buffer that can have bits appended to it.\"\n //\n // We append bits via left-shift and or. accumulatedBits is used to track\n // when we've gotten to 24 bits.\n let buffer = 0;\n let accumulatedBits = 0;\n // \"Let position be a position variable for data, initially pointing at the\n // start of data.\"\n //\n // \"While position does not point past the end of data:\"\n for (let i = 0; i < data.length; i++) {\n // \"Find the code point pointed to by position in the second column of\n // Table 1: The Base 64 Alphabet of RFC 4648. Let n be the number given in\n // the first cell of the same row.\n //\n // \"Append to buffer the six bits corresponding to n, most significant bit\n // first.\"\n //\n // atobLookup() implements the table from RFC 4648.\n buffer <<= 6;\n // @ts-expect-error\n buffer |= atobLookup(data[i]);\n accumulatedBits += 6;\n // \"If buffer has accumulated 24 bits, interpret them as three 8-bit\n // big-endian numbers. Append three bytes with values equal to those\n // numbers to output, in the same order, and then empty buffer.\"\n if (accumulatedBits === 24) {\n output += String.fromCharCode((buffer & 0xff0000) >> 16);\n output += String.fromCharCode((buffer & 0xff00) >> 8);\n output += String.fromCharCode(buffer & 0xff);\n buffer = accumulatedBits = 0;\n }\n // \"Advance position by 1.\"\n }\n // \"If buffer is not empty, it contains either 12 or 18 bits. If it contains\n // 12 bits, then discard the last four and interpret the remaining eight as\n // an 8-bit big-endian number. If it contains 18 bits, then discard the last\n // two and interpret the remaining 16 as two 8-bit big-endian numbers. Append\n // the one or two bytes with values equal to those one or two numbers to\n // output, in the same order.\"\n if (accumulatedBits === 12) {\n buffer >>= 4;\n output += String.fromCharCode(buffer);\n } else if (accumulatedBits === 18) {\n buffer >>= 2;\n output += String.fromCharCode((buffer & 0xff00) >> 8);\n output += String.fromCharCode(buffer & 0xff);\n }\n // \"Return output.\"\n return output;\n}\n/**\n * A lookup table for atob(), which converts an ASCII character to the\n * corresponding six-bit number.\n */\n\nconst keystr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nfunction atobLookup(chr: string): number | undefined {\n const index = keystr.indexOf(chr);\n // Throw exception if character is not in the lookup string; should not be hit in tests\n return index < 0 ? undefined : index;\n}\n\n/**\n * Lookup table for btoa(), which converts a six-bit number into the\n * corresponding ASCII character.\n */\nfunction btoaLookup(idx) {\n if (idx < 26) {\n return String.fromCharCode(idx + 'A'.charCodeAt(0));\n }\n if (idx < 52) {\n return String.fromCharCode(idx - 26 + 'a'.charCodeAt(0));\n }\n if (idx < 62) {\n return String.fromCharCode(idx - 52 + '0'.charCodeAt(0));\n }\n if (idx === 62) {\n return '+';\n }\n if (idx === 63) {\n return '/';\n }\n // Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the teststring.\n return undefined;\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/digest-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"digest-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/digest-utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAS/E;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CASzE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAS/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-utils.js","names":["asciiToBase64","base64ToAscii","encodeNumber","number","encoding","convertNumberToHex","convertHexToBase64","Error","encodeHex","hex","encodeBase64","base64","convertBase64ToHex","hexstring","length","matches","match","string","map","a","String","fromCharCode","parseInt","join","base64String","c","charCodeAt","toString","padStart","cipher","hexString"],"sources":["../../../src/lib/utils/digest-utils.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"digest-utils.js","names":["asciiToBase64","base64ToAscii","encodeNumber","number","encoding","convertNumberToHex","convertHexToBase64","Error","encodeHex","hex","encodeBase64","base64","convertBase64ToHex","hexstring","length","matches","match","string","map","a","String","fromCharCode","parseInt","join","base64String","c","charCodeAt","toString","padStart","cipher","hexString"],"sources":["../../../src/lib/utils/digest-utils.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {asciiToBase64, base64ToAscii} from './base64-utils';\n\n/**\n * Encode a number (usually a digest from a hash function / cipher) as either hex or base64\n * Suitable for hashes like CRC32 where the number of required bits fit withing a JavaScript number.\n */\nexport function encodeNumber(number: number, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return convertNumberToHex(number);\n case 'base64':\n return convertHexToBase64(convertNumberToHex(number));\n default:\n throw new Error(encoding);\n }\n}\n\n/** Encode a hex string, aeither return hex or re-encode as base64 */\nexport function encodeHex(hex: string, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return hex;\n case 'base64':\n return convertHexToBase64(hex);\n default:\n throw new Error(encoding);\n }\n}\n\nexport function encodeBase64(base64: string, encoding: 'hex' | 'base64'): string {\n switch (encoding) {\n case 'hex':\n return convertBase64ToHex(base64);\n case 'base64':\n return base64;\n default:\n throw new Error(encoding);\n }\n}\n\n/**\n * Convert a hexadecimal string to base64 encoded string representation\n */\nfunction convertHexToBase64(hexstring: string): string {\n // Add leading zero to keep even count of digits\n // eg. f85d741 => 0f85d741\n if (hexstring.length % 2 !== 0) {\n hexstring = `0${hexstring}`;\n }\n const matches = hexstring.match(/\\w{2}/g) || [];\n const string = matches.map((a) => String.fromCharCode(parseInt(a, 16))).join('');\n // TODO - define how to handle failures\n return asciiToBase64(string) || '';\n}\n\n/**\n * Convert a base64 encoded string to hexadecimal encoded string representation\n */\nfunction convertBase64ToHex(base64String: string): string {\n return [...base64ToAscii(base64String)]\n .map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))\n .join('');\n}\n\n/**\n * Converts a number to hex\n */\nfunction convertNumberToHex(cipher: number): string {\n const hexString = cipher.toString(16);\n return hexString === '0' ? `0${hexString}` : hexString;\n}\n"],"mappings":"SAIQA,aAAa,EAAEC,aAAa;AAMpC,OAAO,SAASC,YAAYA,CAACC,MAAc,EAAEC,QAA0B,EAAU;EAC/E,QAAQA,QAAQ;IACd,KAAK,KAAK;MACR,OAAOC,kBAAkB,CAACF,MAAM,CAAC;IACnC,KAAK,QAAQ;MACX,OAAOG,kBAAkB,CAACD,kBAAkB,CAACF,MAAM,CAAC,CAAC;IACvD;MACE,MAAM,IAAII,KAAK,CAACH,QAAQ,CAAC;EAC7B;AACF;AAGA,OAAO,SAASI,SAASA,CAACC,GAAW,EAAEL,QAA0B,EAAU;EACzE,QAAQA,QAAQ;IACd,KAAK,KAAK;MACR,OAAOK,GAAG;IACZ,KAAK,QAAQ;MACX,OAAOH,kBAAkB,CAACG,GAAG,CAAC;IAChC;MACE,MAAM,IAAIF,KAAK,CAACH,QAAQ,CAAC;EAC7B;AACF;AAEA,OAAO,SAASM,YAAYA,CAACC,MAAc,EAAEP,QAA0B,EAAU;EAC/E,QAAQA,QAAQ;IACd,KAAK,KAAK;MACR,OAAOQ,kBAAkB,CAACD,MAAM,CAAC;IACnC,KAAK,QAAQ;MACX,OAAOA,MAAM;IACf;MACE,MAAM,IAAIJ,KAAK,CAACH,QAAQ,CAAC;EAC7B;AACF;AAKA,SAASE,kBAAkBA,CAACO,SAAiB,EAAU;EAGrD,IAAIA,SAAS,CAACC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;IAC9BD,SAAS,GAAI,IAAGA,SAAU,EAAC;EAC7B;EACA,MAAME,OAAO,GAAGF,SAAS,CAACG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE;EAC/C,MAAMC,MAAM,GAAGF,OAAO,CAACG,GAAG,CAAEC,CAAC,IAAKC,MAAM,CAACC,YAAY,CAACC,QAAQ,CAACH,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAACI,IAAI,CAAC,EAAE,CAAC;EAEhF,OAAOvB,aAAa,CAACiB,MAAM,CAAC,IAAI,EAAE;AACpC;AAKA,SAASL,kBAAkBA,CAACY,YAAoB,EAAU;EACxD,OAAO,CAAC,GAAGvB,aAAa,CAACuB,YAAY,CAAC,CAAC,CACpCN,GAAG,CAAEO,CAAC,IAAKA,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CACzDL,IAAI,CAAC,EAAE,CAAC;AACb;AAKA,SAASlB,kBAAkBA,CAACwB,MAAc,EAAU;EAClD,MAAMC,SAAS,GAAGD,MAAM,CAACF,QAAQ,CAAC,EAAE,CAAC;EACrC,OAAOG,SAAS,KAAK,GAAG,GAAI,IAAGA,SAAU,EAAC,GAAGA,SAAS;AACxD"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IACtC,MAAM,CAAC,EAAE;QACP,SAAS,MAAC;QACV,KAAK,CAAC,MAAC;KACR,CAAC;CACH,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nexport type CryptoHashOptions = {\n modules?: {[moduleName: string]: any};\n crypto?: {\n algorithm;\n onEnd?;\n };\n};\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-worker.d.ts","sourceRoot":"","sources":["../../src/workers/crypto-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto-worker.d.ts","sourceRoot":"","sources":["../../src/workers/crypto-worker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAI9C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-worker.js","names":["createWorker","CRC32Hash","CRC32CHash","MD5Hash","data","options","arguments","length","undefined","operation","encoding","hash","Error"],"sources":["../../src/workers/crypto-worker.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"crypto-worker.js","names":["createWorker","CRC32Hash","CRC32CHash","MD5Hash","data","options","arguments","length","undefined","operation","encoding","hash","Error"],"sources":["../../src/workers/crypto-worker.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '@loaders.gl/worker-utils';\nimport {CRC32Hash} from '../lib/crc32-hash';\nimport {CRC32CHash} from '../lib/crc32c-hash';\nimport {MD5Hash} from '../lib/md5-hash';\n\n// Assuming we can bundle as module\nexport {CRC32Hash, CRC32CHash};\n\ncreateWorker(async (data, options = {}) => {\n // @ts-ignore\n const {operation, encoding = 'base64'} = options;\n\n switch (operation) {\n case 'crc32':\n return await new CRC32Hash(options).hash(data, encoding);\n case 'crc32c':\n return await new CRC32CHash(options).hash(data, encoding);\n case 'md5':\n return await new MD5Hash(options).hash(data, encoding);\n default:\n throw new Error(`invalid option: ${operation}`);\n }\n});\n"],"mappings":"AAIA,SAAQA,YAAY,QAAO,0BAA0B;AAAC,SAC9CC,SAAS;AAAA,SACTC,UAAU;AAAA,SACVC,OAAO;AAGf,SAAQF,SAAS,EAAEC,UAAU;AAE7BF,YAAY,CAAC,gBAAOI,IAAI,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEpC,MAAM;IAACG,SAAS;IAAEC,QAAQ,GAAG;EAAQ,CAAC,GAAGL,OAAO;EAEhD,QAAQI,SAAS;IACf,KAAK,OAAO;MACV,OAAO,MAAM,IAAIR,SAAS,CAACI,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IAC1D,KAAK,QAAQ;MACX,OAAO,MAAM,IAAIR,UAAU,CAACG,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IAC3D,KAAK,KAAK;MACR,OAAO,MAAM,IAAIP,OAAO,CAACE,OAAO,CAAC,CAACM,IAAI,CAACP,IAAI,EAAEM,QAAQ,CAAC;IACxD;MACE,MAAM,IAAIE,KAAK,CAAE,mBAAkBH,SAAU,EAAC,CAAC;EACnD;AACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/crypto",
|
|
3
|
-
"version": "4.1.0-alpha.
|
|
3
|
+
"version": "4.1.0-alpha.4",
|
|
4
4
|
"description": "Cryptographic/hashing plugins for loaders.gl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@babel/runtime": "^7.3.1",
|
|
49
|
-
"@loaders.gl/loader-utils": "4.1.0-alpha.
|
|
50
|
-
"@loaders.gl/worker-utils": "4.1.0-alpha.
|
|
49
|
+
"@loaders.gl/loader-utils": "4.1.0-alpha.4",
|
|
50
|
+
"@loaders.gl/worker-utils": "4.1.0-alpha.4",
|
|
51
51
|
"@types/crypto-js": "^4.0.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"crypto": false,
|
|
58
58
|
"sse4_crc32": false
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "b18ba1d63be704fd021e4470e8ab84175621e62d"
|
|
61
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
// Inspired by https://gist.github.com/wqli78/1330293/6d85cc967f32cccfcbad94ae7d088a3dcfc14bd9
|
|
5
|
-
|
|
6
|
+
// Full crc32 docs: https://www.kernel.org/doc/Documentation/crc32.txt
|
|
7
|
+
// Better JS implementation: https://stackoverflow.com/a/18639999
|
|
6
8
|
/**
|
|
7
9
|
* Calculates the CRC32 checksum of a string.
|
|
8
10
|
*/
|
|
@@ -24,7 +26,12 @@ export default class CRC32 {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
finalize() {
|
|
27
|
-
|
|
29
|
+
// performing final division and making crc unsigned.
|
|
30
|
+
// The reason why we can't use Math.abs() ther is that 1 in bite representation is 00000000000000000000000000000001
|
|
31
|
+
// and -1 is 11111111111111111111111111111111. So Math.abs() completely changes the bits there,
|
|
32
|
+
// but what we need is just make JS count first 1 bit as a part of a number and not the sign marker.
|
|
33
|
+
// We don't need to change anything else in this bit representation. And that's exactly what >>> does.
|
|
34
|
+
this.crc = (this.crc ^ -1) >>> 0;
|
|
28
35
|
return this.crc;
|
|
29
36
|
}
|
|
30
37
|
}
|
package/src/lib/crc32-hash.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {Hash} from './hash';
|
|
@@ -12,12 +13,10 @@ export class CRC32Hash extends Hash {
|
|
|
12
13
|
readonly name = 'crc32';
|
|
13
14
|
|
|
14
15
|
options;
|
|
15
|
-
private _hash: CRC32;
|
|
16
16
|
|
|
17
17
|
constructor(options = {}) {
|
|
18
18
|
super();
|
|
19
19
|
this.options = {crypto: {}, ...options};
|
|
20
|
-
this._hash = new CRC32();
|
|
21
20
|
this.hashBatches = this.hashBatches.bind(this);
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -30,8 +29,9 @@ export class CRC32Hash extends Hash {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
hashSync(input: ArrayBuffer, encoding: 'hex' | 'base64'): string {
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const hash = new CRC32();
|
|
33
|
+
hash.update(input);
|
|
34
|
+
const digest = hash.finalize();
|
|
35
35
|
return encodeNumber(digest, encoding);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -39,12 +39,12 @@ export class CRC32Hash extends Hash {
|
|
|
39
39
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
40
40
|
encoding: 'hex' | 'base64' = 'base64'
|
|
41
41
|
): AsyncIterable<ArrayBuffer> {
|
|
42
|
+
const hash = new CRC32();
|
|
42
43
|
for await (const chunk of asyncIterator) {
|
|
43
|
-
|
|
44
|
+
hash.update(chunk);
|
|
44
45
|
yield chunk;
|
|
45
46
|
}
|
|
46
|
-
const digest =
|
|
47
|
-
|
|
48
|
-
this.options.crypto?.onEnd?.({hash});
|
|
47
|
+
const digest = hash.finalize();
|
|
48
|
+
this.options.crypto?.onEnd?.({hash: encodeNumber(digest, encoding)});
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/lib/crc32c-hash.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {Hash} from './hash';
|
|
@@ -12,7 +13,6 @@ export class CRC32CHash extends Hash {
|
|
|
12
13
|
readonly name = 'crc32c';
|
|
13
14
|
|
|
14
15
|
options;
|
|
15
|
-
private _hash: CRC32C;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Atomic hash calculation
|
|
@@ -21,7 +21,6 @@ export class CRC32CHash extends Hash {
|
|
|
21
21
|
constructor(options = {}) {
|
|
22
22
|
super();
|
|
23
23
|
this.options = {crypto: {}, ...options};
|
|
24
|
-
this._hash = new CRC32C(options);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
@@ -33,8 +32,9 @@ export class CRC32CHash extends Hash {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
hashSync(input: ArrayBuffer, encoding: 'hex' | 'base64'): string {
|
|
36
|
-
this.
|
|
37
|
-
|
|
35
|
+
const hash = new CRC32C(this.options);
|
|
36
|
+
hash.update(input);
|
|
37
|
+
const digest = hash.finalize();
|
|
38
38
|
return encodeNumber(digest, encoding);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -44,12 +44,12 @@ export class CRC32CHash extends Hash {
|
|
|
44
44
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
45
45
|
encoding: 'hex' | 'base64' = 'base64'
|
|
46
46
|
): AsyncIterable<ArrayBuffer> {
|
|
47
|
+
const hash = new CRC32C(this.options);
|
|
47
48
|
for await (const chunk of asyncIterator) {
|
|
48
|
-
|
|
49
|
+
hash.update(chunk);
|
|
49
50
|
yield chunk;
|
|
50
51
|
}
|
|
51
|
-
const digest =
|
|
52
|
-
|
|
53
|
-
this.options.crypto?.onEnd?.({hash});
|
|
52
|
+
const digest = hash.finalize();
|
|
53
|
+
this.options.crypto?.onEnd?.({hash: encodeNumber(digest, encoding)});
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/lib/crypto-hash.ts
CHANGED
|
@@ -18,8 +18,10 @@ export class CryptoHash extends Hash {
|
|
|
18
18
|
readonly name;
|
|
19
19
|
|
|
20
20
|
options: CryptoHashOptions;
|
|
21
|
+
/** Name of digest algorithm */
|
|
21
22
|
private _algorithm;
|
|
22
|
-
|
|
23
|
+
/** CryptoJS algorithm */
|
|
24
|
+
private _algo;
|
|
23
25
|
|
|
24
26
|
constructor(options: CryptoHashOptions) {
|
|
25
27
|
super();
|
|
@@ -38,13 +40,7 @@ export class CryptoHash extends Hash {
|
|
|
38
40
|
if (!CryptoJS) {
|
|
39
41
|
throw new Error(this.name);
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
const algo = CryptoJS.algo[this._algorithm];
|
|
43
|
-
this._hash = algo.create();
|
|
44
|
-
}
|
|
45
|
-
if (!this._hash) {
|
|
46
|
-
throw new Error(this.name);
|
|
47
|
-
}
|
|
43
|
+
this._algo = CryptoJS.algo[this._algorithm];
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
/**
|
|
@@ -53,12 +49,18 @@ export class CryptoHash extends Hash {
|
|
|
53
49
|
*/
|
|
54
50
|
async hash(input: ArrayBuffer, encoding: 'hex' | 'base64'): Promise<string> {
|
|
55
51
|
await this.preload();
|
|
52
|
+
|
|
53
|
+
const hash = this._algo.create();
|
|
54
|
+
if (!hash) {
|
|
55
|
+
throw new Error(this.name);
|
|
56
|
+
}
|
|
57
|
+
|
|
56
58
|
// arrayBuffer is accepted, even though types and docs say no
|
|
57
59
|
// https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
|
|
58
60
|
const typedWordArray = CryptoJS.lib.WordArray.create(input);
|
|
59
61
|
// Map our encoding constant to Crypto library
|
|
60
62
|
const enc = encoding === 'base64' ? CryptoJS.enc.Base64 : CryptoJS.enc.Hex;
|
|
61
|
-
return
|
|
63
|
+
return hash.update(typedWordArray).finalize().toString(enc);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
async *hashBatches(
|
|
@@ -66,16 +68,23 @@ export class CryptoHash extends Hash {
|
|
|
66
68
|
encoding: 'hex' | 'base64' = 'base64'
|
|
67
69
|
): AsyncIterable<ArrayBuffer> {
|
|
68
70
|
await this.preload();
|
|
71
|
+
|
|
72
|
+
const hash = this._algo.create();
|
|
73
|
+
if (!hash) {
|
|
74
|
+
throw new Error(this.name);
|
|
75
|
+
}
|
|
76
|
+
|
|
69
77
|
for await (const chunk of asyncIterator) {
|
|
70
78
|
// arrayBuffer is accepted, even though types and docs say no
|
|
71
79
|
// https://stackoverflow.com/questions/25567468/how-to-decrypt-an-arraybuffer
|
|
72
80
|
const typedWordArray = CryptoJS.lib.WordArray.create(chunk);
|
|
73
|
-
|
|
81
|
+
hash.update(typedWordArray);
|
|
74
82
|
yield chunk;
|
|
75
83
|
}
|
|
84
|
+
|
|
76
85
|
// Map our encoding constant to Crypto library
|
|
77
86
|
const enc = encoding === 'base64' ? CryptoJS.enc.Base64 : CryptoJS.enc.Hex;
|
|
78
|
-
const digest =
|
|
87
|
+
const digest = hash.finalize().toString(enc);
|
|
79
88
|
this.options?.crypto?.onEnd?.({hash: digest});
|
|
80
89
|
}
|
|
81
90
|
}
|
package/src/lib/hash.ts
CHANGED
package/src/lib/md5-hash.ts
CHANGED
package/src/lib/node-hash.ts
CHANGED
package/src/lib/sha256-hash.ts
CHANGED
package/src/types.ts
CHANGED