micro509 0.16.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +120 -1
  2. package/README.md +3 -0
  3. package/dist/internal/jose/base64url.js +40 -0
  4. package/dist/internal/jose/base64url.js.map +1 -0
  5. package/dist/internal/jose/strict-json.d.ts +9 -0
  6. package/dist/internal/jose/strict-json.js +155 -0
  7. package/dist/internal/jose/strict-json.js.map +1 -0
  8. package/dist/jose/errors.d.ts +44 -0
  9. package/dist/jose/errors.js +11 -0
  10. package/dist/jose/errors.js.map +1 -0
  11. package/dist/jose/jwks.d.ts +93 -0
  12. package/dist/jose/jwks.js +193 -0
  13. package/dist/jose/jwks.js.map +1 -0
  14. package/dist/jose/jws.d.ts +158 -0
  15. package/dist/jose/jws.js +362 -0
  16. package/dist/jose/jws.js.map +1 -0
  17. package/dist/jose/jwt.d.ts +91 -0
  18. package/dist/jose/jwt.js +187 -0
  19. package/dist/jose/jwt.js.map +1 -0
  20. package/dist/jose/remote-jwks.d.ts +95 -0
  21. package/dist/jose/remote-jwks.js +298 -0
  22. package/dist/jose/remote-jwks.js.map +1 -0
  23. package/dist/jose.d.ts +7 -0
  24. package/dist/jose.js +5 -0
  25. package/dist/kdf/argon2-arithmetic.js +15 -0
  26. package/dist/kdf/argon2-arithmetic.js.map +1 -0
  27. package/dist/kdf/argon2-core.js +486 -0
  28. package/dist/kdf/argon2-core.js.map +1 -0
  29. package/dist/kdf/argon2-memory.js +20 -0
  30. package/dist/kdf/argon2-memory.js.map +1 -0
  31. package/dist/kdf/argon2-portable.js +18 -0
  32. package/dist/kdf/argon2-portable.js.map +1 -0
  33. package/dist/kdf/argon2.d.ts +84 -0
  34. package/dist/kdf/argon2.js +186 -0
  35. package/dist/kdf/argon2.js.map +1 -0
  36. package/dist/kdf.d.ts +2 -0
  37. package/dist/kdf.js +1 -0
  38. package/dist/ssh/ssh.d.ts +200 -0
  39. package/dist/ssh/ssh.js +648 -0
  40. package/dist/ssh/ssh.js.map +1 -0
  41. package/dist/ssh/wire.d.ts +3 -0
  42. package/dist/ssh/wire.js +105 -0
  43. package/dist/ssh/wire.js.map +1 -0
  44. package/dist/ssh.d.ts +3 -0
  45. package/dist/ssh.js +1 -0
  46. package/package.json +24 -16
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2-core.js","names":["matrices","createMatrixPool","MASK_64","IV","SIGMA","ROUND_INDEXES","bytes","offset","value","index","parts","output","length","part","a","v","b","x","d","c","y","shift","bits","words","sigma","block","h","count","last","finalBlock","outputBytes","input","seed","next","password","salt","secret","associatedData","fields","values","type","tail","message","aLow","aHigh","bLow","bHigh","cLow","cHigh","dLow","dHigh","product","sum","low","high","multiplyHigh","stride","pair","memory","previousOffset","referenceOffset","permuted","withXor","destinationOffset","original","areaSize","pass","slice","segmentLength","sameLane","laneLength","squareHigh","pseudoRandom","relative","previous","reference","inputBlock","zero","addressTemporary","addressBlock","position","workspace","currentBlock","lane","pseudoOffset","pseudo","pseudoLow","referenceLane","referenceIndex","destinationBlock","independent","memoryBlocks","startingIndex","start","pause","resolve","end","h0","finalWords","suffix","lastOffset"],"sources":["../../src/kdf/argon2-core.ts"],"sourcesContent":["/**\n * Argon2 core: RFC 9106 sections 3.2–3.6, with version 0x10 compatibility.\n * BLAKE2b uses 64-bit BigInts; the memory matrix uses little-endian pairs of\n * 32-bit words. Each derivation owns its state and clears mutable work buffers.\n */\nimport type { Argon2Input } from '#micro509/kdf/argon2';\nimport { multiplyHigh } from '#micro509/kdf/argon2-arithmetic';\nimport { createMatrixPool } from '#micro509/kdf/argon2-memory';\n\nconst matrices = createMatrixPool();\n\nconst MASK_64 = 0xffff_ffff_ffff_ffffn;\nconst IV = [\n\t0x6a09e667f3bcc908n,\n\t0xbb67ae8584caa73bn,\n\t0x3c6ef372fe94f82bn,\n\t0xa54ff53a5f1d36f1n,\n\t0x510e527fade682d1n,\n\t0x9b05688c2b3e6c1fn,\n\t0x1f83d9abfb41bd6bn,\n\t0x5be0cd19137e2179n,\n];\nconst SIGMA = [\n\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],\n\t[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],\n\t[11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],\n\t[7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8],\n\t[9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13],\n\t[2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9],\n\t[12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11],\n\t[13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10],\n\t[6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5],\n\t[10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0],\n\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],\n\t[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],\n];\n// Column and diagonal quarter-round indexes shared by BLAKE2b and BlaMka.\nconst ROUND_INDEXES = [\n\t[0, 4, 8, 12],\n\t[1, 5, 9, 13],\n\t[2, 6, 10, 14],\n\t[3, 7, 11, 15],\n\t[0, 5, 10, 15],\n\t[1, 6, 11, 12],\n\t[2, 7, 8, 13],\n\t[3, 4, 9, 14],\n] as const;\ntype MutableWords = { length: number; [index: number]: bigint };\n\nfunction read32(bytes: Uint8Array, offset: number): number {\n\treturn (\n\t\t((bytes[offset] ?? 0) |\n\t\t\t((bytes[offset + 1] ?? 0) << 8) |\n\t\t\t((bytes[offset + 2] ?? 0) << 16) |\n\t\t\t((bytes[offset + 3] ?? 0) << 24)) >>>\n\t\t0\n\t);\n}\n\nfunction write32(bytes: Uint8Array, offset: number, value: number): void {\n\tbytes[offset] = value & 0xff;\n\tbytes[offset + 1] = (value >>> 8) & 0xff;\n\tbytes[offset + 2] = (value >>> 16) & 0xff;\n\tbytes[offset + 3] = value >>> 24;\n}\n\nfunction read64(bytes: Uint8Array, offset: number): bigint {\n\tlet value = 0n;\n\tfor (let index = 7; index >= 0; index -= 1) {\n\t\tvalue = (value << 8n) | BigInt(bytes[offset + index] ?? 0);\n\t}\n\treturn value;\n}\n\nfunction concat(...parts: Uint8Array[]): Uint8Array {\n\tconst output = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));\n\tlet offset = 0;\n\tfor (const part of parts) {\n\t\toutput.set(part, offset);\n\t\toffset += part.length;\n\t}\n\treturn output;\n}\n\nfunction blakeMix(\n\tv: MutableWords,\n\ta: number,\n\tb: number,\n\tc: number,\n\td: number,\n\tx: bigint,\n\ty: bigint,\n): void {\n\tv[a] = ((v[a] ?? 0n) + (v[b] ?? 0n) + x) & MASK_64;\n\tv[d] = rotateRight((v[d] ?? 0n) ^ (v[a] ?? 0n), 32);\n\tv[c] = ((v[c] ?? 0n) + (v[d] ?? 0n)) & MASK_64;\n\tv[b] = rotateRight((v[b] ?? 0n) ^ (v[c] ?? 0n), 24);\n\tv[a] = ((v[a] ?? 0n) + (v[b] ?? 0n) + y) & MASK_64;\n\tv[d] = rotateRight((v[d] ?? 0n) ^ (v[a] ?? 0n), 16);\n\tv[c] = ((v[c] ?? 0n) + (v[d] ?? 0n)) & MASK_64;\n\tv[b] = rotateRight((v[b] ?? 0n) ^ (v[c] ?? 0n), 63);\n}\n\nfunction rotateRight(value: bigint, bits: number): bigint {\n\tconst shift = BigInt(bits);\n\treturn ((value >> shift) | (value << (64n - shift))) & MASK_64;\n}\n\nfunction blakeRound(v: MutableWords, words: bigint[], sigma: number[]): void {\n\tfor (const [index, [a, b, c, d]] of ROUND_INDEXES.entries()) {\n\t\tblakeMix(\n\t\t\tv,\n\t\t\ta,\n\t\t\tb,\n\t\t\tc,\n\t\t\td,\n\t\t\twords[sigma[index * 2] ?? 0] ?? 0n,\n\t\t\twords[sigma[index * 2 + 1] ?? 0] ?? 0n,\n\t\t);\n\t}\n}\n\nfunction blake2bCompress(h: bigint[], block: Uint8Array, count: bigint, last: boolean): void {\n\tconst words = Array.from({ length: 16 }, (_, index) => read64(block, index * 8));\n\tconst v = [...h, ...IV];\n\ttry {\n\t\tv[12] = (v[12] ?? 0n) ^ (count & MASK_64);\n\t\tv[13] = (v[13] ?? 0n) ^ (count >> 64n);\n\t\tif (last) v[14] = (v[14] ?? 0n) ^ MASK_64;\n\t\tfor (const sigma of SIGMA) blakeRound(v, words, sigma);\n\t\tfor (let index = 0; index < 8; index += 1) {\n\t\t\th[index] = (h[index] ?? 0n) ^ (v[index] ?? 0n) ^ (v[index + 8] ?? 0n);\n\t\t}\n\t} finally {\n\t\twords.fill(0n);\n\t\tv.fill(0n);\n\t}\n}\n\nfunction blake2b(input: Uint8Array, outputBytes: number): Uint8Array {\n\tconst h = [...IV];\n\tconst finalBlock = new Uint8Array(128);\n\ttry {\n\t\th[0] = (h[0] ?? 0n) ^ (0x01010000n | BigInt(outputBytes));\n\t\tlet offset = 0;\n\t\twhile (input.length - offset > 128) {\n\t\t\tblake2bCompress(h, input.subarray(offset, offset + 128), BigInt(offset + 128), false);\n\t\t\toffset += 128;\n\t\t}\n\t\tfinalBlock.set(input.subarray(offset));\n\t\tblake2bCompress(h, finalBlock, BigInt(input.length), true);\n\t\tconst output = new Uint8Array(outputBytes);\n\t\tfor (let index = 0; index < outputBytes; index += 1) {\n\t\t\toutput[index] = Number(((h[Math.floor(index / 8)] ?? 0n) >> BigInt((index % 8) * 8)) & 0xffn);\n\t\t}\n\t\treturn output;\n\t} finally {\n\t\th.fill(0n);\n\t\tfinalBlock.fill(0);\n\t}\n}\n\nfunction blakeLong(input: Uint8Array, outputBytes: number): Uint8Array {\n\tconst seed = concat(\n\t\tUint8Array.from([\n\t\t\toutputBytes & 0xff,\n\t\t\t(outputBytes >>> 8) & 0xff,\n\t\t\t(outputBytes >>> 16) & 0xff,\n\t\t\toutputBytes >>> 24,\n\t\t]),\n\t\tinput,\n\t);\n\tlet value: Uint8Array<ArrayBufferLike> = new Uint8Array(0);\n\ttry {\n\t\tif (outputBytes <= 64) return blake2b(seed, outputBytes);\n\t\tvalue = blake2b(seed, 64);\n\t\tconst output = new Uint8Array(outputBytes);\n\t\tlet offset = 0;\n\t\twhile (outputBytes - offset > 64) {\n\t\t\toutput.set(value.subarray(0, 32), offset);\n\t\t\toffset += 32;\n\t\t\tif (outputBytes - offset > 64) {\n\t\t\t\tconst next = blake2b(value, 64);\n\t\t\t\tvalue.fill(0);\n\t\t\t\tvalue = next;\n\t\t\t}\n\t\t}\n\t\tconst last = blake2b(value, outputBytes - offset);\n\t\ttry {\n\t\t\toutput.set(last, offset);\n\t\t\treturn output;\n\t\t} finally {\n\t\t\tlast.fill(0);\n\t\t}\n\t} finally {\n\t\tseed.fill(0);\n\t\tvalue.fill(0);\n\t}\n}\n\nfunction initialHash(input: Argon2Input, type: number): Uint8Array {\n\tconst password = input.password;\n\tconst salt = input.salt;\n\tconst secret = input.secret ?? new Uint8Array();\n\tconst associatedData = input.associatedData ?? new Uint8Array();\n\tconst fields = new Uint8Array(28);\n\tconst values = [\n\t\tinput.parallelism,\n\t\tinput.outputBytes,\n\t\tinput.memoryKiB,\n\t\tinput.passes,\n\t\tinput.version,\n\t\ttype,\n\t\tpassword.length,\n\t];\n\tlet offset = 0;\n\tfor (const value of values) {\n\t\twrite32(fields, offset, value);\n\t\toffset += 4;\n\t}\n\tconst tail = new Uint8Array(12);\n\twrite32(tail, 0, salt.length);\n\twrite32(tail, 4, secret.length);\n\twrite32(tail, 8, associatedData.length);\n\tconst message = concat(\n\t\tfields.subarray(0, 28),\n\t\tpassword,\n\t\ttail.subarray(0, 4),\n\t\tsalt,\n\t\ttail.subarray(4, 8),\n\t\tsecret,\n\t\ttail.subarray(8, 12),\n\t\tassociatedData,\n\t);\n\ttry {\n\t\treturn blake2b(message, 64);\n\t} finally {\n\t\tmessage.fill(0);\n\t}\n}\n\n// Keep the four 64-bit registers local throughout the quarter round. The\n// scratch block is read once and written once, instead of at each add/rotate.\n// Low words stay unsigned for carry calculation; high words stay signed so\n// the JIT can use 32-bit addition. Storing into Uint32Array preserves the bits.\nfunction argonMix(words: Uint32Array, a: number, b: number, c: number, d: number): void {\n\tlet aLow = words[a] ?? 0;\n\tlet aHigh = (words[a + 1] ?? 0) | 0;\n\tlet bLow = words[b] ?? 0;\n\tlet bHigh = (words[b + 1] ?? 0) | 0;\n\tlet cLow = words[c] ?? 0;\n\tlet cHigh = (words[c + 1] ?? 0) | 0;\n\tlet dLow = words[d] ?? 0;\n\tlet dHigh = (words[d + 1] ?? 0) | 0;\n\tlet product: number;\n\tlet sum: number;\n\tlet low: number;\n\tlet high: number;\n\n\tproduct = Math.imul(aLow, bLow);\n\tsum = aLow + bLow + ((product << 1) >>> 0);\n\taHigh =\n\t\t(aHigh +\n\t\t\tbHigh +\n\t\t\t((multiplyHigh(aLow, bLow, product) << 1) | (product >>> 31)) +\n\t\t\t((sum / 0x1_0000_0000) | 0)) |\n\t\t0;\n\taLow = sum >>> 0;\n\tlow = dLow ^ aLow;\n\thigh = dHigh ^ aHigh;\n\tdLow = high >>> 0;\n\tdHigh = low | 0;\n\n\tproduct = Math.imul(cLow, dLow);\n\tsum = cLow + dLow + ((product << 1) >>> 0);\n\tcHigh =\n\t\t(cHigh +\n\t\t\tdHigh +\n\t\t\t((multiplyHigh(cLow, dLow, product) << 1) | (product >>> 31)) +\n\t\t\t((sum / 0x1_0000_0000) | 0)) |\n\t\t0;\n\tcLow = sum >>> 0;\n\tlow = bLow ^ cLow;\n\thigh = bHigh ^ cHigh;\n\tbLow = ((low >>> 24) | (high << 8)) >>> 0;\n\tbHigh = (high >>> 24) | (low << 8) | 0;\n\n\tproduct = Math.imul(aLow, bLow);\n\tsum = aLow + bLow + ((product << 1) >>> 0);\n\taHigh =\n\t\t(aHigh +\n\t\t\tbHigh +\n\t\t\t((multiplyHigh(aLow, bLow, product) << 1) | (product >>> 31)) +\n\t\t\t((sum / 0x1_0000_0000) | 0)) |\n\t\t0;\n\taLow = sum >>> 0;\n\tlow = dLow ^ aLow;\n\thigh = dHigh ^ aHigh;\n\tdLow = ((low >>> 16) | (high << 16)) >>> 0;\n\tdHigh = (high >>> 16) | (low << 16) | 0;\n\n\tproduct = Math.imul(cLow, dLow);\n\tsum = cLow + dLow + ((product << 1) >>> 0);\n\tcHigh =\n\t\t(cHigh +\n\t\t\tdHigh +\n\t\t\t((multiplyHigh(cLow, dLow, product) << 1) | (product >>> 31)) +\n\t\t\t((sum / 0x1_0000_0000) | 0)) |\n\t\t0;\n\tcLow = sum >>> 0;\n\tlow = bLow ^ cLow;\n\thigh = bHigh ^ cHigh;\n\tbLow = ((low << 1) | (high >>> 31)) >>> 0;\n\tbHigh = (high << 1) | (low >>> 31) | 0;\n\twords[a] = aLow;\n\twords[a + 1] = aHigh;\n\twords[b] = bLow;\n\twords[b + 1] = bHigh;\n\twords[c] = cLow;\n\twords[c + 1] = cHigh;\n\twords[d] = dLow;\n\twords[d + 1] = dHigh;\n}\n\n// Each round uses fixed word strides: contiguous rows, then paired columns.\n// Spell out the eight quarter rounds to avoid schedule-array loads in the hot loop.\nfunction argonRound(words: Uint32Array, offset: number, stride: number, pair: number): void {\n\targonMix(words, offset, offset + 2 * stride, offset + 4 * stride, offset + 6 * stride);\n\targonMix(\n\t\twords,\n\t\toffset + pair,\n\t\toffset + 2 * stride + pair,\n\t\toffset + 4 * stride + pair,\n\t\toffset + 6 * stride + pair,\n\t);\n\targonMix(words, offset + stride, offset + 3 * stride, offset + 5 * stride, offset + 7 * stride);\n\targonMix(\n\t\twords,\n\t\toffset + stride + pair,\n\t\toffset + 3 * stride + pair,\n\t\toffset + 5 * stride + pair,\n\t\toffset + 7 * stride + pair,\n\t);\n\targonMix(\n\t\twords,\n\t\toffset,\n\t\toffset + 2 * stride + pair,\n\t\toffset + 5 * stride,\n\t\toffset + 7 * stride + pair,\n\t);\n\targonMix(\n\t\twords,\n\t\toffset + pair,\n\t\toffset + 3 * stride,\n\t\toffset + 5 * stride + pair,\n\t\toffset + 6 * stride,\n\t);\n\targonMix(\n\t\twords,\n\t\toffset + stride,\n\t\toffset + 3 * stride + pair,\n\t\toffset + 4 * stride,\n\t\toffset + 6 * stride + pair,\n\t);\n\targonMix(\n\t\twords,\n\t\toffset + stride + pair,\n\t\toffset + 2 * stride,\n\t\toffset + 4 * stride + pair,\n\t\toffset + 7 * stride,\n\t);\n}\n\nfunction permuteBlock(words: Uint32Array): void {\n\tfor (let offset = 0; offset < 256; offset += 32) argonRound(words, offset, 4, 2);\n\tfor (let offset = 0; offset < 32; offset += 4) argonRound(words, offset, 32, 2);\n}\n\nfunction fillBlock(\n\tmemory: Uint32Array,\n\tpreviousOffset: number,\n\treferenceOffset: number,\n\tdestinationOffset: number,\n\twithXor: boolean,\n\toriginal: Uint32Array,\n\tpermuted: Uint32Array,\n): void {\n\tfor (let index = 0; index < 256; index += 1) {\n\t\tconst value = (memory[previousOffset + index] ?? 0) ^ (memory[referenceOffset + index] ?? 0);\n\t\toriginal[index] = value;\n\t\tpermuted[index] = value;\n\t}\n\tpermuteBlock(permuted);\n\tif (withXor) {\n\t\tfor (let index = 0; index < 256; index += 1) {\n\t\t\tmemory[destinationOffset + index] =\n\t\t\t\t(original[index] ?? 0) ^ (permuted[index] ?? 0) ^ (memory[destinationOffset + index] ?? 0);\n\t\t}\n\t} else {\n\t\tfor (let index = 0; index < 256; index += 1) {\n\t\t\tmemory[destinationOffset + index] = (original[index] ?? 0) ^ (permuted[index] ?? 0);\n\t\t}\n\t}\n}\n\nfunction indexAlpha(\n\tpass: number,\n\tslice: number,\n\tindex: number,\n\tsameLane: boolean,\n\tsegmentLength: number,\n\tlaneLength: number,\n\tpseudoRandom: number,\n): number {\n\tlet areaSize: number;\n\tif (pass === 0) {\n\t\tareaSize =\n\t\t\tslice === 0\n\t\t\t\t? index - 1\n\t\t\t\t: slice * segmentLength + (sameLane ? index - 1 : index === 0 ? -1 : 0);\n\t} else {\n\t\tareaSize = laneLength - segmentLength + (sameLane ? index - 1 : index === 0 ? -1 : 0);\n\t}\n\tconst squareHigh = multiplyHigh(\n\t\tpseudoRandom,\n\t\tpseudoRandom,\n\t\tMath.imul(pseudoRandom, pseudoRandom),\n\t);\n\tconst relative =\n\t\tareaSize - 1 - multiplyHigh(areaSize, squareHigh, Math.imul(areaSize, squareHigh));\n\tconst start = pass === 0 ? 0 : slice === 3 ? 0 : (slice + 1) * segmentLength;\n\treturn (start + relative) % laneLength;\n}\n\nfunction dataIndependent(type: number, pass: number, slice: number): boolean {\n\treturn type === 1 || (type === 2 && pass === 0 && slice < 2);\n}\n\nfunction compressBlocks(\n\tprevious: Uint32Array,\n\treference: Uint32Array,\n\toutput: Uint32Array,\n\toriginal: Uint32Array,\n\tpermuted: Uint32Array,\n): void {\n\tfor (let index = 0; index < 256; index += 1) {\n\t\tconst value = (previous[index] ?? 0) ^ (reference[index] ?? 0);\n\t\toriginal[index] = value;\n\t\tpermuted[index] = value;\n\t}\n\tpermuteBlock(permuted);\n\tfor (let index = 0; index < 256; index += 1) {\n\t\toutput[index] = (original[index] ?? 0) ^ (permuted[index] ?? 0);\n\t}\n}\n\nfunction generateAddressBlock(\n\tinputBlock: Uint32Array,\n\taddressBlock: Uint32Array,\n\tzero: Uint32Array,\n\toriginal: Uint32Array,\n\tpermuted: Uint32Array,\n\taddressTemporary: Uint32Array,\n): void {\n\tinputBlock[12] = ((inputBlock[12] ?? 0) + 1) >>> 0;\n\tcompressBlocks(zero, inputBlock, addressTemporary, original, permuted);\n\tcompressBlocks(zero, addressTemporary, addressBlock, original, permuted);\n}\n\nfunction toWords(bytes: Uint8Array): Uint32Array {\n\tconst words = new Uint32Array(256);\n\tfor (let index = 0; index < 256; index += 1) words[index] = read32(bytes, index * 4);\n\treturn words;\n}\n\ninterface Workspace {\n\treadonly memory: Uint32Array;\n\treadonly memoryBlocks: number;\n\treadonly laneLength: number;\n\treadonly segmentLength: number;\n\treadonly original: Uint32Array;\n\treadonly permuted: Uint32Array;\n\treadonly zero: Uint32Array;\n\treadonly addressTemporary: Uint32Array;\n}\n\nfunction fillIndexedBlock(\n\tinput: Argon2Input,\n\tworkspace: Workspace,\n\tposition: { pass: number; slice: number; lane: number },\n\tindex: number,\n\taddressBlock: Uint32Array | undefined,\n): void {\n\tconst { pass, slice, lane } = position;\n\tconst { memory, laneLength, segmentLength, original, permuted } = workspace;\n\tconst currentBlock = lane * laneLength + slice * segmentLength + index;\n\tconst previousBlock =\n\t\tcurrentBlock % laneLength === 0 ? currentBlock + laneLength - 1 : currentBlock - 1;\n\tconst previousOffset = previousBlock * 256;\n\tconst pseudoOffset = addressBlock === undefined ? previousOffset : (index % 128) * 2;\n\tconst pseudo = addressBlock ?? memory;\n\tconst pseudoLow = pseudo[pseudoOffset] ?? 0;\n\tconst pseudoHigh = pseudo[pseudoOffset + 1] ?? 0;\n\tlet referenceLane = pseudoHigh % input.parallelism;\n\tif (pass === 0 && slice === 0) referenceLane = lane;\n\tconst referenceIndex = indexAlpha(\n\t\tpass,\n\t\tslice,\n\t\tindex,\n\t\treferenceLane === lane,\n\t\tsegmentLength,\n\t\tlaneLength,\n\t\tpseudoLow,\n\t);\n\tconst destinationBlock = currentBlock * 256;\n\tfillBlock(\n\t\tmemory,\n\t\tpreviousOffset,\n\t\t(referenceLane * laneLength + referenceIndex) * 256,\n\t\tdestinationBlock,\n\t\tinput.version !== 0x10 && pass !== 0,\n\t\toriginal,\n\t\tpermuted,\n\t);\n}\n\nasync function fillSegment(\n\tinput: Argon2Input,\n\ttype: number,\n\tworkspace: Workspace,\n\tposition: { pass: number; slice: number; lane: number },\n): Promise<void> {\n\tconst { pass, slice, lane } = position;\n\tconst { memoryBlocks, segmentLength, original, permuted, zero, addressTemporary } = workspace;\n\tconst independent = dataIndependent(type, pass, slice);\n\tconst inputBlock = new Uint32Array(256);\n\tconst addressBlock = new Uint32Array(256);\n\ttry {\n\t\tif (independent) {\n\t\t\tinputBlock[0] = pass;\n\t\t\tinputBlock[2] = lane;\n\t\t\tinputBlock[4] = slice;\n\t\t\tinputBlock[6] = memoryBlocks;\n\t\t\tinputBlock[8] = input.passes;\n\t\t\tinputBlock[10] = type;\n\t\t}\n\t\tconst startingIndex = pass === 0 && slice === 0 ? 2 : 0;\n\t\tif (independent && startingIndex !== 0) {\n\t\t\tgenerateAddressBlock(inputBlock, addressBlock, zero, original, permuted, addressTemporary);\n\t\t}\n\t\tfor (let start = startingIndex; start < segmentLength; start += 512) {\n\t\t\t// Start the timer before computing so its delay overlaps useful work.\n\t\t\t// Awaiting it still yields to the event loop after at most 512 blocks.\n\t\t\tconst pause = new Promise<void>((resolve) => setTimeout(resolve, 0));\n\t\t\tconst end = Math.min(start + 512, segmentLength);\n\t\t\tfor (let index = start; index < end; index += 1) {\n\t\t\t\tif (independent && index % 128 === 0) {\n\t\t\t\t\tgenerateAddressBlock(\n\t\t\t\t\t\tinputBlock,\n\t\t\t\t\t\taddressBlock,\n\t\t\t\t\t\tzero,\n\t\t\t\t\t\toriginal,\n\t\t\t\t\t\tpermuted,\n\t\t\t\t\t\taddressTemporary,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tfillIndexedBlock(input, workspace, position, index, independent ? addressBlock : undefined);\n\t\t\t}\n\t\t\tawait pause;\n\t\t}\n\t} finally {\n\t\tinputBlock.fill(0);\n\t\taddressBlock.fill(0);\n\t\taddressTemporary.fill(0);\n\t}\n}\n\nexport async function deriveArgon2TypeScript(input: Argon2Input): Promise<Uint8Array> {\n\tconst type = { argon2d: 0, argon2i: 1, argon2id: 2 }[input.algorithm];\n\tconst memoryBlocks =\n\t\tMath.floor(input.memoryKiB / (4 * input.parallelism)) * 4 * input.parallelism;\n\tconst laneLength = memoryBlocks / input.parallelism;\n\tconst segmentLength = laneLength / 4;\n\tlet memory = new Uint32Array(0);\n\tlet h0: Uint8Array<ArrayBufferLike> = new Uint8Array(0);\n\tlet original = new Uint32Array(0);\n\tlet permuted = new Uint32Array(0);\n\tlet zero = new Uint32Array(0);\n\tlet addressTemporary = new Uint32Array(0);\n\tlet finalBlock: Uint8Array<ArrayBufferLike> = new Uint8Array(0);\n\tlet finalWords: Uint32Array<ArrayBufferLike> = new Uint32Array(0);\n\ttry {\n\t\tmemory = matrices.take(memoryBlocks * 256);\n\t\th0 = initialHash(input, type);\n\t\toriginal = new Uint32Array(256);\n\t\tpermuted = new Uint32Array(256);\n\t\tzero = new Uint32Array(256);\n\t\taddressTemporary = new Uint32Array(256);\n\t\tfor (let lane = 0; lane < input.parallelism; lane += 1) {\n\t\t\tfor (let block = 0; block < 2; block += 1) {\n\t\t\t\tconst suffix = new Uint8Array(8);\n\t\t\t\twrite32(suffix, 0, block);\n\t\t\t\twrite32(suffix, 4, lane);\n\t\t\t\tconst seed = concat(h0, suffix);\n\t\t\t\tlet bytes: Uint8Array<ArrayBufferLike> = new Uint8Array(0);\n\t\t\t\tlet words: Uint32Array<ArrayBufferLike> = new Uint32Array(0);\n\t\t\t\ttry {\n\t\t\t\t\tbytes = blakeLong(seed, 1024);\n\t\t\t\t\twords = toWords(bytes);\n\t\t\t\t\tmemory.set(words, (lane * laneLength + block) * 256);\n\t\t\t\t} finally {\n\t\t\t\t\tseed.fill(0);\n\t\t\t\t\tbytes.fill(0);\n\t\t\t\t\twords.fill(0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst workspace: Workspace = {\n\t\t\tmemory,\n\t\t\tmemoryBlocks,\n\t\t\tlaneLength,\n\t\t\tsegmentLength,\n\t\t\toriginal,\n\t\t\tpermuted,\n\t\t\tzero,\n\t\t\taddressTemporary,\n\t\t};\n\t\tfor (let pass = 0; pass < input.passes; pass += 1) {\n\t\t\tfor (let slice = 0; slice < 4; slice += 1) {\n\t\t\t\tfor (let lane = 0; lane < input.parallelism; lane += 1) {\n\t\t\t\t\tawait fillSegment(input, type, workspace, { pass, slice, lane });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfinalBlock = new Uint8Array(1024);\n\t\tfinalWords = toWords(finalBlock);\n\t\tfor (let lane = 0; lane < input.parallelism; lane += 1) {\n\t\t\tconst lastOffset = (lane * laneLength + laneLength - 1) * 256;\n\t\t\tfor (let index = 0; index < 256; index += 1) {\n\t\t\t\tfinalWords[index] = (finalWords[index] ?? 0) ^ (memory[lastOffset + index] ?? 0);\n\t\t\t}\n\t\t}\n\t\tfor (let index = 0; index < 256; index += 1)\n\t\t\twrite32(finalBlock, index * 4, finalWords[index] ?? 0);\n\t\treturn blakeLong(finalBlock, input.outputBytes);\n\t} finally {\n\t\th0.fill(0);\n\t\toriginal.fill(0);\n\t\tpermuted.fill(0);\n\t\tzero.fill(0);\n\t\taddressTemporary.fill(0);\n\t\tfinalBlock.fill(0);\n\t\tfinalWords.fill(0);\n\t\tmatrices.release(memory);\n\t}\n}\n"],"mappings":";;;AASA,MAAMA,IAAWC,EAAiB,GAE5BC,IAAU,uBACVC,IAAK;CACV;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,GACMC,IAAQ;CACb;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAI;EAAI;EAAI;EAAI;EAAI;CAAE;CACrD;EAAC;EAAI;EAAI;EAAG;EAAG;EAAG;EAAI;EAAI;EAAG;EAAG;EAAI;EAAG;EAAG;EAAI;EAAG;EAAG;CAAC;CACrD;EAAC;EAAI;EAAG;EAAI;EAAG;EAAG;EAAG;EAAI;EAAI;EAAI;EAAI;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC;CACrD;EAAC;EAAG;EAAG;EAAG;EAAG;EAAI;EAAI;EAAI;EAAI;EAAG;EAAG;EAAG;EAAI;EAAG;EAAG;EAAI;CAAC;CACrD;EAAC;EAAG;EAAG;EAAG;E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storage. */
3
+ function createMatrixPool() {
4
+ let e = [];
5
+ return {
6
+ take(t) {
7
+ for (let n = e.length - 1; n >= 0; --n) {
8
+ let r = e[n]?.deref();
9
+ if ((r === void 0 || r.length === t) && (e.splice(n, 1), r !== void 0)) return r;
10
+ }
11
+ return new Uint32Array(t);
12
+ },
13
+ release(t) {
14
+ t.fill(0), t.length !== 0 && (e.length === 4 && e.shift(), e.push(new WeakRef(t)));
15
+ }
16
+ };
17
+ }
18
+ export { createMatrixPool };
19
+
20
+ //# sourceMappingURL=argon2-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2-memory.js","names":["idle","index","matrix","words"],"sources":["../../src/kdf/argon2-memory.ts"],"sourcesContent":["interface MatrixPool {\n\treadonly take: (words: number) => Uint32Array<ArrayBuffer>;\n\treadonly release: (matrix: Uint32Array<ArrayBuffer>) => void;\n}\n\n/** Reuse wiped matrices without preventing garbage collection of idle storage. */\nexport function createMatrixPool(): MatrixPool {\n\tconst idle: WeakRef<Uint32Array<ArrayBuffer>>[] = [];\n\treturn {\n\t\ttake(words) {\n\t\t\tfor (let index = idle.length - 1; index >= 0; index -= 1) {\n\t\t\t\tconst matrix = idle[index]?.deref();\n\t\t\t\tif (matrix === undefined || matrix.length === words) {\n\t\t\t\t\tidle.splice(index, 1);\n\t\t\t\t\tif (matrix !== undefined) return matrix;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Uint32Array(words);\n\t\t},\n\t\trelease(matrix) {\n\t\t\tmatrix.fill(0);\n\t\t\tif (matrix.length === 0) return;\n\t\t\tif (idle.length === 4) idle.shift();\n\t\t\tidle.push(new WeakRef(matrix));\n\t\t},\n\t};\n}\n"],"mappings":";;AAMA,SAAgB,mBAA+B;CAC9C,IAAMA,IAA4C,CAAC;CACnD,OAAO;EACN,KAAK,GAAO;GACX,KAAK,IAAIC,IAAQD,EAAK,SAAS,GAAGC,KAAS,GAAG,KAAY;IACzD,IAAMC,IAASF,EAAKC,EAAM,EAAE,MAAM;IAClC,KAAIC,MAAW,KAAA,KAAaA,EAAO,WAAWC,OAC7CH,EAAK,OAAOC,GAAO,CAAC,GAChBC,MAAW,KAAA,IAAW,OAAOA;GAEnC;GACA,OAAO,IAAI,YAAYC,CAAK;EAC7B;EACA,QAAQ,GAAQ;GAEf,AADAD,EAAO,KAAK,CAAC,GACTA,EAAO,WAAW,MAClBF,EAAK,WAAW,KAAGA,EAAK,MAAM,GAClCA,EAAK,KAAK,IAAI,QAAQE,CAAM,CAAC;EAC9B;CACD;AACD"}
@@ -0,0 +1,18 @@
1
+ import { deriveArgon2TypeScript as e } from "./argon2-core.js";
2
+ // src/kdf/argon2-portable.ts
3
+ /** Internal TypeScript backend; the public boundary validates inputs and limits. */
4
+ async function portableArgon2(t) {
5
+ return t.memoryKiB * 1024 + t.outputBytes + t.password.byteLength + t.salt.byteLength + (t.secret?.byteLength ?? 0) + (t.associatedData?.byteLength ?? 0) >= 2147483648 ? {
6
+ ok: !1,
7
+ error: {
8
+ code: "unsupported",
9
+ message: "Request exceeds portable Argon2 address space"
10
+ }
11
+ } : {
12
+ ok: !0,
13
+ value: await e(t)
14
+ };
15
+ }
16
+ export { portableArgon2 };
17
+
18
+ //# sourceMappingURL=argon2-portable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2-portable.js","names":["input","deriveArgon2TypeScript"],"sources":["../../src/kdf/argon2-portable.ts"],"sourcesContent":["import type { Argon2Input, Argon2Result } from '#micro509/kdf/argon2';\nimport { deriveArgon2TypeScript } from '#micro509/kdf/argon2-core';\n\n/** Internal TypeScript backend; the public boundary validates inputs and limits. */\nexport async function portableArgon2(input: Argon2Input): Promise<Argon2Result> {\n\tconst bytes =\n\t\tinput.memoryKiB * 1024 +\n\t\tinput.outputBytes +\n\t\tinput.password.byteLength +\n\t\tinput.salt.byteLength +\n\t\t(input.secret?.byteLength ?? 0) +\n\t\t(input.associatedData?.byteLength ?? 0);\n\tif (bytes >= 0x80000000) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: { code: 'unsupported', message: 'Request exceeds portable Argon2 address space' },\n\t\t};\n\t}\n\treturn { ok: true, value: await deriveArgon2TypeScript(input) };\n}\n"],"mappings":";;;AAIA,eAAsB,eAAe,GAA2C;CAc/E,OAZCA,EAAM,YAAY,OAClBA,EAAM,cACNA,EAAM,SAAS,aACfA,EAAM,KAAK,cACVA,EAAM,QAAQ,cAAc,MAC5BA,EAAM,gBAAgB,cAAc,MACzB,aACL;EACN,IAAI;EACJ,OAAO;GAAE,MAAM;GAAe,SAAS;EAAgD;CACxF,IAEM;EAAE,IAAI;EAAM,OAAO,MAAMC,EAAuBD,CAAK;CAAE;AAC/D"}
@@ -0,0 +1,84 @@
1
+ import { Micro509Error, Result } from "../result/result.js";
2
+ /** RFC 9106 Argon2 variants. Use Argon2id for new password-based applications. */
3
+ export type Argon2Algorithm = "argon2d" | "argon2i" | "argon2id";
4
+ /** Argon2 versions used by KDBX. The native backend supports only 0x13. */
5
+ export type Argon2Version = 0x10 | 0x13;
6
+ /** Exact derivation inputs. Password encoding and format preprocessing belong to the caller. */
7
+ export interface Argon2Input {
8
+ /** Select Argon2id for new applications. */
9
+ readonly algorithm: Argon2Algorithm;
10
+ /** Exact version. No version substitution is performed. */
11
+ readonly version: Argon2Version;
12
+ /** Password or format-preprocessed input bytes. */
13
+ readonly password: Uint8Array;
14
+ /** Salt bytes. RFC 9106 recommends 16 bytes; the native backend requires at least eight. */
15
+ readonly salt: Uint8Array;
16
+ /** Total memory in kibibytes, at least eight times parallelism. */
17
+ readonly memoryKiB: number;
18
+ /** Number of full passes through memory. */
19
+ readonly passes: number;
20
+ /** Number of lanes. */
21
+ readonly parallelism: number;
22
+ /** Requested output length in bytes, at least four. */
23
+ readonly outputBytes: number;
24
+ /** Optional secret input, separate from the password. */
25
+ readonly secret?: Uint8Array;
26
+ /** Optional associated data included in the derivation. */
27
+ readonly associatedData?: Uint8Array;
28
+ }
29
+ /** Per-invocation ceilings, checked before copying inputs or calling the backend. */
30
+ export interface Argon2Limits {
31
+ /** Memory ceiling in KiB. Default: 262144 (256 MiB). */
32
+ readonly maxMemoryKiB?: number;
33
+ /** Pass ceiling. Default: 16. */
34
+ readonly maxPasses?: number;
35
+ /** Lane ceiling. Default: 16. */
36
+ readonly maxParallelism?: number;
37
+ /** Output-byte ceiling. Default: 1024. */
38
+ readonly maxOutputBytes?: number;
39
+ /** Sum of password, salt, secret, and associated-data lengths. Default: 1048576. */
40
+ readonly maxInputBytes?: number;
41
+ }
42
+ /** Stable failures without password, salt, or backend exception content. */
43
+ export type Argon2ErrorCode = "invalid_parameters" | "limit_exceeded" | "unsupported" | "derivation_failed";
44
+ /** Derived bytes or a typed error. Successful output belongs to the caller. */
45
+ export type Argon2Result = Result<Uint8Array, Micro509Error<Argon2ErrorCode>>;
46
+ /**
47
+ * Trusted, explicitly supplied implementation for the exact requested algorithm
48
+ * and version. Called only after parameter and resource checks. Input arrays are
49
+ * private copies, wiped when the promise settles. A backend that transfers an input
50
+ * buffer must erase it in the receiving worker. Transfer ownership of output
51
+ * bytes to the caller: the wrapper copies and wipes that array before returning.
52
+ * Report unsupported requests explicitly, without fallback. Execution behavior
53
+ * and cancellation of a custom backend are its provider's responsibility.
54
+ */
55
+ export type Argon2Backend = (input: Argon2Input) => Promise<Argon2Result>;
56
+ /** Resource policy and optional external implementation for {@linkcode deriveArgon2}. */
57
+ export interface Argon2Options {
58
+ /** Per-call ceilings. Applications must separately bound concurrent calls. */
59
+ readonly limits?: Argon2Limits;
60
+ /**
61
+ * Omit to prefer native WebCrypto, then the TypeScript implementation on `unsupported` only.
62
+ * Select `native` or `portable` to require that implementation, or supply a
63
+ * trusted callback. Explicit selections never fall back to another backend.
64
+ */
65
+ readonly backend?: Argon2Backend | "native" | "portable";
66
+ }
67
+ /**
68
+ * Derives raw Argon2 bytes after validating parameters and resource ceilings.
69
+ *
70
+ * Native WebCrypto is preferred for version 0x13. An unsupported request uses
71
+ * the TypeScript implementation for the exact variant and version, including
72
+ * 0x10. Other native failures are returned without retrying. Explicit
73
+ * backends never fall back. No algorithm, version, or parameter is substituted.
74
+ *
75
+ * Caller buffers are copied synchronously before the first await and never
76
+ * modified. Owned temporary arrays are zeroed on completion. Native key storage
77
+ * and runtime copies cannot be explicitly erased by JavaScript. The returned
78
+ * output is caller-owned. Calls cannot cancel native work once dispatched.
79
+ * TypeScript work yields while filling memory blocks. Its private memory matrix
80
+ * is erased on completion or failure.
81
+ * Limits apply per call, not to concurrent invocations.
82
+ */
83
+ export declare function deriveArgon2(input: Argon2Input, options?: Argon2Options): Promise<Argon2Result>;
84
+ //# sourceMappingURL=argon2.d.ts.map
@@ -0,0 +1,186 @@
1
+ // src/kdf/argon2.ts
2
+ function failure(e, t) {
3
+ return {
4
+ ok: !1,
5
+ error: {
6
+ code: e,
7
+ message: t
8
+ }
9
+ };
10
+ }
11
+ function uintInRange(e, t, n) {
12
+ return Number.isSafeInteger(e) && e >= t && e <= n;
13
+ }
14
+ function validate(e, t) {
15
+ if (e.algorithm !== "argon2id" && e.algorithm !== "argon2d" && e.algorithm !== "argon2i") return failure("unsupported", "Unsupported Argon2 variant");
16
+ if (e.version !== 16 && e.version !== 19) return failure("unsupported", "Unsupported Argon2 version");
17
+ if (!uintInRange(e.parallelism, 1, 16777215) || !uintInRange(e.memoryKiB, 8 * e.parallelism, 4294967295) || !uintInRange(e.passes, 1, 4294967295) || !uintInRange(e.outputBytes, 4, 4294967295)) return failure("invalid_parameters", "Invalid Argon2 numeric parameters");
18
+ let n = [
19
+ e.password,
20
+ e.salt,
21
+ e.secret,
22
+ e.associatedData
23
+ ];
24
+ if (!(e.password instanceof Uint8Array) || !(e.salt instanceof Uint8Array) || n.some((e) => e !== void 0 && !(e instanceof Uint8Array))) return failure("invalid_parameters", "Argon2 inputs must be Uint8Array values");
25
+ try {
26
+ for (let e of n) e !== void 0 && Uint8Array.prototype.values.call(e);
27
+ } catch {
28
+ return failure("invalid_parameters", "Argon2 input buffer is unavailable");
29
+ }
30
+ let r = [
31
+ [e.memoryKiB, t.maxMemoryKiB ?? 262144],
32
+ [e.passes, t.maxPasses ?? 16],
33
+ [e.parallelism, t.maxParallelism ?? 16],
34
+ [e.outputBytes, t.maxOutputBytes ?? 1024],
35
+ [n.reduce((e, t) => e + (t?.byteLength ?? 0), 0), t.maxInputBytes ?? 1048576]
36
+ ];
37
+ if (r.some(([, e]) => !uintInRange(e, 1, 4294967295))) return failure("invalid_parameters", "Argon2 resource limits must be positive uint32 values");
38
+ if (r.some(([e, t]) => e > t)) return failure("limit_exceeded", "Argon2 request exceeds resource limits");
39
+ }
40
+ function snapshotInput(e) {
41
+ let { algorithm: t, version: n, password: r, salt: i, memoryKiB: a, passes: o, parallelism: s, outputBytes: c, secret: l, associatedData: u } = e;
42
+ return {
43
+ algorithm: t,
44
+ version: n,
45
+ password: r,
46
+ salt: i,
47
+ memoryKiB: a,
48
+ passes: o,
49
+ parallelism: s,
50
+ outputBytes: c,
51
+ ...l === void 0 ? {} : { secret: l },
52
+ ...u === void 0 ? {} : { associatedData: u }
53
+ };
54
+ }
55
+ function copyInput(e) {
56
+ return {
57
+ algorithm: e.algorithm,
58
+ version: e.version,
59
+ memoryKiB: e.memoryKiB,
60
+ passes: e.passes,
61
+ parallelism: e.parallelism,
62
+ outputBytes: e.outputBytes,
63
+ password: new Uint8Array(e.password),
64
+ salt: new Uint8Array(e.salt),
65
+ ...e.secret === void 0 ? {} : { secret: new Uint8Array(e.secret) },
66
+ ...e.associatedData === void 0 ? {} : { associatedData: new Uint8Array(e.associatedData) }
67
+ };
68
+ }
69
+ function eraseAccessible(e) {
70
+ e !== void 0 && e.byteLength > 0 && Uint8Array.prototype.fill.call(e, 0);
71
+ }
72
+ async function nativeArgon2(e) {
73
+ if (e.version !== 19) return failure("unsupported", "Native Argon2 supports version 0x13 only");
74
+ if (e.salt.byteLength < 8) return failure("unsupported", "Native Argon2 requires a salt of at least eight bytes");
75
+ if (e.outputBytes > 536870911) return failure("unsupported", "Requested output exceeds the native WebCrypto bit-length range");
76
+ if (globalThis.crypto?.subtle === void 0) return failure("unsupported", "Native WebCrypto is unavailable");
77
+ let t = globalThis.crypto.subtle, n;
78
+ switch (e.algorithm) {
79
+ case "argon2id":
80
+ n = "Argon2id";
81
+ break;
82
+ case "argon2d":
83
+ n = "Argon2d";
84
+ break;
85
+ case "argon2i":
86
+ n = "Argon2i";
87
+ break;
88
+ default: return failure("unsupported", "Unsupported Argon2 variant");
89
+ }
90
+ try {
91
+ let r;
92
+ try {
93
+ r = await Reflect.apply(t.importKey, t, [
94
+ "raw-secret",
95
+ e.password,
96
+ n,
97
+ !1,
98
+ ["deriveBits"]
99
+ ]);
100
+ } catch (e) {
101
+ if (e instanceof TypeError) return failure("unsupported", "This runtime does not support the raw-secret key format");
102
+ throw e;
103
+ }
104
+ if (typeof CryptoKey > "u" || !(r instanceof CryptoKey)) return failure("derivation_failed", "Native Argon2 returned an invalid key");
105
+ let i = {
106
+ name: n,
107
+ version: e.version,
108
+ memory: e.memoryKiB,
109
+ passes: e.passes,
110
+ parallelism: e.parallelism,
111
+ nonce: new Uint8Array(e.salt),
112
+ ...e.secret === void 0 ? {} : { secretValue: new Uint8Array(e.secret) },
113
+ ...e.associatedData === void 0 ? {} : { associatedData: new Uint8Array(e.associatedData) }
114
+ };
115
+ try {
116
+ let n = await t.deriveBits(i, r, e.outputBytes * 8);
117
+ return {
118
+ ok: !0,
119
+ value: new Uint8Array(n)
120
+ };
121
+ } finally {
122
+ i.nonce.fill(0), i.secretValue?.fill(0), i.associatedData?.fill(0);
123
+ }
124
+ } catch (e) {
125
+ return e instanceof Error && e.name === "NotSupportedError" ? failure("unsupported", "This runtime does not support native Argon2") : failure("derivation_failed", "Native Argon2 derivation failed");
126
+ }
127
+ }
128
+ async function builtinArgon2(e, t) {
129
+ if (t !== "portable") {
130
+ let n = await nativeArgon2(e);
131
+ if (t === "native" || n.ok || n.error.code !== "unsupported") return n;
132
+ }
133
+ let { portableArgon2: n } = await import("./argon2-portable.js");
134
+ return n(e);
135
+ }
136
+ /**
137
+ * Derives raw Argon2 bytes after validating parameters and resource ceilings.
138
+ *
139
+ * Native WebCrypto is preferred for version 0x13. An unsupported request uses
140
+ * the TypeScript implementation for the exact variant and version, including
141
+ * 0x10. Other native failures are returned without retrying. Explicit
142
+ * backends never fall back. No algorithm, version, or parameter is substituted.
143
+ *
144
+ * Caller buffers are copied synchronously before the first await and never
145
+ * modified. Owned temporary arrays are zeroed on completion. Native key storage
146
+ * and runtime copies cannot be explicitly erased by JavaScript. The returned
147
+ * output is caller-owned. Calls cannot cancel native work once dispatched.
148
+ * TypeScript work yields while filling memory blocks. Its private memory matrix
149
+ * is erased on completion or failure.
150
+ * Limits apply per call, not to concurrent invocations.
151
+ */
152
+ async function deriveArgon2(e, t = {}) {
153
+ if (typeof e != "object" || !e) return failure("invalid_parameters", "Argon2 input must be an object");
154
+ let n;
155
+ try {
156
+ n = snapshotInput(e);
157
+ } catch {
158
+ return failure("invalid_parameters", "Argon2 input properties could not be read");
159
+ }
160
+ let r = validate(n, t.limits ?? {});
161
+ if (r !== void 0) return r;
162
+ let i = copyInput(n);
163
+ try {
164
+ let e = typeof t.backend == "function" ? await t.backend(i) : await builtinArgon2(i, t.backend);
165
+ if (!e.ok) {
166
+ let t = e.error.code;
167
+ return failure(t === "unsupported" || t === "limit_exceeded" || t === "invalid_parameters" ? t : "derivation_failed", "Argon2 backend could not derive the requested key");
168
+ }
169
+ if (!(e.value instanceof Uint8Array)) return failure("derivation_failed", "Argon2 backend returned invalid output");
170
+ try {
171
+ return e.value.byteLength === i.outputBytes ? {
172
+ ok: !0,
173
+ value: new Uint8Array(e.value)
174
+ } : failure("derivation_failed", "Argon2 backend returned an incorrect output length");
175
+ } finally {
176
+ eraseAccessible(e.value);
177
+ }
178
+ } catch {
179
+ return failure("derivation_failed", "Argon2 backend failed");
180
+ } finally {
181
+ eraseAccessible(i.password), eraseAccessible(i.salt), eraseAccessible(i.secret), eraseAccessible(i.associatedData);
182
+ }
183
+ }
184
+ export { deriveArgon2 };
185
+
186
+ //# sourceMappingURL=argon2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2.js","names":["value","min","max","input","inputs","bytes","bounds","limits","sum","maximum","actual","secret","associatedData","subtle","name","key","error","params","output","backend","result","portableArgon2","snapshot","invalid","options","owned","code"],"sources":["../../src/kdf/argon2.ts"],"sourcesContent":["/**\n * Argon2 derivation and resource-policy boundary. The default backend prefers\n * native WebCrypto and uses the TypeScript implementation when unsupported.\n *\n * @module\n */\n\nimport type { Micro509Error, Result } from '#micro509/result/result';\n\n/** RFC 9106 Argon2 variants. Use Argon2id for new password-based applications. */\nexport type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';\n\n/** Argon2 versions used by KDBX. The native backend supports only 0x13. */\nexport type Argon2Version = 0x10 | 0x13;\n\n/** Exact derivation inputs. Password encoding and format preprocessing belong to the caller. */\nexport interface Argon2Input {\n\t/** Select Argon2id for new applications. */\n\treadonly algorithm: Argon2Algorithm;\n\t/** Exact version. No version substitution is performed. */\n\treadonly version: Argon2Version;\n\t/** Password or format-preprocessed input bytes. */\n\treadonly password: Uint8Array;\n\t/** Salt bytes. RFC 9106 recommends 16 bytes; the native backend requires at least eight. */\n\treadonly salt: Uint8Array;\n\t/** Total memory in kibibytes, at least eight times parallelism. */\n\treadonly memoryKiB: number;\n\t/** Number of full passes through memory. */\n\treadonly passes: number;\n\t/** Number of lanes. */\n\treadonly parallelism: number;\n\t/** Requested output length in bytes, at least four. */\n\treadonly outputBytes: number;\n\t/** Optional secret input, separate from the password. */\n\treadonly secret?: Uint8Array;\n\t/** Optional associated data included in the derivation. */\n\treadonly associatedData?: Uint8Array;\n}\n\n/** Per-invocation ceilings, checked before copying inputs or calling the backend. */\nexport interface Argon2Limits {\n\t/** Memory ceiling in KiB. Default: 262144 (256 MiB). */\n\treadonly maxMemoryKiB?: number;\n\t/** Pass ceiling. Default: 16. */\n\treadonly maxPasses?: number;\n\t/** Lane ceiling. Default: 16. */\n\treadonly maxParallelism?: number;\n\t/** Output-byte ceiling. Default: 1024. */\n\treadonly maxOutputBytes?: number;\n\t/** Sum of password, salt, secret, and associated-data lengths. Default: 1048576. */\n\treadonly maxInputBytes?: number;\n}\n\n/** Stable failures without password, salt, or backend exception content. */\nexport type Argon2ErrorCode =\n\t| 'invalid_parameters'\n\t| 'limit_exceeded'\n\t| 'unsupported'\n\t| 'derivation_failed';\n\n/** Derived bytes or a typed error. Successful output belongs to the caller. */\nexport type Argon2Result = Result<Uint8Array, Micro509Error<Argon2ErrorCode>>;\n\n/**\n * Trusted, explicitly supplied implementation for the exact requested algorithm\n * and version. Called only after parameter and resource checks. Input arrays are\n * private copies, wiped when the promise settles. A backend that transfers an input\n * buffer must erase it in the receiving worker. Transfer ownership of output\n * bytes to the caller: the wrapper copies and wipes that array before returning.\n * Report unsupported requests explicitly, without fallback. Execution behavior\n * and cancellation of a custom backend are its provider's responsibility.\n */\nexport type Argon2Backend = (input: Argon2Input) => Promise<Argon2Result>;\n\n/** Resource policy and optional external implementation for {@linkcode deriveArgon2}. */\nexport interface Argon2Options {\n\t/** Per-call ceilings. Applications must separately bound concurrent calls. */\n\treadonly limits?: Argon2Limits;\n\t/**\n\t * Omit to prefer native WebCrypto, then the TypeScript implementation on `unsupported` only.\n\t * Select `native` or `portable` to require that implementation, or supply a\n\t * trusted callback. Explicit selections never fall back to another backend.\n\t */\n\treadonly backend?: Argon2Backend | 'native' | 'portable';\n}\n\nfunction failure(code: Argon2ErrorCode, message: string): Argon2Result {\n\treturn { ok: false, error: { code, message } };\n}\n\nfunction uintInRange(value: number, min: number, max: number): boolean {\n\treturn Number.isSafeInteger(value) && value >= min && value <= max;\n}\n\nfunction validate(input: Argon2Input, limits: Argon2Limits): Argon2Result | undefined {\n\tif (\n\t\tinput.algorithm !== 'argon2id' &&\n\t\tinput.algorithm !== 'argon2d' &&\n\t\tinput.algorithm !== 'argon2i'\n\t) {\n\t\treturn failure('unsupported', 'Unsupported Argon2 variant');\n\t}\n\tif (input.version !== 0x10 && input.version !== 0x13) {\n\t\treturn failure('unsupported', 'Unsupported Argon2 version');\n\t}\n\t// RFC 9106 section 3.1. Memory is passed exactly, including values not\n\t// divisible by 4*p: rounding the input would change the initial hash.\n\tif (\n\t\t!uintInRange(input.parallelism, 1, 0xffffff) ||\n\t\t!uintInRange(input.memoryKiB, 8 * input.parallelism, 0xffffffff) ||\n\t\t!uintInRange(input.passes, 1, 0xffffffff) ||\n\t\t!uintInRange(input.outputBytes, 4, 0xffffffff)\n\t) {\n\t\treturn failure('invalid_parameters', 'Invalid Argon2 numeric parameters');\n\t}\n\tconst inputs = [input.password, input.salt, input.secret, input.associatedData];\n\tif (\n\t\t!(input.password instanceof Uint8Array) ||\n\t\t!(input.salt instanceof Uint8Array) ||\n\t\tinputs.some((bytes) => bytes !== undefined && !(bytes instanceof Uint8Array))\n\t) {\n\t\treturn failure('invalid_parameters', 'Argon2 inputs must be Uint8Array values');\n\t}\n\ttry {\n\t\t// A detached or out-of-bounds view reports zero length. Validate its\n\t\t// backing store before copying any of the caller's secret material.\n\t\tfor (const bytes of inputs) {\n\t\t\tif (bytes !== undefined) Uint8Array.prototype.values.call(bytes);\n\t\t}\n\t} catch {\n\t\treturn failure('invalid_parameters', 'Argon2 input buffer is unavailable');\n\t}\n\tconst bounds = [\n\t\t[input.memoryKiB, limits.maxMemoryKiB ?? 262144],\n\t\t[input.passes, limits.maxPasses ?? 16],\n\t\t[input.parallelism, limits.maxParallelism ?? 16],\n\t\t[input.outputBytes, limits.maxOutputBytes ?? 1024],\n\t\t[\n\t\t\tinputs.reduce((sum, bytes) => sum + (bytes?.byteLength ?? 0), 0),\n\t\t\tlimits.maxInputBytes ?? 1048576,\n\t\t],\n\t] as const;\n\tif (bounds.some(([, maximum]) => !uintInRange(maximum, 1, 0xffffffff))) {\n\t\treturn failure('invalid_parameters', 'Argon2 resource limits must be positive uint32 values');\n\t}\n\tif (bounds.some(([actual, maximum]) => actual > maximum)) {\n\t\treturn failure('limit_exceeded', 'Argon2 request exceeds resource limits');\n\t}\n\treturn undefined;\n}\n\nfunction snapshotInput(input: Argon2Input): Argon2Input {\n\t// Read declared properties once, including inherited and non-enumerable ones.\n\t// Byte arrays remain references until validation has enforced resource bounds.\n\tconst {\n\t\talgorithm,\n\t\tversion,\n\t\tpassword,\n\t\tsalt,\n\t\tmemoryKiB,\n\t\tpasses,\n\t\tparallelism,\n\t\toutputBytes,\n\t\tsecret,\n\t\tassociatedData,\n\t} = input;\n\treturn {\n\t\talgorithm,\n\t\tversion,\n\t\tpassword,\n\t\tsalt,\n\t\tmemoryKiB,\n\t\tpasses,\n\t\tparallelism,\n\t\toutputBytes,\n\t\t...(secret === undefined ? {} : { secret }),\n\t\t...(associatedData === undefined ? {} : { associatedData }),\n\t};\n}\n\nfunction copyInput(input: Argon2Input): Argon2Input {\n\treturn {\n\t\talgorithm: input.algorithm,\n\t\tversion: input.version,\n\t\tmemoryKiB: input.memoryKiB,\n\t\tpasses: input.passes,\n\t\tparallelism: input.parallelism,\n\t\toutputBytes: input.outputBytes,\n\t\tpassword: new Uint8Array(input.password),\n\t\tsalt: new Uint8Array(input.salt),\n\t\t...(input.secret === undefined ? {} : { secret: new Uint8Array(input.secret) }),\n\t\t...(input.associatedData === undefined\n\t\t\t? {}\n\t\t\t: { associatedData: new Uint8Array(input.associatedData) }),\n\t};\n}\n\nfunction eraseAccessible(bytes: Uint8Array | undefined): void {\n\t// Transfer detaches the sender's view. Its bytes can only be erased by the\n\t// receiving worker, and cleanup must still proceed through the other inputs.\n\tif (bytes !== undefined && bytes.byteLength > 0) Uint8Array.prototype.fill.call(bytes, 0);\n}\n\nasync function nativeArgon2(input: Argon2Input): Promise<Argon2Result> {\n\tif (input.version !== 0x13) {\n\t\treturn failure('unsupported', 'Native Argon2 supports version 0x13 only');\n\t}\n\tif (input.salt.byteLength < 8) {\n\t\treturn failure('unsupported', 'Native Argon2 requires a salt of at least eight bytes');\n\t}\n\tif (input.outputBytes > Math.floor(0xffffffff / 8)) {\n\t\treturn failure('unsupported', 'Requested output exceeds the native WebCrypto bit-length range');\n\t}\n\tif (typeof globalThis.crypto?.subtle === 'undefined') {\n\t\treturn failure('unsupported', 'Native WebCrypto is unavailable');\n\t}\n\tconst subtle = globalThis.crypto.subtle;\n\tlet name: 'Argon2d' | 'Argon2i' | 'Argon2id';\n\tswitch (input.algorithm) {\n\t\tcase 'argon2id':\n\t\t\tname = 'Argon2id';\n\t\t\tbreak;\n\t\tcase 'argon2d':\n\t\t\tname = 'Argon2d';\n\t\t\tbreak;\n\t\tcase 'argon2i':\n\t\t\tname = 'Argon2i';\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn failure('unsupported', 'Unsupported Argon2 variant');\n\t}\n\ttry {\n\t\t// raw-secret is a runtime WebCrypto extension not present in every DOM\n\t\t// declaration. The result is narrowed rather than asserted or globally\n\t\t// augmenting consumers' SubtleCrypto definitions.\n\t\tlet key: unknown;\n\t\ttry {\n\t\t\tkey = await Reflect.apply(subtle.importKey, subtle, [\n\t\t\t\t'raw-secret',\n\t\t\t\tinput.password,\n\t\t\t\tname,\n\t\t\t\tfalse,\n\t\t\t\t['deriveBits'],\n\t\t\t]);\n\t\t} catch (error) {\n\t\t\t// Older WebCrypto KeyFormat enums reject raw-secret with TypeError.\n\t\t\t// Keep this classification local to import; deriveBits failures stay failures.\n\t\t\tif (error instanceof TypeError) {\n\t\t\t\treturn failure('unsupported', 'This runtime does not support the raw-secret key format');\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tif (typeof CryptoKey === 'undefined' || !(key instanceof CryptoKey)) {\n\t\t\treturn failure('derivation_failed', 'Native Argon2 returned an invalid key');\n\t\t}\n\t\tconst params = {\n\t\t\tname,\n\t\t\tversion: input.version,\n\t\t\tmemory: input.memoryKiB,\n\t\t\tpasses: input.passes,\n\t\t\tparallelism: input.parallelism,\n\t\t\tnonce: new Uint8Array(input.salt),\n\t\t\t...(input.secret === undefined ? {} : { secretValue: new Uint8Array(input.secret) }),\n\t\t\t...(input.associatedData === undefined\n\t\t\t\t? {}\n\t\t\t\t: { associatedData: new Uint8Array(input.associatedData) }),\n\t\t};\n\t\ttry {\n\t\t\tconst output = await subtle.deriveBits(params, key, input.outputBytes * 8);\n\t\t\treturn { ok: true, value: new Uint8Array(output) };\n\t\t} finally {\n\t\t\tparams.nonce.fill(0);\n\t\t\tparams.secretValue?.fill(0);\n\t\t\tparams.associatedData?.fill(0);\n\t\t}\n\t} catch (error) {\n\t\treturn error instanceof Error && error.name === 'NotSupportedError'\n\t\t\t? failure('unsupported', 'This runtime does not support native Argon2')\n\t\t\t: failure('derivation_failed', 'Native Argon2 derivation failed');\n\t}\n}\n\nasync function builtinArgon2(\n\tinput: Argon2Input,\n\tbackend: 'native' | 'portable' | undefined,\n): Promise<Argon2Result> {\n\tif (backend !== 'portable') {\n\t\tconst result = await nativeArgon2(input);\n\t\tif (backend === 'native' || result.ok || result.error.code !== 'unsupported') return result;\n\t}\n\tconst { portableArgon2 } = await import('#micro509/kdf/argon2-portable');\n\treturn portableArgon2(input);\n}\n\n/**\n * Derives raw Argon2 bytes after validating parameters and resource ceilings.\n *\n * Native WebCrypto is preferred for version 0x13. An unsupported request uses\n * the TypeScript implementation for the exact variant and version, including\n * 0x10. Other native failures are returned without retrying. Explicit\n * backends never fall back. No algorithm, version, or parameter is substituted.\n *\n * Caller buffers are copied synchronously before the first await and never\n * modified. Owned temporary arrays are zeroed on completion. Native key storage\n * and runtime copies cannot be explicitly erased by JavaScript. The returned\n * output is caller-owned. Calls cannot cancel native work once dispatched.\n * TypeScript work yields while filling memory blocks. Its private memory matrix\n * is erased on completion or failure.\n * Limits apply per call, not to concurrent invocations.\n */\nexport async function deriveArgon2(\n\tinput: Argon2Input,\n\toptions: Argon2Options = {},\n): Promise<Argon2Result> {\n\tif (input === null || typeof input !== 'object') {\n\t\treturn failure('invalid_parameters', 'Argon2 input must be an object');\n\t}\n\tlet snapshot: Argon2Input;\n\ttry {\n\t\tsnapshot = snapshotInput(input);\n\t} catch {\n\t\treturn failure('invalid_parameters', 'Argon2 input properties could not be read');\n\t}\n\tconst invalid = validate(snapshot, options.limits ?? {});\n\tif (invalid !== undefined) return invalid;\n\tconst owned = copyInput(snapshot);\n\ttry {\n\t\tconst result =\n\t\t\ttypeof options.backend === 'function'\n\t\t\t\t? await options.backend(owned)\n\t\t\t\t: await builtinArgon2(owned, options.backend);\n\t\tif (!result.ok) {\n\t\t\t// A custom provider's diagnostic may contain secrets. Return only the\n\t\t\t// recognized code and a fixed message at this public boundary.\n\t\t\tconst code = result.error.code;\n\t\t\treturn failure(\n\t\t\t\tcode === 'unsupported' || code === 'limit_exceeded' || code === 'invalid_parameters'\n\t\t\t\t\t? code\n\t\t\t\t\t: 'derivation_failed',\n\t\t\t\t'Argon2 backend could not derive the requested key',\n\t\t\t);\n\t\t}\n\t\tif (!(result.value instanceof Uint8Array)) {\n\t\t\treturn failure('derivation_failed', 'Argon2 backend returned invalid output');\n\t\t}\n\t\ttry {\n\t\t\treturn result.value.byteLength === owned.outputBytes\n\t\t\t\t? { ok: true, value: new Uint8Array(result.value) }\n\t\t\t\t: failure('derivation_failed', 'Argon2 backend returned an incorrect output length');\n\t\t} finally {\n\t\t\teraseAccessible(result.value);\n\t\t}\n\t} catch {\n\t\treturn failure('derivation_failed', 'Argon2 backend failed');\n\t} finally {\n\t\teraseAccessible(owned.password);\n\t\teraseAccessible(owned.salt);\n\t\teraseAccessible(owned.secret);\n\t\teraseAccessible(owned.associatedData);\n\t}\n}\n"],"mappings":";AAsFA,SAAS,QAAQ,GAAuB,GAA+B;CACtE,OAAO;EAAE,IAAI;EAAO,OAAO;GAAE;GAAM;EAAQ;CAAE;AAC9C;AAEA,SAAS,YAAY,GAAe,GAAa,GAAsB;CACtE,OAAO,OAAO,cAAcA,CAAK,KAAKA,KAASC,KAAOD,KAASE;AAChE;AAEA,SAAS,SAAS,GAAoB,GAAgD;CACrF,IACCC,EAAM,cAAc,cACpBA,EAA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BAAgBA,EAAM,cAAc;CACrC;AACD"}
package/dist/kdf.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { Argon2Algorithm, Argon2Backend, Argon2ErrorCode, Argon2Input, Argon2Limits, Argon2Options, Argon2Result, Argon2Version, deriveArgon2 } from "./kdf/argon2.js";
2
+ export { type Argon2Algorithm, type Argon2Backend, type Argon2ErrorCode, type Argon2Input, type Argon2Limits, type Argon2Options, type Argon2Result, type Argon2Version, deriveArgon2 };
package/dist/kdf.js ADDED
@@ -0,0 +1 @@
1
+ export { deriveArgon2 } from "./kdf/argon2.js";