@gjsify/crypto 0.3.21 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
- package/lib/esm/asn1.js +1 -1
- package/lib/esm/bigint-math.js +1 -1
- package/lib/esm/cipher.js +1 -1
- package/lib/esm/crypto-utils.js +1 -1
- package/lib/esm/dh.js +1 -1
- package/lib/esm/ecdh.js +1 -1
- package/lib/esm/ecdsa.js +1 -1
- package/lib/esm/hash.js +1 -1
- package/lib/esm/hkdf.js +1 -1
- package/lib/esm/hmac.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/key-object.js +1 -1
- package/lib/esm/mgf1.js +1 -1
- package/lib/esm/pbkdf2.js +1 -1
- package/lib/esm/public-encrypt.js +1 -1
- package/lib/esm/random.js +1 -1
- package/lib/esm/rsa-oaep.js +1 -1
- package/lib/esm/rsa-pss.js +1 -1
- package/lib/esm/scrypt.js +1 -1
- package/lib/esm/sign.js +1 -1
- package/lib/esm/timing-safe-equal.js +1 -1
- package/lib/esm/x509.js +1 -1
- package/package.json +46 -43
- package/src/asn1.ts +0 -797
- package/src/bigint-math.ts +0 -45
- package/src/cipher.spec.ts +0 -332
- package/src/cipher.ts +0 -952
- package/src/constants.ts +0 -16
- package/src/crypto-utils.ts +0 -64
- package/src/dh.spec.ts +0 -111
- package/src/dh.ts +0 -761
- package/src/ecdh.spec.ts +0 -120
- package/src/ecdh.ts +0 -624
- package/src/ecdsa.ts +0 -243
- package/src/extended.spec.ts +0 -444
- package/src/gcm.spec.ts +0 -141
- package/src/hash.spec.ts +0 -86
- package/src/hash.ts +0 -119
- package/src/hkdf.ts +0 -99
- package/src/hmac.spec.ts +0 -64
- package/src/hmac.ts +0 -123
- package/src/index.ts +0 -93
- package/src/key-object.spec.ts +0 -205
- package/src/key-object.ts +0 -401
- package/src/mgf1.ts +0 -37
- package/src/pbkdf2.spec.ts +0 -76
- package/src/pbkdf2.ts +0 -106
- package/src/public-encrypt.ts +0 -288
- package/src/random.spec.ts +0 -133
- package/src/random.ts +0 -183
- package/src/rsa-oaep.ts +0 -167
- package/src/rsa-pss.ts +0 -190
- package/src/scrypt.spec.ts +0 -90
- package/src/scrypt.ts +0 -191
- package/src/sign.spec.ts +0 -160
- package/src/sign.ts +0 -319
- package/src/test.mts +0 -19
- package/src/timing-safe-equal.ts +0 -21
- package/src/x509.spec.ts +0 -211
- package/src/x509.ts +0 -262
- package/tsconfig.json +0 -29
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
package/lib/esm/asn1.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Buffer as e}from"node:buffer";function pemToDer(t){let n=t.trim().split(/\r?\n/),r=n.findIndex(e=>e.startsWith(`-----BEGIN `));if(r===-1)throw Error(`Invalid PEM: no BEGIN line found`);let i=n[r].match(/^-----BEGIN (.+)-----$/);if(!i)throw Error(`Invalid PEM header format`);let a=i[1],o=n.findIndex((e,t)=>t>r&&e.startsWith(`-----END `));if(o===-1)throw Error(`Invalid PEM: no END line found`);let s=n.slice(r+1,o).join(``),c=e.from(s,`base64`);return{type:a,der:new Uint8Array(c.buffer,c.byteOffset,c.byteLength)}}function parseTlv(e,t){if(t>=e.length)throw Error(`ASN.1 parse error: unexpected end of data`);let n=e[t++],r,i=e[t++];if(i<128)r=i;else{let n=i&127;if(n===0)throw Error(`ASN.1 parse error: indefinite length not supported`);r=0;for(let i=0;i<n;i++)r=r<<8|e[t++]}let a=e.slice(t,t+r),o=t+r,s={tag:n,data:a};return n===48&&(s.children=parseSequenceChildren(a)),{value:s,next:o}}function parseSequenceChildren(e){let t=[],n=0;for(;n<e.length;){let{value:r,next:i}=parseTlv(e,n);t.push(r),n=i}return t}function parseDer(e){let{value:t}=parseTlv(e,0);return t}function integerToBigInt(e){let t=0;for(;t<e.length-1&&e[t]===0;)t++;let n=0n;for(let r=t;r<e.length;r++)n=n<<8n|BigInt(e[r]);return n}const t=new Uint8Array([42,134,72,134,247,13,1,1,1]);function oidsEqual(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function parseRsaPublicKeyPkcs1(e){let t=e.children;if(!t||t.length<2)throw Error(`Invalid PKCS#1 RSAPublicKey structure`);return{n:integerToBigInt(t[0].data),e:integerToBigInt(t[1].data)}}function parseRsaPrivateKeyPkcs1(e){let t=e.children;if(!t||t.length<6)throw Error(`Invalid PKCS#1 RSAPrivateKey structure`);return{n:integerToBigInt(t[1].data),e:integerToBigInt(t[2].data),d:integerToBigInt(t[3].data),p:integerToBigInt(t[4].data),q:integerToBigInt(t[5].data)}}function parseSubjectPublicKeyInfo(e){let n=e.children;if(!n||n.length<2)throw Error(`Invalid SubjectPublicKeyInfo structure`);let r=n[0];if(!r.children||r.children.length<1)throw Error(`Invalid AlgorithmIdentifier`);let i=r.children[0];if(i.tag!==6||!oidsEqual(i.data,t))throw Error(`Unsupported algorithm: only RSA is supported`);let a=n[1];if(a.tag!==3)throw Error(`Expected BIT STRING for public key data`);return parseRsaPublicKeyPkcs1(parseDer(a.data.slice(1)))}function parsePrivateKeyInfo(e){let n=e.children;if(!n||n.length<3)throw Error(`Invalid PrivateKeyInfo structure`);let r=n[1];if(!r.children||r.children.length<1)throw Error(`Invalid AlgorithmIdentifier`);let i=r.children[0];if(i.tag!==6||!oidsEqual(i.data,t))throw Error(`Unsupported algorithm: only RSA is supported`);let a=n[2];if(a.tag!==4)throw Error(`Expected OCTET STRING for private key data`);return parseRsaPrivateKeyPkcs1(parseDer(a.data))}function encodeLength(e){if(e<128)return new Uint8Array([e]);let t=[],n=e;for(;n>0;)t.unshift(n&255),n>>=8;return new Uint8Array([128|t.length,...t])}function encodeTlv(e,t){let n=encodeLength(t.length),r=new Uint8Array(1+n.length+t.length);return r[0]=e,r.set(n,1),r.set(t,1+n.length),r}function bigintToAsn1Integer(e){if(e===0n)return encodeTlv(2,new Uint8Array([0]));let t=e.toString(16),n=t.length%2?`0`+t:t,r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return r[0]&128&&r.unshift(0),encodeTlv(2,new Uint8Array(r))}function encodeSequence(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return encodeTlv(48,n)}function encodeBitString(e){let t=new Uint8Array(1+e.length);return t[0]=0,t.set(e,1),encodeTlv(3,t)}function encodeOctetString(e){return encodeTlv(4,e)}function encodeOid(e){return encodeTlv(6,e)}function encodeNull(){return new Uint8Array([5,0])}function encodeRsaPublicKeyPkcs1(e){return encodeSequence([bigintToAsn1Integer(e.n),bigintToAsn1Integer(e.e)])}function encodeSubjectPublicKeyInfo(e){return encodeSequence([encodeSequence([encodeOid(t),encodeNull()]),encodeBitString(encodeRsaPublicKeyPkcs1(e))])}function encodeRsaPrivateKeyPkcs1(e){let t=e.d%(e.p-1n),n=e.d%(e.q-1n),r=modInverse(e.q,e.p);return encodeSequence([bigintToAsn1Integer(0n),bigintToAsn1Integer(e.n),bigintToAsn1Integer(e.e),bigintToAsn1Integer(e.d),bigintToAsn1Integer(e.p),bigintToAsn1Integer(e.q),bigintToAsn1Integer(t),bigintToAsn1Integer(n),bigintToAsn1Integer(r)])}function encodePrivateKeyInfo(e){let n=encodeSequence([encodeOid(t),encodeNull()]),r=encodeOctetString(encodeRsaPrivateKeyPkcs1(e));return encodeSequence([bigintToAsn1Integer(0n),n,r])}function derToPem(t,n){let r=e.from(t).toString(`base64`),i=[`-----BEGIN ${n}-----`];for(let e=0;e<r.length;e+=64)i.push(r.substring(e,e+64));return i.push(`-----END ${n}-----`),i.join(`
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Buffer as e}from"node:buffer";function pemToDer(t){let n=t.trim().split(/\r?\n/),r=n.findIndex(e=>e.startsWith(`-----BEGIN `));if(r===-1)throw Error(`Invalid PEM: no BEGIN line found`);let i=n[r].match(/^-----BEGIN (.+)-----$/);if(!i)throw Error(`Invalid PEM header format`);let a=i[1],o=n.findIndex((e,t)=>t>r&&e.startsWith(`-----END `));if(o===-1)throw Error(`Invalid PEM: no END line found`);let s=n.slice(r+1,o).join(``),c=e.from(s,`base64`);return{type:a,der:new Uint8Array(c.buffer,c.byteOffset,c.byteLength)}}function parseTlv(e,t){if(t>=e.length)throw Error(`ASN.1 parse error: unexpected end of data`);let n=e[t++],r,i=e[t++];if(i<128)r=i;else{let n=i&127;if(n===0)throw Error(`ASN.1 parse error: indefinite length not supported`);r=0;for(let i=0;i<n;i++)r=r<<8|e[t++]}let a=e.slice(t,t+r),o=t+r,s={tag:n,data:a};return n===48&&(s.children=parseSequenceChildren(a)),{value:s,next:o}}function parseSequenceChildren(e){let t=[],n=0;for(;n<e.length;){let{value:r,next:i}=parseTlv(e,n);t.push(r),n=i}return t}function parseDer(e){let{value:t}=parseTlv(e,0);return t}function integerToBigInt(e){let t=0;for(;t<e.length-1&&e[t]===0;)t++;let n=0n;for(let r=t;r<e.length;r++)n=n<<8n|BigInt(e[r]);return n}const t=new Uint8Array([42,134,72,134,247,13,1,1,1]);function oidsEqual(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function parseRsaPublicKeyPkcs1(e){let t=e.children;if(!t||t.length<2)throw Error(`Invalid PKCS#1 RSAPublicKey structure`);return{n:integerToBigInt(t[0].data),e:integerToBigInt(t[1].data)}}function parseRsaPrivateKeyPkcs1(e){let t=e.children;if(!t||t.length<6)throw Error(`Invalid PKCS#1 RSAPrivateKey structure`);return{n:integerToBigInt(t[1].data),e:integerToBigInt(t[2].data),d:integerToBigInt(t[3].data),p:integerToBigInt(t[4].data),q:integerToBigInt(t[5].data)}}function parseSubjectPublicKeyInfo(e){let n=e.children;if(!n||n.length<2)throw Error(`Invalid SubjectPublicKeyInfo structure`);let r=n[0];if(!r.children||r.children.length<1)throw Error(`Invalid AlgorithmIdentifier`);let i=r.children[0];if(i.tag!==6||!oidsEqual(i.data,t))throw Error(`Unsupported algorithm: only RSA is supported`);let a=n[1];if(a.tag!==3)throw Error(`Expected BIT STRING for public key data`);return parseRsaPublicKeyPkcs1(parseDer(a.data.slice(1)))}function parsePrivateKeyInfo(e){let n=e.children;if(!n||n.length<3)throw Error(`Invalid PrivateKeyInfo structure`);let r=n[1];if(!r.children||r.children.length<1)throw Error(`Invalid AlgorithmIdentifier`);let i=r.children[0];if(i.tag!==6||!oidsEqual(i.data,t))throw Error(`Unsupported algorithm: only RSA is supported`);let a=n[2];if(a.tag!==4)throw Error(`Expected OCTET STRING for private key data`);return parseRsaPrivateKeyPkcs1(parseDer(a.data))}function encodeLength(e){if(e<128)return new Uint8Array([e]);let t=[],n=e;for(;n>0;)t.unshift(n&255),n>>=8;return new Uint8Array([128|t.length,...t])}function encodeTlv(e,t){let n=encodeLength(t.length),r=new Uint8Array(1+n.length+t.length);return r[0]=e,r.set(n,1),r.set(t,1+n.length),r}function bigintToAsn1Integer(e){if(e===0n)return encodeTlv(2,new Uint8Array([0]));let t=e.toString(16),n=t.length%2?`0`+t:t,r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return r[0]&128&&r.unshift(0),encodeTlv(2,new Uint8Array(r))}function encodeSequence(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return encodeTlv(48,n)}function encodeBitString(e){let t=new Uint8Array(1+e.length);return t[0]=0,t.set(e,1),encodeTlv(3,t)}function encodeOctetString(e){return encodeTlv(4,e)}function encodeOid(e){return encodeTlv(6,e)}function encodeNull(){return new Uint8Array([5,0])}function encodeRsaPublicKeyPkcs1(e){return encodeSequence([bigintToAsn1Integer(e.n),bigintToAsn1Integer(e.e)])}function encodeSubjectPublicKeyInfo(e){return encodeSequence([encodeSequence([encodeOid(t),encodeNull()]),encodeBitString(encodeRsaPublicKeyPkcs1(e))])}function encodeRsaPrivateKeyPkcs1(e){let t=e.d%(e.p-1n),n=e.d%(e.q-1n),r=modInverse(e.q,e.p);return encodeSequence([bigintToAsn1Integer(0n),bigintToAsn1Integer(e.n),bigintToAsn1Integer(e.e),bigintToAsn1Integer(e.d),bigintToAsn1Integer(e.p),bigintToAsn1Integer(e.q),bigintToAsn1Integer(t),bigintToAsn1Integer(n),bigintToAsn1Integer(r)])}function encodePrivateKeyInfo(e){let n=encodeSequence([encodeOid(t),encodeNull()]),r=encodeOctetString(encodeRsaPrivateKeyPkcs1(e));return encodeSequence([bigintToAsn1Integer(0n),n,r])}function derToPem(t,n){let r=e.from(t).toString(`base64`),i=[`-----BEGIN ${n}-----`];for(let e=0;e<r.length;e+=64)i.push(r.substring(e,e+64));return i.push(`-----END ${n}-----`),i.join(`
|
|
2
2
|
`)}function modInverse(e,t){let[n,r]=[e%t,t],[i,a]=[1n,0n];for(;r!==0n;){let e=n/r;[n,r]=[r,n-e*r],[i,a]=[a,i-e*a]}return(i%t+t)%t}function parseX509(e){let{der:t}=pemToDer(e);return parseX509Der(t)}function parseX509Der(e){let n=parseDer(e);if(n.tag!==48||!n.children||n.children.length<3)throw Error(`Invalid X.509 certificate structure`);let r=n.children[0],i=n.children[1],a=n.children[2];if(!r.children||r.children.length<6)throw Error(`Invalid TBSCertificate structure`);let o=0;r.children[0].tag===160&&o++;let s=integerToBigInt(r.children[o].data);o++,o++;let c=parseDN(r.children[o]);o++;let l=r.children[o],u=parseAsn1Time(l.children[0]),d=parseAsn1Time(l.children[1]);o++;let f=parseDN(r.children[o]);o++;let p=null,m=`unknown`;if(o<r.children.length){let e=r.children[o];try{if(e.children&&e.children.length>=2){let n=e.children[0];if(n.children&&n.children.length>=1){let r=n.children[0];r.tag===6&&oidsEqual(r.data,t)&&(m=`rsa`,p=parseSubjectPublicKeyInfo(e))}}}catch{}o++}let h,g;for(let e=o;e<r.children.length;e++){let t=r.children[e];if(t.tag===163&&t.data.length>0){let e=parseDer(t.data);if(e.children){g=e.children;let t=new Uint8Array([85,29,17]);for(let n of e.children)if(n.children&&n.children.length>=2){let e=n.children[0];if(e.tag===6&&oidsEqual(e.data,t)){let e=n.children[n.children.length-1];h=parseSAN(e.data)}}}}}let _=`unknown`;i.children&&i.children.length>=1&&(_=oidToName(i.children[0].data));let v=a.tag===3?a.data.slice(1):a.data;return{raw:e,tbsCertificate:r.data,serialNumber:s,issuer:c,subject:f,validFrom:u,validTo:d,publicKey:p,publicKeyAlgorithm:m,signatureAlgorithm:_,signature:v,subjectAltName:h,extensions:g}}const n={"2.5.4.3":`CN`,"2.5.4.6":`C`,"2.5.4.7":`L`,"2.5.4.8":`ST`,"2.5.4.10":`O`,"2.5.4.11":`OU`,"1.2.840.113549.1.9.1":`emailAddress`},r={"1.2.840.113549.1.1.1":`rsaEncryption`,"1.2.840.113549.1.1.5":`sha1WithRSAEncryption`,"1.2.840.113549.1.1.11":`sha256WithRSAEncryption`,"1.2.840.113549.1.1.12":`sha384WithRSAEncryption`,"1.2.840.113549.1.1.13":`sha512WithRSAEncryption`};function decodeOidString(e){if(e.length===0)return``;let t=[];t.push(Math.floor(e[0]/40)),t.push(e[0]%40);let n=0;for(let r=1;r<e.length;r++)n=n<<7|e[r]&127,e[r]&128||(t.push(n),n=0);return t.join(`.`)}function oidToName(e){let t=decodeOidString(e);return r[t]||t}function parseDN(e){if(!e.children)return``;let t=[];for(let r of e.children){let e=r.tag===49?parseSequenceChildren(r.data):r.children||[];for(let r of e)if(r.children&&r.children.length>=2){let e=r.children[0].data,i=decodeOidString(e),a=n[i]||i,o=r.children[1].data,s=new TextDecoder().decode(o);t.push(`${a}=${s}`)}}return t.join(`, `)}function parseAsn1Time(e){let t=new TextDecoder().decode(e.data);if(e.tag===23){let e=parseInt(t.substring(0,2),10);e=e>=50?1900+e:2e3+e;let n=parseInt(t.substring(2,4),10)-1,r=parseInt(t.substring(4,6),10),i=parseInt(t.substring(6,8),10),a=parseInt(t.substring(8,10),10),o=parseInt(t.substring(10,12),10);return new Date(Date.UTC(e,n,r,i,a,o))}if(e.tag===24){let e=parseInt(t.substring(0,4),10),n=parseInt(t.substring(4,6),10)-1,r=parseInt(t.substring(6,8),10),i=parseInt(t.substring(8,10),10),a=parseInt(t.substring(10,12),10),o=parseInt(t.substring(12,14),10);return new Date(Date.UTC(e,n,r,i,a,o))}throw Error(`Unsupported time tag: 0x${e.tag.toString(16)}`)}function parseSAN(e){let t=[];try{let n=parseDer(e);if(n.tag===48&&n.children){for(let e of n.children)if(e.tag===130)t.push(`DNS:`+new TextDecoder().decode(e.data));else if(e.tag===135){if(e.data.length===4)t.push(`IP Address:`+e.data.join(`.`));else if(e.data.length===16){let n=[];for(let t=0;t<16;t+=2)n.push((e.data[t]<<8|e.data[t+1]).toString(16));t.push(`IP Address:`+n.join(`:`))}}}}catch{}return t}function parsePemKey(e){let{type:t,der:n}=pemToDer(e),r=parseDer(n);if(r.tag!==48)throw Error(`Invalid key format: expected top-level SEQUENCE`);switch(t){case`RSA PUBLIC KEY`:return{type:`rsa-public`,components:parseRsaPublicKeyPkcs1(r)};case`PUBLIC KEY`:return{type:`rsa-public`,components:parseSubjectPublicKeyInfo(r)};case`RSA PRIVATE KEY`:return{type:`rsa-private`,components:parseRsaPrivateKeyPkcs1(r)};case`PRIVATE KEY`:return{type:`rsa-private`,components:parsePrivateKeyInfo(r)};default:throw Error(`Unsupported PEM type: ${t}`)}}function rsaKeySize(e){let t=0,n=e;for(;n>0n;)t++,n>>=1n;return Math.ceil(t/8)}export{bigintToAsn1Integer,derToPem,encodePrivateKeyInfo,encodeRsaPrivateKeyPkcs1,encodeRsaPublicKeyPkcs1,encodeSequence,encodeSubjectPublicKeyInfo,parsePemKey,parseX509,parseX509Der,rsaKeySize};
|
package/lib/esm/bigint-math.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function modPow(e,t,n){if(n===1n)return 0n;e=(e%n+n)%n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),t>>=1n,e=e*e%n;return r}function bigIntToBytes(e,t){let n=new Uint8Array(t),r=e;for(let e=t-1;e>=0;e--)n[e]=Number(r&255n),r>>=8n;return n}function bytesToBigInt(e){let t=0n;for(let n=0;n<e.length;n++)t=t<<8n|BigInt(e[n]);return t}export{bigIntToBytes,bytesToBigInt,modPow};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function modPow(e,t,n){if(n===1n)return 0n;e=(e%n+n)%n;let r=1n;for(;t>0n;)t&1n&&(r=r*e%n),t>>=1n,e=e*e%n;return r}function bigIntToBytes(e,t){let n=new Uint8Array(t),r=e;for(let e=t-1;e>=0;e--)n[e]=Number(r&255n),r>>=8n;return n}function bytesToBigInt(e){let t=0n;for(let n=0;n<e.length;n++)t=t<<8n|BigInt(e[n]);return t}export{bigIntToBytes,bytesToBigInt,modPow};
|
package/lib/esm/cipher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as e}from"node:buffer";const t=new Uint8Array([99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22]),n=new Uint8Array([82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125]),r=[1,2,4,8,16,32,64,128,27,54];function gmul(e,t){let n=0;for(let r=0;r<8;r++){t&1&&(n^=e);let r=e&128;e=e<<1&255,r&&(e^=27),t>>=1}return n}function keyExpansion(e){let n=e.length/4,i=n+6,a=4*(i+1),o=Array(a);for(let t=0;t<n;t++)o[t]=new Uint8Array([e[4*t],e[4*t+1],e[4*t+2],e[4*t+3]]);for(let e=n;e<a;e++){let i=new Uint8Array(o[e-1]);e%n===0?i=new Uint8Array([t[i[1]]^r[e/n-1],t[i[2]],t[i[3]],t[i[0]]]):n>6&&e%n===4&&(i=new Uint8Array([t[i[0]],t[i[1]],t[i[2]],t[i[3]]])),o[e]=new Uint8Array(4);for(let t=0;t<4;t++)o[e][t]=o[e-n][t]^i[t]}let s=[];for(let e=0;e<=i;e++){let t=new Uint8Array(16);for(let n=0;n<4;n++)t[4*n]=o[4*e+n][0],t[4*n+1]=o[4*e+n][1],t[4*n+2]=o[4*e+n][2],t[4*n+3]=o[4*e+n][3];s.push(t)}return s}function aesEncryptBlock(e,n){let r=new Uint8Array(e),i=n.length-1;for(let e=0;e<16;e++)r[e]^=n[0][e];for(let e=1;e<i;e++){for(let e=0;e<16;e++)r[e]=t[r[e]];let i=r[1];r[1]=r[5],r[5]=r[9],r[9]=r[13],r[13]=i;let a=r[2],o=r[6];r[2]=r[10],r[6]=r[14],r[10]=a,r[14]=o;let s=r[15];r[15]=r[11],r[11]=r[7],r[7]=r[3],r[3]=s;for(let e=0;e<4;e++){let t=e*4,n=r[t],i=r[t+1],a=r[t+2],o=r[t+3];r[t]=gmul(2,n)^gmul(3,i)^a^o,r[t+1]=n^gmul(2,i)^gmul(3,a)^o,r[t+2]=n^i^gmul(2,a)^gmul(3,o),r[t+3]=gmul(3,n)^i^a^gmul(2,o)}for(let t=0;t<16;t++)r[t]^=n[e][t]}for(let e=0;e<16;e++)r[e]=t[r[e]];let a=r[1];r[1]=r[5],r[5]=r[9],r[9]=r[13],r[13]=a;let o=r[2],s=r[6];r[2]=r[10],r[6]=r[14],r[10]=o,r[14]=s;let c=r[15];r[15]=r[11],r[11]=r[7],r[7]=r[3],r[3]=c;for(let e=0;e<16;e++)r[e]^=n[i][e];return r}function aesDecryptBlock(e,t){let r=new Uint8Array(e),i=t.length-1;for(let e=0;e<16;e++)r[e]^=t[i][e];for(let e=i-1;e>0;e--){let i=r[13];r[13]=r[9],r[9]=r[5],r[5]=r[1],r[1]=i;let a=r[10],o=r[14];r[10]=r[2],r[14]=r[6],r[2]=a,r[6]=o;let s=r[3];r[3]=r[7],r[7]=r[11],r[11]=r[15],r[15]=s;for(let e=0;e<16;e++)r[e]=n[r[e]];for(let n=0;n<16;n++)r[n]^=t[e][n];for(let e=0;e<4;e++){let t=e*4,n=r[t],i=r[t+1],a=r[t+2],o=r[t+3];r[t]=gmul(14,n)^gmul(11,i)^gmul(13,a)^gmul(9,o),r[t+1]=gmul(9,n)^gmul(14,i)^gmul(11,a)^gmul(13,o),r[t+2]=gmul(13,n)^gmul(9,i)^gmul(14,a)^gmul(11,o),r[t+3]=gmul(11,n)^gmul(13,i)^gmul(9,a)^gmul(14,o)}}let a=r[13];r[13]=r[9],r[9]=r[5],r[5]=r[1],r[1]=a;let o=r[10],s=r[14];r[10]=r[2],r[14]=r[6],r[2]=o,r[6]=s;let c=r[3];r[3]=r[7],r[7]=r[11],r[11]=r[15],r[15]=c;for(let e=0;e<16;e++)r[e]=n[r[e]];for(let e=0;e<16;e++)r[e]^=t[0][e];return r}function incrementCounter(e){for(let t=15;t>=0&&++e[t]===0;t--);}function gcmIncrementCounter(e){for(let t=15;t>=12&&++e[t]===0;t--);}function gfMul(e,t){let n=new Uint8Array(16),r=new Uint8Array(e);for(let e=0;e<128;e++){if(t[e>>>3]&1<<7-(e&7))for(let e=0;e<16;e++)n[e]^=r[e];let i=r[15]&1;for(let e=15;e>0;e--)r[e]=r[e]>>>1|(r[e-1]&1)<<7;r[0]>>>=1,i&&(r[0]^=225)}return n}function ghash(e,t,n){let r=new Uint8Array(16),i=Math.ceil(t.length/16)||0;for(let n=0;n<i;n++){let i=n*16,a=Math.min(i+16,t.length);for(let e=0;e<16;e++){let n=i+e;n<a&&(r[e]^=t[n])}let o=gfMul(r,e);r.set(o)}let a=Math.ceil(n.length/16)||0;for(let t=0;t<a;t++){let i=t*16,a=Math.min(i+16,n.length);for(let e=0;e<16;e++){let t=i+e;t<a&&(r[e]^=n[t])}let o=gfMul(r,e);r.set(o)}let o=new Uint8Array(16),s=t.length*8,c=n.length*8,l=Math.floor(s/4294967296),u=s>>>0;o[0]=l>>>24&255,o[1]=l>>>16&255,o[2]=l>>>8&255,o[3]=l&255,o[4]=u>>>24&255,o[5]=u>>>16&255,o[6]=u>>>8&255,o[7]=u&255;let d=Math.floor(c/4294967296),f=c>>>0;o[8]=d>>>24&255,o[9]=d>>>16&255,o[10]=d>>>8&255,o[11]=d&255,o[12]=f>>>24&255,o[13]=f>>>16&255,o[14]=f>>>8&255,o[15]=f&255;for(let e=0;e<16;e++)r[e]^=o[e];let p=gfMul(r,e);return r.set(p),r}function parseAlgorithm(e){let t=e.toLowerCase().match(/^aes-(128|192|256)-(cbc|ctr|ecb|cfb|ofb|gcm)$/);if(!t)throw Error(`Unsupported cipher algorithm: ${e}`);let n=parseInt(t[1]),r=t[2];return{keySize:n/8,ivSize:r===`ecb`?0:r===`gcm`?12:16,mode:r}}function toBuffer(t,n){return typeof t==`string`?e.from(t,n||`utf8`):e.from(t)}function encodeOutput(t,n){return n?e.from(t).toString(n):e.from(t)}function incompleteUtf8Tail(e){if(e.length===0)return 0;let t=e.length;for(let n=1;n<=Math.min(4,t);n++){let r=e[t-n];if(!(r&128))return 0;if((r&192)==128)continue;let i;if((r&224)==192)i=2;else if((r&240)==224)i=3;else if((r&248)==240)i=4;else return 0;return n<i?n:0}return 0}function pkcs7Pad(e){let t=16-e.length%16,n=new Uint8Array(e.length+t);n.set(e);for(let r=e.length;r<n.length;r++)n[r]=t;return n}function pkcs7Unpad(e){if(e.length===0||e.length%16!=0)throw Error(`bad decrypt`);let t=e[e.length-1];if(t===0||t>16)throw Error(`bad decrypt`);for(let n=e.length-t;n<e.length;n++)if(e[n]!==t)throw Error(`bad decrypt`);return new Uint8Array(e.slice(0,e.length-t))}var CipherBase=class{_roundKeys;_iv;_mode;_buffer=new Uint8Array;_autoPadding=!0;_finalized=!1;constructor(e,t,n){let r=parseAlgorithm(e);if(t.length!==r.keySize)throw Error(`Invalid key length ${t.length}, expected ${r.keySize} for ${e}`);if(r.ivSize>0&&(!n||n.length!==r.ivSize))throw Error(`Invalid IV length ${n?.length??0}, expected ${r.ivSize} for ${e}`);this._roundKeys=keyExpansion(t),this._iv=n?new Uint8Array(n):new Uint8Array(16),this._mode=r.mode}setAutoPadding(e){return this._autoPadding=e,this}},Cipher=class extends CipherBase{_prevBlock;_counter;_gcmH=null;_gcmJ0=null;_gcmAAD=new Uint8Array;_gcmCiphertext=[];_gcmCiphertextLen=0;_gcmAuthTag=null;_gcmAADSet=!1;constructor(e,t,n){super(e,t,n),this._prevBlock=new Uint8Array(this._iv),this._mode===`gcm`?(this._gcmH=aesEncryptBlock(new Uint8Array(16),this._roundKeys),this._gcmJ0=new Uint8Array(16),this._gcmJ0.set(this._iv.subarray(0,12)),this._gcmJ0[15]=1,this._counter=new Uint8Array(this._gcmJ0),gcmIncrementCounter(this._counter)):this._counter=new Uint8Array(this._iv)}setAAD(e){if(this._mode!==`gcm`)throw Error(`setAAD is only supported in GCM mode`);if(this._gcmCiphertextLen>0)throw Error(`setAAD must be called before update()`);return this._gcmAAD=new Uint8Array(e),this._gcmAADSet=!0,this}getAuthTag(){if(this._mode!==`gcm`)throw Error(`getAuthTag is only supported in GCM mode`);if(!this._gcmAuthTag)throw Error(`getAuthTag must be called after final()`);return e.from(this._gcmAuthTag)}update(e,t,n){let r=toBuffer(e,t),i=new Uint8Array(this._buffer.length+r.length);if(i.set(this._buffer),i.set(r,this._buffer.length),this._mode===`gcm`){let e=this._processGcmEncrypt(i);return this._buffer=new Uint8Array,encodeOutput(e,n)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){let e=this._processStream(i);return this._buffer=new Uint8Array,encodeOutput(e,n)}let a=Math.floor(i.length/16)*16,o=[];for(let e=0;e<a;e+=16){let t=i.slice(e,e+16);o.push(this._encryptBlock(t))}this._buffer=i.slice(a);let s=new Uint8Array(o.length*16);for(let e=0;e<o.length;e++)s.set(o[e],e*16);return encodeOutput(s,n)}final(t){if(this._finalized)throw Error(`Cipher already finalized`);if(this._finalized=!0,this._mode===`gcm`){let n=new Uint8Array;this._buffer.length>0&&(n=this._processGcmEncrypt(this._buffer),this._buffer=new Uint8Array);let r=new Uint8Array(this._gcmCiphertextLen),i=0;for(let e of this._gcmCiphertext)r.set(e,i),i+=e.length;let a=ghash(this._gcmH,this._gcmAAD,r),o=aesEncryptBlock(this._gcmJ0,this._roundKeys),s=new Uint8Array(16);for(let e=0;e<16;e++)s[e]=a[e]^o[e];return this._gcmAuthTag=e.from(s),encodeOutput(n,t)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){if(this._buffer.length>0){let e=this._processStream(this._buffer);return this._buffer=new Uint8Array,encodeOutput(e,t)}return encodeOutput(new Uint8Array,t)}let n=this._buffer;if(this._autoPadding)n=pkcs7Pad(n);else if(n.length%16!=0)throw Error(`data not multiple of block size`);let r=[];for(let e=0;e<n.length;e+=16)r.push(this._encryptBlock(n.slice(e,e+16)));if(this._buffer=new Uint8Array,r.length===0)return encodeOutput(new Uint8Array,t);let i=new Uint8Array(r.length*16);for(let e=0;e<r.length;e++)i.set(r[e],e*16);return encodeOutput(i,t)}_encryptBlock(e){if(this._mode===`cbc`){let t=new Uint8Array(16);for(let n=0;n<16;n++)t[n]=e[n]^this._prevBlock[n];let n=aesEncryptBlock(t,this._roundKeys);return this._prevBlock=n,n}else if(this._mode===`ecb`)return aesEncryptBlock(e,this._roundKeys);throw Error(`Block encryption not supported for mode: ${this._mode}`)}_processStream(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];incrementCounter(this._counter)}return t}_processGcmEncrypt(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];gcmIncrementCounter(this._counter)}return this._gcmCiphertext.push(new Uint8Array(t)),this._gcmCiphertextLen+=t.length,t}},Decipher=class extends CipherBase{_prevBlock;_counter;_pendingUtf8=new Uint8Array;_gcmH=null;_gcmJ0=null;_gcmAAD=new Uint8Array;_gcmCiphertext=[];_gcmCiphertextLen=0;_gcmExpectedTag=null;_gcmAADSet=!1;constructor(e,t,n){super(e,t,n),this._prevBlock=new Uint8Array(this._iv),this._mode===`gcm`?(this._gcmH=aesEncryptBlock(new Uint8Array(16),this._roundKeys),this._gcmJ0=new Uint8Array(16),this._gcmJ0.set(this._iv.subarray(0,12)),this._gcmJ0[15]=1,this._counter=new Uint8Array(this._gcmJ0),gcmIncrementCounter(this._counter)):this._counter=new Uint8Array(this._iv)}setAAD(e){if(this._mode!==`gcm`)throw Error(`setAAD is only supported in GCM mode`);if(this._gcmCiphertextLen>0)throw Error(`setAAD must be called before update()`);return this._gcmAAD=new Uint8Array(e),this._gcmAADSet=!0,this}setAuthTag(t){if(this._mode!==`gcm`)throw Error(`setAuthTag is only supported in GCM mode`);return this._gcmExpectedTag=e.from(t),this}_encodeWithUtf8Handling(t,n,r){if(!n||n!==`utf8`&&n!==`utf-8`)return encodeOutput(t,n);let i;if(this._pendingUtf8.length>0?(i=new Uint8Array(this._pendingUtf8.length+t.length),i.set(this._pendingUtf8),i.set(t,this._pendingUtf8.length),this._pendingUtf8=new Uint8Array):i=t,!r){let e=incompleteUtf8Tail(i);e>0&&(this._pendingUtf8=new Uint8Array(i.slice(i.length-e)),i=new Uint8Array(i.slice(0,i.length-e)))}return e.from(i).toString(`utf8`)}update(e,t,n){let r=toBuffer(e,t),i=new Uint8Array(this._buffer.length+r.length);if(i.set(this._buffer),i.set(r,this._buffer.length),this._mode===`gcm`){this._gcmCiphertext.push(new Uint8Array(i)),this._gcmCiphertextLen+=i.length;let e=this._processGcmDecrypt(i);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(e,n,!1)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){let e=this._processStream(i);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(e,n,!1)}let a=Math.floor(i.length/16);if(a===0)return this._buffer=i,this._encodeWithUtf8Handling(new Uint8Array,n,!1);let o=(this._autoPadding?a-1:a)*16,s=[];for(let e=0;e<o;e+=16){let t=i.slice(e,e+16);s.push(this._decryptBlock(t))}this._buffer=i.slice(o);let c=new Uint8Array(s.length*16);for(let e=0;e<s.length;e++)c.set(s[e],e*16);return this._encodeWithUtf8Handling(c,n,!1)}final(e){if(this._finalized)throw Error(`Decipher already finalized`);if(this._finalized=!0,this._mode===`gcm`){let t=new Uint8Array;if(this._buffer.length>0&&(this._gcmCiphertext.push(new Uint8Array(this._buffer)),this._gcmCiphertextLen+=this._buffer.length,t=this._processGcmDecrypt(this._buffer),this._buffer=new Uint8Array),!this._gcmExpectedTag)throw Error(`Unsupported state or unable to authenticate data`);let n=new Uint8Array(this._gcmCiphertextLen),r=0;for(let e of this._gcmCiphertext)n.set(e,r),r+=e.length;let i=ghash(this._gcmH,this._gcmAAD,n),a=aesEncryptBlock(this._gcmJ0,this._roundKeys),o=new Uint8Array(16);for(let e=0;e<16;e++)o[e]=i[e]^a[e];let s=this._gcmExpectedTag,c=Math.min(s.length,16),l=0;for(let e=0;e<c;e++)l|=o[e]^s[e];if(l!==0)throw Error(`Unsupported state or unable to authenticate data`);return this._encodeWithUtf8Handling(t,e,!0)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){if(this._buffer.length>0){let t=this._processStream(this._buffer);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(t,e,!0)}return this._encodeWithUtf8Handling(new Uint8Array,e,!0)}if(this._buffer.length===0)return this._encodeWithUtf8Handling(new Uint8Array,e,!0);if(this._buffer.length%16!=0)throw Error(`bad decrypt`);let t=[];for(let e=0;e<this._buffer.length;e+=16)t.push(this._decryptBlock(this._buffer.slice(e,e+16)));let n=new Uint8Array(t.length*16);for(let e=0;e<t.length;e++)n.set(t[e],e*16);let r=this._autoPadding?pkcs7Unpad(n):n;return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(r,e,!0)}_decryptBlock(e){if(this._mode===`cbc`){let t=aesDecryptBlock(e,this._roundKeys),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=t[e]^this._prevBlock[e];return this._prevBlock=new Uint8Array(e),n}else if(this._mode===`ecb`)return aesDecryptBlock(e,this._roundKeys);throw Error(`Block decryption not supported for mode: ${this._mode}`)}_processStream(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];incrementCounter(this._counter)}return t}_processGcmDecrypt(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];gcmIncrementCounter(this._counter)}return t}};function createCipher(e,t){throw Error(`crypto.createCipher() is deprecated. Use createCipheriv() instead.`)}function createCipheriv(t,n,r){return new Cipher(t,typeof n==`string`?e.from(n):new Uint8Array(n),r==null?null:typeof r==`string`?e.from(r):new Uint8Array(r))}function createDecipher(e,t){throw Error(`crypto.createDecipher() is deprecated. Use createDecipheriv() instead.`)}function createDecipheriv(t,n,r){return new Decipher(t,typeof n==`string`?e.from(n):new Uint8Array(n),r==null?null:typeof r==`string`?e.from(r):new Uint8Array(r))}function getCiphers(){return[`aes-128-cbc`,`aes-128-ecb`,`aes-192-cbc`,`aes-192-ecb`,`aes-256-cbc`,`aes-256-ecb`,`aes-128-ctr`,`aes-192-ctr`,`aes-256-ctr`,`aes-128-cfb`,`aes-192-cfb`,`aes-256-cfb`,`aes-128-gcm`,`aes-192-gcm`,`aes-256-gcm`]}export{createCipher,createCipheriv,createDecipher,createDecipheriv,getCiphers};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Buffer as e}from"node:buffer";const t=new Uint8Array([99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22]),n=new Uint8Array([82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125]),r=[1,2,4,8,16,32,64,128,27,54];function gmul(e,t){let n=0;for(let r=0;r<8;r++){t&1&&(n^=e);let r=e&128;e=e<<1&255,r&&(e^=27),t>>=1}return n}function keyExpansion(e){let n=e.length/4,i=n+6,a=4*(i+1),o=Array(a);for(let t=0;t<n;t++)o[t]=new Uint8Array([e[4*t],e[4*t+1],e[4*t+2],e[4*t+3]]);for(let e=n;e<a;e++){let i=new Uint8Array(o[e-1]);e%n===0?i=new Uint8Array([t[i[1]]^r[e/n-1],t[i[2]],t[i[3]],t[i[0]]]):n>6&&e%n===4&&(i=new Uint8Array([t[i[0]],t[i[1]],t[i[2]],t[i[3]]])),o[e]=new Uint8Array(4);for(let t=0;t<4;t++)o[e][t]=o[e-n][t]^i[t]}let s=[];for(let e=0;e<=i;e++){let t=new Uint8Array(16);for(let n=0;n<4;n++)t[4*n]=o[4*e+n][0],t[4*n+1]=o[4*e+n][1],t[4*n+2]=o[4*e+n][2],t[4*n+3]=o[4*e+n][3];s.push(t)}return s}function aesEncryptBlock(e,n){let r=new Uint8Array(e),i=n.length-1;for(let e=0;e<16;e++)r[e]^=n[0][e];for(let e=1;e<i;e++){for(let e=0;e<16;e++)r[e]=t[r[e]];let i=r[1];r[1]=r[5],r[5]=r[9],r[9]=r[13],r[13]=i;let a=r[2],o=r[6];r[2]=r[10],r[6]=r[14],r[10]=a,r[14]=o;let s=r[15];r[15]=r[11],r[11]=r[7],r[7]=r[3],r[3]=s;for(let e=0;e<4;e++){let t=e*4,n=r[t],i=r[t+1],a=r[t+2],o=r[t+3];r[t]=gmul(2,n)^gmul(3,i)^a^o,r[t+1]=n^gmul(2,i)^gmul(3,a)^o,r[t+2]=n^i^gmul(2,a)^gmul(3,o),r[t+3]=gmul(3,n)^i^a^gmul(2,o)}for(let t=0;t<16;t++)r[t]^=n[e][t]}for(let e=0;e<16;e++)r[e]=t[r[e]];let a=r[1];r[1]=r[5],r[5]=r[9],r[9]=r[13],r[13]=a;let o=r[2],s=r[6];r[2]=r[10],r[6]=r[14],r[10]=o,r[14]=s;let c=r[15];r[15]=r[11],r[11]=r[7],r[7]=r[3],r[3]=c;for(let e=0;e<16;e++)r[e]^=n[i][e];return r}function aesDecryptBlock(e,t){let r=new Uint8Array(e),i=t.length-1;for(let e=0;e<16;e++)r[e]^=t[i][e];for(let e=i-1;e>0;e--){let i=r[13];r[13]=r[9],r[9]=r[5],r[5]=r[1],r[1]=i;let a=r[10],o=r[14];r[10]=r[2],r[14]=r[6],r[2]=a,r[6]=o;let s=r[3];r[3]=r[7],r[7]=r[11],r[11]=r[15],r[15]=s;for(let e=0;e<16;e++)r[e]=n[r[e]];for(let n=0;n<16;n++)r[n]^=t[e][n];for(let e=0;e<4;e++){let t=e*4,n=r[t],i=r[t+1],a=r[t+2],o=r[t+3];r[t]=gmul(14,n)^gmul(11,i)^gmul(13,a)^gmul(9,o),r[t+1]=gmul(9,n)^gmul(14,i)^gmul(11,a)^gmul(13,o),r[t+2]=gmul(13,n)^gmul(9,i)^gmul(14,a)^gmul(11,o),r[t+3]=gmul(11,n)^gmul(13,i)^gmul(9,a)^gmul(14,o)}}let a=r[13];r[13]=r[9],r[9]=r[5],r[5]=r[1],r[1]=a;let o=r[10],s=r[14];r[10]=r[2],r[14]=r[6],r[2]=o,r[6]=s;let c=r[3];r[3]=r[7],r[7]=r[11],r[11]=r[15],r[15]=c;for(let e=0;e<16;e++)r[e]=n[r[e]];for(let e=0;e<16;e++)r[e]^=t[0][e];return r}function incrementCounter(e){for(let t=15;t>=0&&++e[t]===0;t--);}function gcmIncrementCounter(e){for(let t=15;t>=12&&++e[t]===0;t--);}function gfMul(e,t){let n=new Uint8Array(16),r=new Uint8Array(e);for(let e=0;e<128;e++){if(t[e>>>3]&1<<7-(e&7))for(let e=0;e<16;e++)n[e]^=r[e];let i=r[15]&1;for(let e=15;e>0;e--)r[e]=r[e]>>>1|(r[e-1]&1)<<7;r[0]>>>=1,i&&(r[0]^=225)}return n}function ghash(e,t,n){let r=new Uint8Array(16),i=Math.ceil(t.length/16)||0;for(let n=0;n<i;n++){let i=n*16,a=Math.min(i+16,t.length);for(let e=0;e<16;e++){let n=i+e;n<a&&(r[e]^=t[n])}let o=gfMul(r,e);r.set(o)}let a=Math.ceil(n.length/16)||0;for(let t=0;t<a;t++){let i=t*16,a=Math.min(i+16,n.length);for(let e=0;e<16;e++){let t=i+e;t<a&&(r[e]^=n[t])}let o=gfMul(r,e);r.set(o)}let o=new Uint8Array(16),s=t.length*8,c=n.length*8,l=Math.floor(s/4294967296),u=s>>>0;o[0]=l>>>24&255,o[1]=l>>>16&255,o[2]=l>>>8&255,o[3]=l&255,o[4]=u>>>24&255,o[5]=u>>>16&255,o[6]=u>>>8&255,o[7]=u&255;let d=Math.floor(c/4294967296),f=c>>>0;o[8]=d>>>24&255,o[9]=d>>>16&255,o[10]=d>>>8&255,o[11]=d&255,o[12]=f>>>24&255,o[13]=f>>>16&255,o[14]=f>>>8&255,o[15]=f&255;for(let e=0;e<16;e++)r[e]^=o[e];let p=gfMul(r,e);return r.set(p),r}function parseAlgorithm(e){let t=e.toLowerCase().match(/^aes-(128|192|256)-(cbc|ctr|ecb|cfb|ofb|gcm)$/);if(!t)throw Error(`Unsupported cipher algorithm: ${e}`);let n=parseInt(t[1]),r=t[2];return{keySize:n/8,ivSize:r===`ecb`?0:r===`gcm`?12:16,mode:r}}function toBuffer(t,n){return typeof t==`string`?e.from(t,n||`utf8`):e.from(t)}function encodeOutput(t,n){return n?e.from(t).toString(n):e.from(t)}function incompleteUtf8Tail(e){if(e.length===0)return 0;let t=e.length;for(let n=1;n<=Math.min(4,t);n++){let r=e[t-n];if(!(r&128))return 0;if((r&192)==128)continue;let i;if((r&224)==192)i=2;else if((r&240)==224)i=3;else if((r&248)==240)i=4;else return 0;return n<i?n:0}return 0}function pkcs7Pad(e){let t=16-e.length%16,n=new Uint8Array(e.length+t);n.set(e);for(let r=e.length;r<n.length;r++)n[r]=t;return n}function pkcs7Unpad(e){if(e.length===0||e.length%16!=0)throw Error(`bad decrypt`);let t=e[e.length-1];if(t===0||t>16)throw Error(`bad decrypt`);for(let n=e.length-t;n<e.length;n++)if(e[n]!==t)throw Error(`bad decrypt`);return new Uint8Array(e.slice(0,e.length-t))}var CipherBase=class{_roundKeys;_iv;_mode;_buffer=new Uint8Array;_autoPadding=!0;_finalized=!1;constructor(e,t,n){let r=parseAlgorithm(e);if(t.length!==r.keySize)throw Error(`Invalid key length ${t.length}, expected ${r.keySize} for ${e}`);if(r.ivSize>0&&(!n||n.length!==r.ivSize))throw Error(`Invalid IV length ${n?.length??0}, expected ${r.ivSize} for ${e}`);this._roundKeys=keyExpansion(t),this._iv=n?new Uint8Array(n):new Uint8Array(16),this._mode=r.mode}setAutoPadding(e){return this._autoPadding=e,this}},Cipher=class extends CipherBase{_prevBlock;_counter;_gcmH=null;_gcmJ0=null;_gcmAAD=new Uint8Array;_gcmCiphertext=[];_gcmCiphertextLen=0;_gcmAuthTag=null;_gcmAADSet=!1;constructor(e,t,n){super(e,t,n),this._prevBlock=new Uint8Array(this._iv),this._mode===`gcm`?(this._gcmH=aesEncryptBlock(new Uint8Array(16),this._roundKeys),this._gcmJ0=new Uint8Array(16),this._gcmJ0.set(this._iv.subarray(0,12)),this._gcmJ0[15]=1,this._counter=new Uint8Array(this._gcmJ0),gcmIncrementCounter(this._counter)):this._counter=new Uint8Array(this._iv)}setAAD(e){if(this._mode!==`gcm`)throw Error(`setAAD is only supported in GCM mode`);if(this._gcmCiphertextLen>0)throw Error(`setAAD must be called before update()`);return this._gcmAAD=new Uint8Array(e),this._gcmAADSet=!0,this}getAuthTag(){if(this._mode!==`gcm`)throw Error(`getAuthTag is only supported in GCM mode`);if(!this._gcmAuthTag)throw Error(`getAuthTag must be called after final()`);return e.from(this._gcmAuthTag)}update(e,t,n){let r=toBuffer(e,t),i=new Uint8Array(this._buffer.length+r.length);if(i.set(this._buffer),i.set(r,this._buffer.length),this._mode===`gcm`){let e=this._processGcmEncrypt(i);return this._buffer=new Uint8Array,encodeOutput(e,n)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){let e=this._processStream(i);return this._buffer=new Uint8Array,encodeOutput(e,n)}let a=Math.floor(i.length/16)*16,o=[];for(let e=0;e<a;e+=16){let t=i.slice(e,e+16);o.push(this._encryptBlock(t))}this._buffer=i.slice(a);let s=new Uint8Array(o.length*16);for(let e=0;e<o.length;e++)s.set(o[e],e*16);return encodeOutput(s,n)}final(t){if(this._finalized)throw Error(`Cipher already finalized`);if(this._finalized=!0,this._mode===`gcm`){let n=new Uint8Array;this._buffer.length>0&&(n=this._processGcmEncrypt(this._buffer),this._buffer=new Uint8Array);let r=new Uint8Array(this._gcmCiphertextLen),i=0;for(let e of this._gcmCiphertext)r.set(e,i),i+=e.length;let a=ghash(this._gcmH,this._gcmAAD,r),o=aesEncryptBlock(this._gcmJ0,this._roundKeys),s=new Uint8Array(16);for(let e=0;e<16;e++)s[e]=a[e]^o[e];return this._gcmAuthTag=e.from(s),encodeOutput(n,t)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){if(this._buffer.length>0){let e=this._processStream(this._buffer);return this._buffer=new Uint8Array,encodeOutput(e,t)}return encodeOutput(new Uint8Array,t)}let n=this._buffer;if(this._autoPadding)n=pkcs7Pad(n);else if(n.length%16!=0)throw Error(`data not multiple of block size`);let r=[];for(let e=0;e<n.length;e+=16)r.push(this._encryptBlock(n.slice(e,e+16)));if(this._buffer=new Uint8Array,r.length===0)return encodeOutput(new Uint8Array,t);let i=new Uint8Array(r.length*16);for(let e=0;e<r.length;e++)i.set(r[e],e*16);return encodeOutput(i,t)}_encryptBlock(e){if(this._mode===`cbc`){let t=new Uint8Array(16);for(let n=0;n<16;n++)t[n]=e[n]^this._prevBlock[n];let n=aesEncryptBlock(t,this._roundKeys);return this._prevBlock=n,n}else if(this._mode===`ecb`)return aesEncryptBlock(e,this._roundKeys);throw Error(`Block encryption not supported for mode: ${this._mode}`)}_processStream(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];incrementCounter(this._counter)}return t}_processGcmEncrypt(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];gcmIncrementCounter(this._counter)}return this._gcmCiphertext.push(new Uint8Array(t)),this._gcmCiphertextLen+=t.length,t}},Decipher=class extends CipherBase{_prevBlock;_counter;_pendingUtf8=new Uint8Array;_gcmH=null;_gcmJ0=null;_gcmAAD=new Uint8Array;_gcmCiphertext=[];_gcmCiphertextLen=0;_gcmExpectedTag=null;_gcmAADSet=!1;constructor(e,t,n){super(e,t,n),this._prevBlock=new Uint8Array(this._iv),this._mode===`gcm`?(this._gcmH=aesEncryptBlock(new Uint8Array(16),this._roundKeys),this._gcmJ0=new Uint8Array(16),this._gcmJ0.set(this._iv.subarray(0,12)),this._gcmJ0[15]=1,this._counter=new Uint8Array(this._gcmJ0),gcmIncrementCounter(this._counter)):this._counter=new Uint8Array(this._iv)}setAAD(e){if(this._mode!==`gcm`)throw Error(`setAAD is only supported in GCM mode`);if(this._gcmCiphertextLen>0)throw Error(`setAAD must be called before update()`);return this._gcmAAD=new Uint8Array(e),this._gcmAADSet=!0,this}setAuthTag(t){if(this._mode!==`gcm`)throw Error(`setAuthTag is only supported in GCM mode`);return this._gcmExpectedTag=e.from(t),this}_encodeWithUtf8Handling(t,n,r){if(!n||n!==`utf8`&&n!==`utf-8`)return encodeOutput(t,n);let i;if(this._pendingUtf8.length>0?(i=new Uint8Array(this._pendingUtf8.length+t.length),i.set(this._pendingUtf8),i.set(t,this._pendingUtf8.length),this._pendingUtf8=new Uint8Array):i=t,!r){let e=incompleteUtf8Tail(i);e>0&&(this._pendingUtf8=new Uint8Array(i.slice(i.length-e)),i=new Uint8Array(i.slice(0,i.length-e)))}return e.from(i).toString(`utf8`)}update(e,t,n){let r=toBuffer(e,t),i=new Uint8Array(this._buffer.length+r.length);if(i.set(this._buffer),i.set(r,this._buffer.length),this._mode===`gcm`){this._gcmCiphertext.push(new Uint8Array(i)),this._gcmCiphertextLen+=i.length;let e=this._processGcmDecrypt(i);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(e,n,!1)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){let e=this._processStream(i);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(e,n,!1)}let a=Math.floor(i.length/16);if(a===0)return this._buffer=i,this._encodeWithUtf8Handling(new Uint8Array,n,!1);let o=(this._autoPadding?a-1:a)*16,s=[];for(let e=0;e<o;e+=16){let t=i.slice(e,e+16);s.push(this._decryptBlock(t))}this._buffer=i.slice(o);let c=new Uint8Array(s.length*16);for(let e=0;e<s.length;e++)c.set(s[e],e*16);return this._encodeWithUtf8Handling(c,n,!1)}final(e){if(this._finalized)throw Error(`Decipher already finalized`);if(this._finalized=!0,this._mode===`gcm`){let t=new Uint8Array;if(this._buffer.length>0&&(this._gcmCiphertext.push(new Uint8Array(this._buffer)),this._gcmCiphertextLen+=this._buffer.length,t=this._processGcmDecrypt(this._buffer),this._buffer=new Uint8Array),!this._gcmExpectedTag)throw Error(`Unsupported state or unable to authenticate data`);let n=new Uint8Array(this._gcmCiphertextLen),r=0;for(let e of this._gcmCiphertext)n.set(e,r),r+=e.length;let i=ghash(this._gcmH,this._gcmAAD,n),a=aesEncryptBlock(this._gcmJ0,this._roundKeys),o=new Uint8Array(16);for(let e=0;e<16;e++)o[e]=i[e]^a[e];let s=this._gcmExpectedTag,c=Math.min(s.length,16),l=0;for(let e=0;e<c;e++)l|=o[e]^s[e];if(l!==0)throw Error(`Unsupported state or unable to authenticate data`);return this._encodeWithUtf8Handling(t,e,!0)}if(this._mode===`ctr`||this._mode===`cfb`||this._mode===`ofb`){if(this._buffer.length>0){let t=this._processStream(this._buffer);return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(t,e,!0)}return this._encodeWithUtf8Handling(new Uint8Array,e,!0)}if(this._buffer.length===0)return this._encodeWithUtf8Handling(new Uint8Array,e,!0);if(this._buffer.length%16!=0)throw Error(`bad decrypt`);let t=[];for(let e=0;e<this._buffer.length;e+=16)t.push(this._decryptBlock(this._buffer.slice(e,e+16)));let n=new Uint8Array(t.length*16);for(let e=0;e<t.length;e++)n.set(t[e],e*16);let r=this._autoPadding?pkcs7Unpad(n):n;return this._buffer=new Uint8Array,this._encodeWithUtf8Handling(r,e,!0)}_decryptBlock(e){if(this._mode===`cbc`){let t=aesDecryptBlock(e,this._roundKeys),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=t[e]^this._prevBlock[e];return this._prevBlock=new Uint8Array(e),n}else if(this._mode===`ecb`)return aesDecryptBlock(e,this._roundKeys);throw Error(`Block decryption not supported for mode: ${this._mode}`)}_processStream(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];incrementCounter(this._counter)}return t}_processGcmDecrypt(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=16){let r=aesEncryptBlock(this._counter,this._roundKeys),i=Math.min(16,e.length-n);for(let a=0;a<i;a++)t[n+a]=e[n+a]^r[a];gcmIncrementCounter(this._counter)}return t}};function createCipher(e,t){throw Error(`crypto.createCipher() is deprecated. Use createCipheriv() instead.`)}function createCipheriv(t,n,r){return new Cipher(t,typeof n==`string`?e.from(n):new Uint8Array(n),r==null?null:typeof r==`string`?e.from(r):new Uint8Array(r))}function createDecipher(e,t){throw Error(`crypto.createDecipher() is deprecated. Use createDecipheriv() instead.`)}function createDecipheriv(t,n,r){return new Decipher(t,typeof n==`string`?e.from(n):new Uint8Array(n),r==null?null:typeof r==`string`?e.from(r):new Uint8Array(r))}function getCiphers(){return[`aes-128-cbc`,`aes-128-ecb`,`aes-192-cbc`,`aes-192-ecb`,`aes-256-cbc`,`aes-256-ecb`,`aes-128-ctr`,`aes-192-ctr`,`aes-256-ctr`,`aes-128-cfb`,`aes-192-cfb`,`aes-256-cfb`,`aes-128-gcm`,`aes-192-gcm`,`aes-256-gcm`]}export{createCipher,createCipheriv,createDecipher,createDecipheriv,getCiphers};
|
package/lib/esm/crypto-utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as e}from"node:buffer";function normalizeAlgorithm(e){return e.toLowerCase().replace(/-/g,``)}const t={md5:16,sha1:20,sha256:32,sha384:48,sha512:64},n={md5:64,sha1:64,sha256:64,sha384:128,sha512:128},r=new Set([`md5`,`sha1`,`sha256`,`sha384`,`sha512`]);function hashSize(e){let n=t[normalizeAlgorithm(e)];if(n===void 0)throw Error(`Unknown hash algorithm: ${e}`);return n}function toBuffer(t,n){return typeof t==`string`?e.from(t,n||`utf8`):t instanceof DataView?e.from(t.buffer,t.byteOffset,t.byteLength):(t instanceof ArrayBuffer,e.from(t))}export{n as BLOCK_SIZES,t as DIGEST_SIZES,r as SUPPORTED_ALGORITHMS,hashSize,normalizeAlgorithm,toBuffer};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Buffer as e}from"node:buffer";function normalizeAlgorithm(e){return e.toLowerCase().replace(/-/g,``)}const t={md5:16,sha1:20,sha256:32,sha384:48,sha512:64},n={md5:64,sha1:64,sha256:64,sha384:128,sha512:128},r=new Set([`md5`,`sha1`,`sha256`,`sha384`,`sha512`]);function hashSize(e){let n=t[normalizeAlgorithm(e)];if(n===void 0)throw Error(`Unknown hash algorithm: ${e}`);return n}function toBuffer(t,n){return typeof t==`string`?e.from(t,n||`utf8`):t instanceof DataView?e.from(t.buffer,t.byteOffset,t.byteLength):(t instanceof ArrayBuffer,e.from(t))}export{n as BLOCK_SIZES,t as DIGEST_SIZES,r as SUPPORTED_ALGORITHMS,hashSize,normalizeAlgorithm,toBuffer};
|
package/lib/esm/dh.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{modPow as e}from"./bigint-math.js";import{randomBytes as t}from"./random.js";import{Buffer as n}from"node:buffer";const r={modp1:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff`},modp2:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff`},modp5:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff`},modp14:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff`},modp15:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff`},modp16:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff`},modp17:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff`},modp18:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff`}};function bigIntToBuffer(e){if(e===0n)return n.from([0]);let t=e.toString(16);return t.length%2!=0&&(t=`0`+t),n.from(t,`hex`)}function bufferToBigInt(e){if(e.length===0)return 0n;let t=n.from(e).toString(`hex`);return t.length===0?0n:BigInt(`0x`+t)}function bitLength(e){return e===0n?0:e.toString(2).length}const i=[];{let e=1e3,t=new Uint8Array(e+1);for(let n=2;n*n<=e;n++)if(!t[n])for(let r=n*n;r<=e;r+=n)t[r]=1;for(let n=2;n<=e;n++)t[n]||i.push(n)}function simpleSieve(e){for(let t of i){let n=BigInt(t);if(e%n===0n)return e===n}return!0}function fermatTest(t){return e(2n,t-1n,t)===1n}function millerRabinTest(t){if(t<2n)return!1;if(t===2n||t===3n)return!0;if(t%2n==0n)return!1;let n=t-1n,r=0;for(;n%2n==0n;)n/=2n,r++;for(let i of[2n,3n,5n,7n,11n,13n]){if(i>=t)continue;let a=e(i,n,t);if(a===1n||a===t-1n)continue;let o=!0;for(let n=0;n<r-1;n++)if(a=e(a,2n,t),a===t-1n){o=!1;break}if(o)return!1}return!0}function checkPrime(e,t){let n=t.toString(`hex`),r=0;if(e%2n==0n||!simpleSieve(e)||!fermatTest(e)||!millerRabinTest(e))return r+=1,n===`02`||n===`05`?r+=8:r+=4,r;switch(millerRabinTest(e>>1n)||(r+=2),n){case`02`:e%24n!=11n&&(r+=8);break;case`05`:{let t=e%10n;t!==3n&&t!==7n&&(r+=8)}break;default:r+=4}return r}const a={};function getCachedCheckPrime(e,t){let n=t.toString(`hex`)+`_`+e.toString(16);if(n in a)return a[n];let r=checkPrime(e,t);return a[n]=r,r}function formatReturnValue(e,t){let n=bigIntToBuffer(e);return t?n.toString(t):n}var DiffieHellman=class{_prime;_generator;_generatorBuf;_primeByteLength;_pubKey;_privKey;_primeCode;_malleable;constructor(e,t,n=!1){this._prime=bufferToBigInt(e),this._generatorBuf=t,this._generator=bufferToBigInt(t),this._primeByteLength=e.length,this._pubKey=void 0,this._privKey=void 0,this._primeCode=void 0,this._malleable=n,n||(this._primeCode=0,this.setPublicKey=void 0,this.setPrivateKey=void 0)}get verifyError(){return typeof this._primeCode!=`number`&&(this._primeCode=getCachedCheckPrime(this._prime,this._generatorBuf)),this._primeCode}generateKeys(n){if(!this._privKey){let e=t(this._primeByteLength);this._privKey=bufferToBigInt(e)}return this._pubKey=e(this._generator,this._privKey,this._prime),this.getPublicKey(n)}computeSecret(t,r,i){let a;a=typeof t==`string`?n.from(t,r||`utf8`):n.from(t);let o=bufferToBigInt(a);if(!this._privKey)throw Error(`You must generate keys before computing a secret`);if(o<=0n||o>=this._prime)throw Error(`Supplied key is too large`);let s=bigIntToBuffer(e(o,this._privKey,this._prime)),c=this._primeByteLength;if(s.length<c){let e=n.alloc(c);s.copy(e,c-s.length),s=e}return i?s.toString(i):s}getPrime(e){return formatReturnValue(this._prime,e)}getGenerator(e){return formatReturnValue(this._generator,e)}getPublicKey(e){if(!this._pubKey)throw Error(`No public key - call generateKeys() first`);return formatReturnValue(this._pubKey,e)}getPrivateKey(e){if(!this._privKey)throw Error(`No private key - call generateKeys() first`);return formatReturnValue(this._privKey,e)}setPublicKey(e,t){if(!this._malleable)throw Error(`setPublicKey is not available for predefined DH groups`);let r=typeof e==`string`?n.from(e,t||`utf8`):n.from(e);this._pubKey=bufferToBigInt(r)}setPrivateKey(e,t){if(!this._malleable)throw Error(`setPrivateKey is not available for predefined DH groups`);let r=typeof e==`string`?n.from(e,t||`utf8`):n.from(e);this._privKey=bufferToBigInt(r)}};function generatePrime(e,r){let i=bufferToBigInt(r);if(e<16)return i===2n||i===5n?n.from([140,123]):n.from([140,39]);let a=Math.ceil(e/8),o=2n,s=4n;for(;;){let n=bufferToBigInt(t(a));for(;bitLength(n)>e;)n>>=1n;if(n%o===0n&&(n+=1n),n&o||(n+=o),i===o)for(;n%24n!=11n;)n+=s;else if(i===5n)for(;n%10n!=3n;)n+=s;let r=n>>1n;if(simpleSieve(r)&&simpleSieve(n)&&fermatTest(r)&&fermatTest(n)&&millerRabinTest(r)&&millerRabinTest(n))return bigIntToBuffer(n)}}const o={binary:!0,hex:!0,base64:!0,latin1:!0,utf8:!0,"utf-8":!0,base64url:!0,ascii:!0,ucs2:!0,"ucs-2":!0,utf16le:!0,"utf-16le":!0};function createDiffieHellman(e,t,r,i){if(t!==void 0&&typeof t!=`number`&&(n.isBuffer(t)||t instanceof Uint8Array||typeof t==`string`&&!(t in o)))return createDiffieHellman(e,`binary`,t,r);let a=t||`binary`,s=i||`binary`,c=n.from([2]);if(r!==void 0&&(typeof r==`number`?(c=n.alloc(1),c[0]=r):c=n.isBuffer(r)?r:n.from(r,s)),typeof e==`number`)return new DiffieHellman(generatePrime(e,c),c,!0);let l;return l=n.isBuffer(e)?e:e instanceof Uint8Array?n.from(e):n.from(e,a),new DiffieHellman(l,c,!0)}function getDiffieHellman(e){let t=r[e];if(!t)throw Error(`Unknown group: ${e}. Supported groups: ${Object.keys(r).join(`, `)}`);return new DiffieHellman(n.from(t.prime,`hex`),n.from(t.gen,`hex`),!1)}const s=getDiffieHellman,c=getDiffieHellman;export{DiffieHellman,c as DiffieHellmanGroup,createDiffieHellman,s as createDiffieHellmanGroup,getDiffieHellman};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{modPow as e}from"./bigint-math.js";import{randomBytes as t}from"./random.js";import{Buffer as n}from"node:buffer";const r={modp1:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff`},modp2:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff`},modp5:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff`},modp14:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff`},modp15:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff`},modp16:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff`},modp17:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff`},modp18:{gen:`02`,prime:`ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff`}};function bigIntToBuffer(e){if(e===0n)return n.from([0]);let t=e.toString(16);return t.length%2!=0&&(t=`0`+t),n.from(t,`hex`)}function bufferToBigInt(e){if(e.length===0)return 0n;let t=n.from(e).toString(`hex`);return t.length===0?0n:BigInt(`0x`+t)}function bitLength(e){return e===0n?0:e.toString(2).length}const i=[];{let e=1e3,t=new Uint8Array(e+1);for(let n=2;n*n<=e;n++)if(!t[n])for(let r=n*n;r<=e;r+=n)t[r]=1;for(let n=2;n<=e;n++)t[n]||i.push(n)}function simpleSieve(e){for(let t of i){let n=BigInt(t);if(e%n===0n)return e===n}return!0}function fermatTest(t){return e(2n,t-1n,t)===1n}function millerRabinTest(t){if(t<2n)return!1;if(t===2n||t===3n)return!0;if(t%2n==0n)return!1;let n=t-1n,r=0;for(;n%2n==0n;)n/=2n,r++;for(let i of[2n,3n,5n,7n,11n,13n]){if(i>=t)continue;let a=e(i,n,t);if(a===1n||a===t-1n)continue;let o=!0;for(let n=0;n<r-1;n++)if(a=e(a,2n,t),a===t-1n){o=!1;break}if(o)return!1}return!0}function checkPrime(e,t){let n=t.toString(`hex`),r=0;if(e%2n==0n||!simpleSieve(e)||!fermatTest(e)||!millerRabinTest(e))return r+=1,n===`02`||n===`05`?r+=8:r+=4,r;switch(millerRabinTest(e>>1n)||(r+=2),n){case`02`:e%24n!=11n&&(r+=8);break;case`05`:{let t=e%10n;t!==3n&&t!==7n&&(r+=8)}break;default:r+=4}return r}const a={};function getCachedCheckPrime(e,t){let n=t.toString(`hex`)+`_`+e.toString(16);if(n in a)return a[n];let r=checkPrime(e,t);return a[n]=r,r}function formatReturnValue(e,t){let n=bigIntToBuffer(e);return t?n.toString(t):n}var DiffieHellman=class{_prime;_generator;_generatorBuf;_primeByteLength;_pubKey;_privKey;_primeCode;_malleable;constructor(e,t,n=!1){this._prime=bufferToBigInt(e),this._generatorBuf=t,this._generator=bufferToBigInt(t),this._primeByteLength=e.length,this._pubKey=void 0,this._privKey=void 0,this._primeCode=void 0,this._malleable=n,n||(this._primeCode=0,this.setPublicKey=void 0,this.setPrivateKey=void 0)}get verifyError(){return typeof this._primeCode!=`number`&&(this._primeCode=getCachedCheckPrime(this._prime,this._generatorBuf)),this._primeCode}generateKeys(n){if(!this._privKey){let e=t(this._primeByteLength);this._privKey=bufferToBigInt(e)}return this._pubKey=e(this._generator,this._privKey,this._prime),this.getPublicKey(n)}computeSecret(t,r,i){let a;a=typeof t==`string`?n.from(t,r||`utf8`):n.from(t);let o=bufferToBigInt(a);if(!this._privKey)throw Error(`You must generate keys before computing a secret`);if(o<=0n||o>=this._prime)throw Error(`Supplied key is too large`);let s=bigIntToBuffer(e(o,this._privKey,this._prime)),c=this._primeByteLength;if(s.length<c){let e=n.alloc(c);s.copy(e,c-s.length),s=e}return i?s.toString(i):s}getPrime(e){return formatReturnValue(this._prime,e)}getGenerator(e){return formatReturnValue(this._generator,e)}getPublicKey(e){if(!this._pubKey)throw Error(`No public key - call generateKeys() first`);return formatReturnValue(this._pubKey,e)}getPrivateKey(e){if(!this._privKey)throw Error(`No private key - call generateKeys() first`);return formatReturnValue(this._privKey,e)}setPublicKey(e,t){if(!this._malleable)throw Error(`setPublicKey is not available for predefined DH groups`);let r=typeof e==`string`?n.from(e,t||`utf8`):n.from(e);this._pubKey=bufferToBigInt(r)}setPrivateKey(e,t){if(!this._malleable)throw Error(`setPrivateKey is not available for predefined DH groups`);let r=typeof e==`string`?n.from(e,t||`utf8`):n.from(e);this._privKey=bufferToBigInt(r)}};function generatePrime(e,r){let i=bufferToBigInt(r);if(e<16)return i===2n||i===5n?n.from([140,123]):n.from([140,39]);let a=Math.ceil(e/8),o=2n,s=4n;for(;;){let n=bufferToBigInt(t(a));for(;bitLength(n)>e;)n>>=1n;if(n%o===0n&&(n+=1n),n&o||(n+=o),i===o)for(;n%24n!=11n;)n+=s;else if(i===5n)for(;n%10n!=3n;)n+=s;let r=n>>1n;if(simpleSieve(r)&&simpleSieve(n)&&fermatTest(r)&&fermatTest(n)&&millerRabinTest(r)&&millerRabinTest(n))return bigIntToBuffer(n)}}const o={binary:!0,hex:!0,base64:!0,latin1:!0,utf8:!0,"utf-8":!0,base64url:!0,ascii:!0,ucs2:!0,"ucs-2":!0,utf16le:!0,"utf-16le":!0};function createDiffieHellman(e,t,r,i){if(t!==void 0&&typeof t!=`number`&&(n.isBuffer(t)||t instanceof Uint8Array||typeof t==`string`&&!(t in o)))return createDiffieHellman(e,`binary`,t,r);let a=t||`binary`,s=i||`binary`,c=n.from([2]);if(r!==void 0&&(typeof r==`number`?(c=n.alloc(1),c[0]=r):c=n.isBuffer(r)?r:n.from(r,s)),typeof e==`number`)return new DiffieHellman(generatePrime(e,c),c,!0);let l;return l=n.isBuffer(e)?e:e instanceof Uint8Array?n.from(e):n.from(e,a),new DiffieHellman(l,c,!0)}function getDiffieHellman(e){let t=r[e];if(!t)throw Error(`Unknown group: ${e}. Supported groups: ${Object.keys(r).join(`, `)}`);return new DiffieHellman(n.from(t.prime,`hex`),n.from(t.gen,`hex`),!1)}const s=getDiffieHellman,c=getDiffieHellman;export{DiffieHellman,c as DiffieHellmanGroup,createDiffieHellman,s as createDiffieHellmanGroup,getDiffieHellman};
|
package/lib/esm/ecdh.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{modPow as e}from"./bigint-math.js";import{randomBytes as t}from"./random.js";import{Buffer as n}from"node:buffer";const r={secp256k1:{p:115792089237316195423570985008687907853269984665640564039457584007908834671663n,a:0n,b:7n,Gx:55066263022277343669578718895168534326250603453777594175500187360389116729240n,Gy:32670510020758816978083085130507043184471273380659243275938904335757337482424n,n:115792089237316195423570985008687907852837564279074904382605163141518161494337n,byteLength:32},prime256v1:{p:115792089210356248762697446949407573530086143415290314195533631308867097853951n,a:115792089210356248762697446949407573530086143415290314195533631308867097853951n-3n,b:41058363725152142129326129780047268409114441015993725554835256314039467401291n,Gx:48439561293906451759052585252797914202762949526041747995844080717082404635286n,Gy:36134250956749795798585127919587881956611106672985015071877198253568414405109n,n:115792089210356248762697446949407573529996955224135760342422259061068512044369n,byteLength:32},secp384r1:{p:39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319n,a:39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319n-3n,b:27580193559959705877849011840389048093056905856361568521428707301988689241309860865136260764883745107765439761230575n,Gx:26247035095799689268623156744566981891852923491109213387815615900925518854738050089022388053975719786650872476732087n,Gy:8325710961489029985546751289520108179287853048861315594709205902480503199884419224438643760392947333078086511627871n,n:39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643n,byteLength:48},secp521r1:{p:6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151n,a:6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151n-3n,b:1093849038073734274511112390766805569936207598951683748994586394495953116150735016013708737573759623248592132296706313309438452531591012912142327488478985984n,Gx:2661740802050217063228768716723360960729859168756973147706671368418802944996427808491545080627771902352094241225065558662157113545570916814161637315895999846n,Gy:3757180025770020463545507224491183603594455134769762486694567779615544477440556316691234405012945539562144444537289428522585666729196580810124344277578376784n,n:6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449n,byteLength:66}},i={secp256k1:`secp256k1`,prime256v1:`prime256v1`,secp256r1:`prime256v1`,"p-256":`prime256v1`,p256:`prime256v1`,secp384r1:`secp384r1`,"p-384":`secp384r1`,p384:`secp384r1`,secp521r1:`secp521r1`,"p-521":`secp521r1`,p521:`secp521r1`};function mod(e,t){let n=e%t;return n<0n?n+t:n}function modInverse(e,t){if(e=mod(e,t),e===0n)throw Error(`No modular inverse for zero`);let[n,r]=[e,t],[i,a]=[1n,0n];for(;r!==0n;){let e=n/r;[n,r]=[r,n-e*r],[i,a]=[a,i-e*a]}if(n!==1n)throw Error(`Modular inverse does not exist`);return mod(i,t)}function pointAdd(e,t,n){if(e===null)return t;if(t===null)return e;let{p:r}=n;if(e.x===t.x)return mod(e.y+t.y,r)===0n?null:pointDouble(e,n);let i=mod(t.x-e.x,r),a=mod(mod(t.y-e.y,r)*modInverse(i,r),r),o=mod(a*a-e.x-t.x,r);return{x:o,y:mod(a*(e.x-o)-e.y,r)}}function pointDouble(e,t){if(e===null)return null;let{a:n,p:r}=t;if(e.y===0n)return null;let i=mod(mod(3n*e.x*e.x+n,r)*modInverse(mod(2n*e.y,r),r),r),a=mod(i*i-2n*e.x,r);return{x:a,y:mod(i*(e.x-a)-e.y,r)}}function scalarMul(e,t,n){if(t===null||e===0n)return null;let{n:r}=n;if(e=mod(e,r),e===0n)return null;let i=null,a=t,o=e.toString(2);for(let e=0;e<o.length;e++)o[e]===`1`?(i=pointAdd(i,a,n),a=pointDouble(a,n)):(a=pointAdd(i,a,n),i=pointDouble(i,n));return i}function bigintToBuffer(e,t){let r=e.toString(16).padStart(t*2,`0`);return n.from(r,`hex`)}function bufferToBigint(e){let t=n.from(e).toString(`hex`);return t.length===0?0n:BigInt(`0x`+t)}function encodePublicKey(e,t,r=`uncompressed`){if(e===null)throw Error(`Cannot encode the point at infinity`);let i=bigintToBuffer(e.x,t);if(r===`compressed`){let t=e.y%2n==0n?2:3;return n.concat([n.from([t]),i])}let a=bigintToBuffer(e.y,t);if(r===`hybrid`){let t=e.y%2n==0n?6:7;return n.concat([n.from([t]),i,a])}return n.concat([n.from([4]),i,a])}function decodePublicKey(e,t){let r=n.from(e);if(r.length===0)throw Error(`Invalid public key: empty buffer`);let i=r[0],{p:a,a:o,b:s,byteLength:c}=t;if(i===4||i===6||i===7){if(r.length!==1+2*c)throw Error(`Invalid public key length: expected ${1+2*c} bytes, got ${r.length}`);let e=bufferToBigint(r.subarray(1,1+c)),t=bufferToBigint(r.subarray(1+c));if(mod(t*t,a)!==mod(e*e*e+o*e+s,a))throw Error(`Invalid public key: point is not on the curve`);return{x:e,y:t}}if(i===2||i===3){if(r.length!==1+c)throw Error(`Invalid public key length: expected ${1+c} bytes, got ${r.length}`);let e=bufferToBigint(r.subarray(1,1+c)),t=sqrtMod(mod(e*e*e+o*e+s,a),a);if(t===null)throw Error(`Invalid public key: no valid y coordinate for the given x`);let n=i===3;return{x:e,y:t%2n!=0n===n?t:mod(a-t,a)}}throw Error(`Invalid public key prefix: 0x${i.toString(16).padStart(2,`0`)}`)}function sqrtMod(t,n){if(t=mod(t,n),t===0n)return 0n;if(e(t,(n-1n)/2n,n)!==1n)return null;if(mod(n,4n)===3n)return e(t,(n+1n)/4n,n);let r=0n,i=n-1n;for(;mod(i,2n)===0n;)i/=2n,r++;let a=2n;for(;e(a,(n-1n)/2n,n)!==n-1n;)a++;let o=r,s=e(a,i,n),c=e(t,i,n),l=e(t,(i+1n)/2n,n);for(;;){if(c===0n)return 0n;if(c===1n)return l;let t=1n,r=mod(c*c,n);for(;r!==1n;)r=mod(r*r,n),t++;let i=e(s,e(2n,o-t-1n,n-1n),n);o=t,s=mod(i*i,n),c=mod(c*s,n),l=mod(l*i,n)}}function toBuffer(e,t){if(n.isBuffer(e))return e;if(e instanceof Uint8Array)return n.from(e);if(typeof e==`string`)return n.from(e,t||`utf8`);if(ArrayBuffer.isView(e))return n.from(e.buffer,e.byteOffset,e.byteLength);throw TypeError(`The "key" argument must be of type string or an instance of Buffer, TypedArray, or DataView.`)}function formatReturnValue(e,t){return t?e.toString(t):e}function resolveCurve(e){let t=i[e.toLowerCase()];if(!t)throw Error(`Unsupported curve: ${e}`);let n=r[t];if(!n)throw Error(`Unsupported curve: ${e}`);return{canonical:t,params:n}}var ECDH=class{_curve;_curveName;_privateKey=null;_publicKey=null;constructor(e){let t=resolveCurve(e);this._curve=t.params,this._curveName=t.canonical}generateKeys(e,n){let{n:r,byteLength:i}=this._curve,a;do a=bufferToBigint(t(i));while(a===0n||a>=r);this._privateKey=a;let o={x:this._curve.Gx,y:this._curve.Gy};return this._publicKey=scalarMul(a,o,this._curve),this.getPublicKey(e,n)}computeSecret(e,t,n){if(this._privateKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);let r=decodePublicKey(toBuffer(e,t),this._curve);if(r===null)throw Error(`Invalid public key: point at infinity`);let i=scalarMul(this._privateKey,r,this._curve);if(i===null)throw Error(`Shared secret computation resulted in the point at infinity`);return formatReturnValue(bigintToBuffer(i.x,this._curve.byteLength),n)}getPublicKey(e,t){if(this._publicKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);return formatReturnValue(encodePublicKey(this._publicKey,this._curve.byteLength,t||`uncompressed`),e)}getPrivateKey(e){if(this._privateKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);return formatReturnValue(bigintToBuffer(this._privateKey,this._curve.byteLength),e)}setPublicKey(e,t){let n=toBuffer(e,t);this._publicKey=decodePublicKey(n,this._curve)}setPrivateKey(e,t){let n=bufferToBigint(toBuffer(e,t));if(n===0n||n>=this._curve.n)throw Error(`Private key is out of range [1, n-1]`);this._privateKey=n;let r={x:this._curve.Gx,y:this._curve.Gy};this._publicKey=scalarMul(n,r,this._curve)}};function createECDH(e){return new ECDH(e)}function getCurves(){return[`secp256k1`,`prime256v1`,`secp256r1`,`secp384r1`,`secp521r1`]}export{r as CURVES,i as CURVE_ALIASES,createECDH,getCurves,mod,modInverse,pointAdd,scalarMul};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{modPow as e}from"./bigint-math.js";import{randomBytes as t}from"./random.js";import{Buffer as n}from"node:buffer";const r={secp256k1:{p:115792089237316195423570985008687907853269984665640564039457584007908834671663n,a:0n,b:7n,Gx:55066263022277343669578718895168534326250603453777594175500187360389116729240n,Gy:32670510020758816978083085130507043184471273380659243275938904335757337482424n,n:115792089237316195423570985008687907852837564279074904382605163141518161494337n,byteLength:32},prime256v1:{p:115792089210356248762697446949407573530086143415290314195533631308867097853951n,a:115792089210356248762697446949407573530086143415290314195533631308867097853951n-3n,b:41058363725152142129326129780047268409114441015993725554835256314039467401291n,Gx:48439561293906451759052585252797914202762949526041747995844080717082404635286n,Gy:36134250956749795798585127919587881956611106672985015071877198253568414405109n,n:115792089210356248762697446949407573529996955224135760342422259061068512044369n,byteLength:32},secp384r1:{p:39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319n,a:39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319n-3n,b:27580193559959705877849011840389048093056905856361568521428707301988689241309860865136260764883745107765439761230575n,Gx:26247035095799689268623156744566981891852923491109213387815615900925518854738050089022388053975719786650872476732087n,Gy:8325710961489029985546751289520108179287853048861315594709205902480503199884419224438643760392947333078086511627871n,n:39402006196394479212279040100143613805079739270465446667946905279627659399113263569398956308152294913554433653942643n,byteLength:48},secp521r1:{p:6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151n,a:6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151n-3n,b:1093849038073734274511112390766805569936207598951683748994586394495953116150735016013708737573759623248592132296706313309438452531591012912142327488478985984n,Gx:2661740802050217063228768716723360960729859168756973147706671368418802944996427808491545080627771902352094241225065558662157113545570916814161637315895999846n,Gy:3757180025770020463545507224491183603594455134769762486694567779615544477440556316691234405012945539562144444537289428522585666729196580810124344277578376784n,n:6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449n,byteLength:66}},i={secp256k1:`secp256k1`,prime256v1:`prime256v1`,secp256r1:`prime256v1`,"p-256":`prime256v1`,p256:`prime256v1`,secp384r1:`secp384r1`,"p-384":`secp384r1`,p384:`secp384r1`,secp521r1:`secp521r1`,"p-521":`secp521r1`,p521:`secp521r1`};function mod(e,t){let n=e%t;return n<0n?n+t:n}function modInverse(e,t){if(e=mod(e,t),e===0n)throw Error(`No modular inverse for zero`);let[n,r]=[e,t],[i,a]=[1n,0n];for(;r!==0n;){let e=n/r;[n,r]=[r,n-e*r],[i,a]=[a,i-e*a]}if(n!==1n)throw Error(`Modular inverse does not exist`);return mod(i,t)}function pointAdd(e,t,n){if(e===null)return t;if(t===null)return e;let{p:r}=n;if(e.x===t.x)return mod(e.y+t.y,r)===0n?null:pointDouble(e,n);let i=mod(t.x-e.x,r),a=mod(mod(t.y-e.y,r)*modInverse(i,r),r),o=mod(a*a-e.x-t.x,r);return{x:o,y:mod(a*(e.x-o)-e.y,r)}}function pointDouble(e,t){if(e===null)return null;let{a:n,p:r}=t;if(e.y===0n)return null;let i=mod(mod(3n*e.x*e.x+n,r)*modInverse(mod(2n*e.y,r),r),r),a=mod(i*i-2n*e.x,r);return{x:a,y:mod(i*(e.x-a)-e.y,r)}}function scalarMul(e,t,n){if(t===null||e===0n)return null;let{n:r}=n;if(e=mod(e,r),e===0n)return null;let i=null,a=t,o=e.toString(2);for(let e=0;e<o.length;e++)o[e]===`1`?(i=pointAdd(i,a,n),a=pointDouble(a,n)):(a=pointAdd(i,a,n),i=pointDouble(i,n));return i}function bigintToBuffer(e,t){let r=e.toString(16).padStart(t*2,`0`);return n.from(r,`hex`)}function bufferToBigint(e){let t=n.from(e).toString(`hex`);return t.length===0?0n:BigInt(`0x`+t)}function encodePublicKey(e,t,r=`uncompressed`){if(e===null)throw Error(`Cannot encode the point at infinity`);let i=bigintToBuffer(e.x,t);if(r===`compressed`){let t=e.y%2n==0n?2:3;return n.concat([n.from([t]),i])}let a=bigintToBuffer(e.y,t);if(r===`hybrid`){let t=e.y%2n==0n?6:7;return n.concat([n.from([t]),i,a])}return n.concat([n.from([4]),i,a])}function decodePublicKey(e,t){let r=n.from(e);if(r.length===0)throw Error(`Invalid public key: empty buffer`);let i=r[0],{p:a,a:o,b:s,byteLength:c}=t;if(i===4||i===6||i===7){if(r.length!==1+2*c)throw Error(`Invalid public key length: expected ${1+2*c} bytes, got ${r.length}`);let e=bufferToBigint(r.subarray(1,1+c)),t=bufferToBigint(r.subarray(1+c));if(mod(t*t,a)!==mod(e*e*e+o*e+s,a))throw Error(`Invalid public key: point is not on the curve`);return{x:e,y:t}}if(i===2||i===3){if(r.length!==1+c)throw Error(`Invalid public key length: expected ${1+c} bytes, got ${r.length}`);let e=bufferToBigint(r.subarray(1,1+c)),t=sqrtMod(mod(e*e*e+o*e+s,a),a);if(t===null)throw Error(`Invalid public key: no valid y coordinate for the given x`);let n=i===3;return{x:e,y:t%2n!=0n===n?t:mod(a-t,a)}}throw Error(`Invalid public key prefix: 0x${i.toString(16).padStart(2,`0`)}`)}function sqrtMod(t,n){if(t=mod(t,n),t===0n)return 0n;if(e(t,(n-1n)/2n,n)!==1n)return null;if(mod(n,4n)===3n)return e(t,(n+1n)/4n,n);let r=0n,i=n-1n;for(;mod(i,2n)===0n;)i/=2n,r++;let a=2n;for(;e(a,(n-1n)/2n,n)!==n-1n;)a++;let o=r,s=e(a,i,n),c=e(t,i,n),l=e(t,(i+1n)/2n,n);for(;;){if(c===0n)return 0n;if(c===1n)return l;let t=1n,r=mod(c*c,n);for(;r!==1n;)r=mod(r*r,n),t++;let i=e(s,e(2n,o-t-1n,n-1n),n);o=t,s=mod(i*i,n),c=mod(c*s,n),l=mod(l*i,n)}}function toBuffer(e,t){if(n.isBuffer(e))return e;if(e instanceof Uint8Array)return n.from(e);if(typeof e==`string`)return n.from(e,t||`utf8`);if(ArrayBuffer.isView(e))return n.from(e.buffer,e.byteOffset,e.byteLength);throw TypeError(`The "key" argument must be of type string or an instance of Buffer, TypedArray, or DataView.`)}function formatReturnValue(e,t){return t?e.toString(t):e}function resolveCurve(e){let t=i[e.toLowerCase()];if(!t)throw Error(`Unsupported curve: ${e}`);let n=r[t];if(!n)throw Error(`Unsupported curve: ${e}`);return{canonical:t,params:n}}var ECDH=class{_curve;_curveName;_privateKey=null;_publicKey=null;constructor(e){let t=resolveCurve(e);this._curve=t.params,this._curveName=t.canonical}generateKeys(e,n){let{n:r,byteLength:i}=this._curve,a;do a=bufferToBigint(t(i));while(a===0n||a>=r);this._privateKey=a;let o={x:this._curve.Gx,y:this._curve.Gy};return this._publicKey=scalarMul(a,o,this._curve),this.getPublicKey(e,n)}computeSecret(e,t,n){if(this._privateKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);let r=decodePublicKey(toBuffer(e,t),this._curve);if(r===null)throw Error(`Invalid public key: point at infinity`);let i=scalarMul(this._privateKey,r,this._curve);if(i===null)throw Error(`Shared secret computation resulted in the point at infinity`);return formatReturnValue(bigintToBuffer(i.x,this._curve.byteLength),n)}getPublicKey(e,t){if(this._publicKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);return formatReturnValue(encodePublicKey(this._publicKey,this._curve.byteLength,t||`uncompressed`),e)}getPrivateKey(e){if(this._privateKey===null)throw Error(`ECDH key not generated. Call generateKeys() or setPrivateKey() first.`);return formatReturnValue(bigintToBuffer(this._privateKey,this._curve.byteLength),e)}setPublicKey(e,t){let n=toBuffer(e,t);this._publicKey=decodePublicKey(n,this._curve)}setPrivateKey(e,t){let n=bufferToBigint(toBuffer(e,t));if(n===0n||n>=this._curve.n)throw Error(`Private key is out of range [1, n-1]`);this._privateKey=n;let r={x:this._curve.Gx,y:this._curve.Gy};this._publicKey=scalarMul(n,r,this._curve)}};function createECDH(e){return new ECDH(e)}function getCurves(){return[`secp256k1`,`prime256v1`,`secp256r1`,`secp384r1`,`secp521r1`]}export{r as CURVES,i as CURVE_ALIASES,createECDH,getCurves,mod,modInverse,pointAdd,scalarMul};
|
package/lib/esm/ecdsa.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bigIntToBytes as e,bytesToBigInt as t}from"./bigint-math.js";import{CURVES as n,CURVE_ALIASES as r,mod as i,modInverse as a,pointAdd as o,scalarMul as s}from"./ecdh.js";import{Hash as c}from"./hash.js";import{Hmac as l}from"./hmac.js";function getCurve(e){let t=r[e.toLowerCase()];if(!t)throw Error(`Unsupported curve: ${e}`);return n[t]}function truncateHash(e,n){let r=n.n.toString(2).length,i=t(e),a=e.length*8;return a>r&&(i>>=BigInt(a-r)),i}function hmacDigest(e,t,n){let r=new l(e,t);return r.update(n),new Uint8Array(r.digest())}function rfc6979(t,n,r,a){let o=a.byteLength,s=r.length,c=new Uint8Array(s).fill(1),l=new Uint8Array(s).fill(0),u=e(n,o),d=e(i(truncateHash(r,a),a.n),o),f=new Uint8Array(s+1+o+o);f.set(c,0),f[s]=0,f.set(u,s+1),f.set(d,s+1+o),l=hmacDigest(t,l,f),c=hmacDigest(t,l,c);let p=new Uint8Array(s+1+o+o);p.set(c,0),p[s]=1,p.set(u,s+1),p.set(d,s+1+o),l=hmacDigest(t,l,p),c=hmacDigest(t,l,c);for(let e=0;e<100;e++){let e=new Uint8Array;for(;e.length<o;){c=hmacDigest(t,l,c);let n=new Uint8Array(e.length+c.length);n.set(e,0),n.set(c,e.length),e=n}let n=truncateHash(e.slice(0,o),a);if(n>=1n&&n<a.n)return n;let r=new Uint8Array(s+1);r.set(c,0),r[s]=0,l=hmacDigest(t,l,r),c=hmacDigest(t,l,c)}throw Error(`RFC 6979: failed to generate valid k after 100 attempts`)}function ecdsaSign(n,r,o,l){let u=getCurve(l),d={x:u.Gx,y:u.Gy},f=t(r),p=new c(n);p.update(o);let m=new Uint8Array(p.digest()),h=truncateHash(m,u),g=rfc6979(n,f,m,u),_=s(g,d,u);if(_===null)throw Error(`ECDSA: k * G is point at infinity`);let v=i(_.x,u.n);if(v===0n)throw Error(`ECDSA: r is zero`);let y=i(a(g,u.n)*(h+v*f),u.n);if(y===0n)throw Error(`ECDSA: s is zero`);let b=u.byteLength,x=new Uint8Array(b*2);return x.set(e(v,b),0),x.set(e(y,b),b),x}function ecdsaVerify(e,n,r,l,u){let d=getCurve(u),f={x:d.Gx,y:d.Gy},p=d.byteLength;if(n[0]!==4||n.length!==1+p*2)return!1;let m={x:t(n.slice(1,1+p)),y:t(n.slice(1+p))};if(r.length!==p*2)return!1;let h=t(r.slice(0,p)),g=t(r.slice(p));if(h<1n||h>=d.n||g<1n||g>=d.n)return!1;let _=new c(e);_.update(l);let v=truncateHash(new Uint8Array(_.digest()),d),y=a(g,d.n),b=i(v*y,d.n),x=i(h*y,d.n),S=o(s(b,f,d),s(x,m,d),d);return S===null?!1:i(S.x,d.n)===h}export{ecdsaSign,ecdsaVerify};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{bigIntToBytes as e,bytesToBigInt as t}from"./bigint-math.js";import{CURVES as n,CURVE_ALIASES as r,mod as i,modInverse as a,pointAdd as o,scalarMul as s}from"./ecdh.js";import{Hash as c}from"./hash.js";import{Hmac as l}from"./hmac.js";function getCurve(e){let t=r[e.toLowerCase()];if(!t)throw Error(`Unsupported curve: ${e}`);return n[t]}function truncateHash(e,n){let r=n.n.toString(2).length,i=t(e),a=e.length*8;return a>r&&(i>>=BigInt(a-r)),i}function hmacDigest(e,t,n){let r=new l(e,t);return r.update(n),new Uint8Array(r.digest())}function rfc6979(t,n,r,a){let o=a.byteLength,s=r.length,c=new Uint8Array(s).fill(1),l=new Uint8Array(s).fill(0),u=e(n,o),d=e(i(truncateHash(r,a),a.n),o),f=new Uint8Array(s+1+o+o);f.set(c,0),f[s]=0,f.set(u,s+1),f.set(d,s+1+o),l=hmacDigest(t,l,f),c=hmacDigest(t,l,c);let p=new Uint8Array(s+1+o+o);p.set(c,0),p[s]=1,p.set(u,s+1),p.set(d,s+1+o),l=hmacDigest(t,l,p),c=hmacDigest(t,l,c);for(let e=0;e<100;e++){let e=new Uint8Array;for(;e.length<o;){c=hmacDigest(t,l,c);let n=new Uint8Array(e.length+c.length);n.set(e,0),n.set(c,e.length),e=n}let n=truncateHash(e.slice(0,o),a);if(n>=1n&&n<a.n)return n;let r=new Uint8Array(s+1);r.set(c,0),r[s]=0,l=hmacDigest(t,l,r),c=hmacDigest(t,l,c)}throw Error(`RFC 6979: failed to generate valid k after 100 attempts`)}function ecdsaSign(n,r,o,l){let u=getCurve(l),d={x:u.Gx,y:u.Gy},f=t(r),p=new c(n);p.update(o);let m=new Uint8Array(p.digest()),h=truncateHash(m,u),g=rfc6979(n,f,m,u),_=s(g,d,u);if(_===null)throw Error(`ECDSA: k * G is point at infinity`);let v=i(_.x,u.n);if(v===0n)throw Error(`ECDSA: r is zero`);let y=i(a(g,u.n)*(h+v*f),u.n);if(y===0n)throw Error(`ECDSA: s is zero`);let b=u.byteLength,x=new Uint8Array(b*2);return x.set(e(v,b),0),x.set(e(y,b),b),x}function ecdsaVerify(e,n,r,l,u){let d=getCurve(u),f={x:d.Gx,y:d.Gy},p=d.byteLength;if(n[0]!==4||n.length!==1+p*2)return!1;let m={x:t(n.slice(1,1+p)),y:t(n.slice(1+p))};if(r.length!==p*2)return!1;let h=t(r.slice(0,p)),g=t(r.slice(p));if(h<1n||h>=d.n||g<1n||g>=d.n)return!1;let _=new c(e);_.update(l);let v=truncateHash(new Uint8Array(_.digest()),d),y=a(g,d.n),b=i(v*y,d.n),x=i(h*y,d.n),S=o(s(b,f,d),s(x,m,d),d);return S===null?!1:i(S.x,d.n)===h}export{ecdsaSign,ecdsaVerify};
|
package/lib/esm/hash.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeAlgorithm as e}from"./crypto-utils.js";import{Buffer as t}from"node:buffer";import n from"@girs/glib-2.0";import{Transform as r}from"node:stream";import{normalizeEncoding as i}from"@gjsify/utils";const a={md5:n.ChecksumType.MD5,sha1:n.ChecksumType.SHA1,sha256:n.ChecksumType.SHA256,sha384:n.ChecksumType.SHA384,sha512:n.ChecksumType.SHA512};function getChecksumType(t){let n=a[e(t)];if(n===void 0){let e=Error(`Unknown message digest: ${t}`);throw e.code=`ERR_CRYPTO_HASH_UNKNOWN`,e}return n}var o=class Hash extends r{_algorithm;_checksum;_finalized=!1;constructor(t){super();let r=e(t),i=getChecksumType(r);this._algorithm=r,this._checksum=new n.Checksum(i)}update(e,n){if(this._finalized)throw Error(`Digest already called`);let r;if(typeof e==`string`){let a=i(n);r=t.from(e,a)}else r=e instanceof Uint8Array?e:t.from(e);return this._checksum.update(r),this}digest(e){if(this._finalized)throw Error(`Digest already called`);this._finalized=!0;let n=this._checksum.get_string(),r=t.from(n,`hex`);return e?r.toString(e):r}copy(){if(this._finalized)throw Error(`Digest already called`);let e=Object.create(Hash.prototype);return r.call(e),e._algorithm=this._algorithm,e._finalized=!1,e._checksum=this._checksum.copy(),e}_transform(e,t,n){try{this.update(e,t),n()}catch(e){n(e)}}_flush(e){try{this.push(this.digest()),e()}catch(t){e(t)}}};function getHashes(){return[`md5`,`sha1`,`sha256`,`sha384`,`sha512`]}function hash(e,t,n){return new o(e).update(t).digest(n)}export{o as Hash,getHashes,hash};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizeAlgorithm as e}from"./crypto-utils.js";import{Buffer as t}from"node:buffer";import n from"@girs/glib-2.0";import{Transform as r}from"node:stream";import{normalizeEncoding as i}from"@gjsify/utils";const a={md5:n.ChecksumType.MD5,sha1:n.ChecksumType.SHA1,sha256:n.ChecksumType.SHA256,sha384:n.ChecksumType.SHA384,sha512:n.ChecksumType.SHA512};function getChecksumType(t){let n=a[e(t)];if(n===void 0){let e=Error(`Unknown message digest: ${t}`);throw e.code=`ERR_CRYPTO_HASH_UNKNOWN`,e}return n}var o=class Hash extends r{_algorithm;_checksum;_finalized=!1;constructor(t){super();let r=e(t),i=getChecksumType(r);this._algorithm=r,this._checksum=new n.Checksum(i)}update(e,n){if(this._finalized)throw Error(`Digest already called`);let r;if(typeof e==`string`){let a=i(n);r=t.from(e,a)}else r=e instanceof Uint8Array?e:t.from(e);return this._checksum.update(r),this}digest(e){if(this._finalized)throw Error(`Digest already called`);this._finalized=!0;let n=this._checksum.get_string(),r=t.from(n,`hex`);return e?r.toString(e):r}copy(){if(this._finalized)throw Error(`Digest already called`);let e=Object.create(Hash.prototype);return r.call(e),e._algorithm=this._algorithm,e._finalized=!1,e._checksum=this._checksum.copy(),e}_transform(e,t,n){try{this.update(e,t),n()}catch(e){n(e)}}_flush(e){try{this.push(this.digest()),e()}catch(t){e(t)}}};function getHashes(){return[`md5`,`sha1`,`sha256`,`sha384`,`sha512`]}function hash(e,t,n){return new o(e).update(t).digest(n)}export{o as Hash,getHashes,hash};
|
package/lib/esm/hkdf.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DIGEST_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n,toBuffer as r}from"./crypto-utils.js";import{Hmac as i}from"./hmac.js";import{Buffer as a}from"node:buffer";function hmacDigest(e,t,n){let r=new i(e,t);return r.update(n),r.digest()}function hkdfExtract(e,t,n){return hmacDigest(e,n,t)}function hkdfExpand(e,t,n,r,i){let o=Math.ceil(r/i);if(o>255)throw Error(`HKDF cannot generate more than 255 * HashLen bytes`);let s=a.allocUnsafe(o*i),c=a.alloc(0);for(let r=1;r<=o;r++)c=hmacDigest(e,t,a.concat([c,n,a.from([r])])),c.copy(s,(r-1)*i);return a.from(s.buffer,s.byteOffset,r)}function hkdfSync(i,o,s,c,l){let u=n(i),d=e[u];if(!t.has(u)||d===void 0)throw TypeError(`Unknown message digest: ${i}`);if(typeof l!=`number`||l<0)throw TypeError(`keylen must be a non-negative number`);let f=r(o),p=r(s),m=r(c),h=hkdfExpand(u,hkdfExtract(u,f,p.length===0?a.alloc(d,0):p),m,l,d),g=new ArrayBuffer(h.length);return new Uint8Array(g).set(h),g}function hkdf(e,t,n,r,i,a){setTimeout(()=>{try{a(null,hkdfSync(e,t,n,r,i))}catch(e){a(e instanceof Error?e:Error(String(e)))}},0)}export{hkdf,hkdfSync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{DIGEST_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n,toBuffer as r}from"./crypto-utils.js";import{Hmac as i}from"./hmac.js";import{Buffer as a}from"node:buffer";function hmacDigest(e,t,n){let r=new i(e,t);return r.update(n),r.digest()}function hkdfExtract(e,t,n){return hmacDigest(e,n,t)}function hkdfExpand(e,t,n,r,i){let o=Math.ceil(r/i);if(o>255)throw Error(`HKDF cannot generate more than 255 * HashLen bytes`);let s=a.allocUnsafe(o*i),c=a.alloc(0);for(let r=1;r<=o;r++)c=hmacDigest(e,t,a.concat([c,n,a.from([r])])),c.copy(s,(r-1)*i);return a.from(s.buffer,s.byteOffset,r)}function hkdfSync(i,o,s,c,l){let u=n(i),d=e[u];if(!t.has(u)||d===void 0)throw TypeError(`Unknown message digest: ${i}`);if(typeof l!=`number`||l<0)throw TypeError(`keylen must be a non-negative number`);let f=r(o),p=r(s),m=r(c),h=hkdfExpand(u,hkdfExtract(u,f,p.length===0?a.alloc(d,0):p),m,l,d),g=new ArrayBuffer(h.length);return new Uint8Array(g).set(h),g}function hkdf(e,t,n,r,i,a){setTimeout(()=>{try{a(null,hkdfSync(e,t,n,r,i))}catch(e){a(e instanceof Error?e:Error(String(e)))}},0)}export{hkdf,hkdfSync};
|
package/lib/esm/hmac.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BLOCK_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n}from"./crypto-utils.js";import{Hash as r}from"./hash.js";import{Buffer as i}from"node:buffer";import{Transform as a}from"node:stream";import{normalizeEncoding as o}from"@gjsify/utils";var Hmac=class extends a{_algorithm;_innerHash;_outerKeyPad;_finalized=!1;constructor(a,o){super();let s=n(a);if(!t.has(s)){let e=Error(`Unknown message digest: ${a}`);throw e.code=`ERR_CRYPTO_HASH_UNKNOWN`,e}this._algorithm=s;let c;c=typeof o==`string`?i.from(o,`utf8`):o instanceof Uint8Array?o:i.from(o);let l=e[s];if(c.length>l){let e=new r(s);e.update(c),c=e.digest()}let u=new Uint8Array(l);u.set(c);let d=new Uint8Array(l),f=new Uint8Array(l);for(let e=0;e<l;e++)d[e]=u[e]^54,f[e]=u[e]^92;this._outerKeyPad=f,this._innerHash=new r(s),this._innerHash.update(d)}update(e,t){if(this._finalized)throw Error(`Digest already called`);let n;if(typeof e==`string`){let r=o(t);n=i.from(e,r)}else n=e instanceof Uint8Array?e:i.from(e);return this._innerHash.update(n),this}digest(e){if(this._finalized)throw Error(`Digest already called`);this._finalized=!0;let t=this._innerHash.digest(),n=new r(this._algorithm);n.update(this._outerKeyPad),n.update(t);let i=n.digest();return e?i.toString(e):i}_transform(e,t,n){try{this.update(e,t),n()}catch(e){n(e)}}_flush(e){try{this.push(this.digest()),e()}catch(t){e(t)}}};export{Hmac};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{BLOCK_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n}from"./crypto-utils.js";import{Hash as r}from"./hash.js";import{Buffer as i}from"node:buffer";import{Transform as a}from"node:stream";import{normalizeEncoding as o}from"@gjsify/utils";var Hmac=class extends a{_algorithm;_innerHash;_outerKeyPad;_finalized=!1;constructor(a,o){super();let s=n(a);if(!t.has(s)){let e=Error(`Unknown message digest: ${a}`);throw e.code=`ERR_CRYPTO_HASH_UNKNOWN`,e}this._algorithm=s;let c;c=typeof o==`string`?i.from(o,`utf8`):o instanceof Uint8Array?o:i.from(o);let l=e[s];if(c.length>l){let e=new r(s);e.update(c),c=e.digest()}let u=new Uint8Array(l);u.set(c);let d=new Uint8Array(l),f=new Uint8Array(l);for(let e=0;e<l;e++)d[e]=u[e]^54,f[e]=u[e]^92;this._outerKeyPad=f,this._innerHash=new r(s),this._innerHash.update(d)}update(e,t){if(this._finalized)throw Error(`Digest already called`);let n;if(typeof e==`string`){let r=o(t);n=i.from(e,r)}else n=e instanceof Uint8Array?e:i.from(e);return this._innerHash.update(n),this}digest(e){if(this._finalized)throw Error(`Digest already called`);this._finalized=!0;let t=this._innerHash.digest(),n=new r(this._algorithm);n.update(this._outerKeyPad),n.update(t);let i=n.digest();return e?i.toString(e):i}_transform(e,t,n){try{this.update(e,t),n()}catch(e){n(e)}}_flush(e){try{this.push(this.digest()),e()}catch(t){e(t)}}};export{Hmac};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createCipher as e,createCipheriv as t,createDecipher as n,createDecipheriv as r,getCiphers as i}from"./cipher.js";import{constants as a}from"./constants.js";import{randomBytes as o,randomFill as s,randomFillSync as c,randomInt as l,randomUUID as u}from"./random.js";import{DiffieHellman as d,DiffieHellmanGroup as f,createDiffieHellman as p,createDiffieHellmanGroup as m,getDiffieHellman as h}from"./dh.js";import{createECDH as g,getCurves as _}from"./ecdh.js";import{Hash as v,getHashes as y,hash as b}from"./hash.js";import{Hmac as x}from"./hmac.js";import{ecdsaSign as S,ecdsaVerify as C}from"./ecdsa.js";import{hkdf as w,hkdfSync as T}from"./hkdf.js";import{timingSafeEqual as E}from"./timing-safe-equal.js";import{pbkdf2 as D,pbkdf2Sync as O}from"./pbkdf2.js";import{scrypt as k,scryptSync as A}from"./scrypt.js";import{Sign as j,Verify as M,createSign as N,createVerify as P}from"./sign.js";import{privateDecrypt as F,privateEncrypt as I,publicDecrypt as L,publicEncrypt as R}from"./public-encrypt.js";import{mgf1 as z}from"./mgf1.js";import{rsaPssSign as B,rsaPssVerify as V}from"./rsa-pss.js";import{rsaOaepDecrypt as H,rsaOaepEncrypt as U}from"./rsa-oaep.js";import{KeyObject as W,createPrivateKey as G,createPublicKey as K,createSecretKey as q}from"./key-object.js";import{X509Certificate as J}from"./x509.js";function createHash(e){return new v(e)}function createHmac(e,t){return new x(e,t)}var Y={Hash:v,getHashes:y,hash:b,Hmac:x,randomBytes:o,randomFill:s,randomFillSync:c,randomUUID:u,randomInt:l,timingSafeEqual:E,constants:a,pbkdf2:D,pbkdf2Sync:O,hkdf:w,hkdfSync:T,scrypt:k,scryptSync:A,createHash,createHmac,createCipher:e,createCipheriv:t,createDecipher:n,createDecipheriv:r,getCiphers:i,Sign:j,Verify:M,createSign:N,createVerify:P,createDiffieHellman:p,getDiffieHellman:h,DiffieHellman:d,DiffieHellmanGroup:f,createDiffieHellmanGroup:m,createECDH:g,getCurves:_,ecdsaSign:S,ecdsaVerify:C,publicEncrypt:R,privateDecrypt:F,privateEncrypt:I,publicDecrypt:L,rsaPssSign:B,rsaPssVerify:V,rsaOaepEncrypt:U,rsaOaepDecrypt:H,mgf1:z,KeyObject:W,createSecretKey:q,createPublicKey:K,createPrivateKey:G,X509Certificate:J};export{d as DiffieHellman,f as DiffieHellmanGroup,v as Hash,x as Hmac,W as KeyObject,j as Sign,M as Verify,J as X509Certificate,a as constants,e as createCipher,t as createCipheriv,n as createDecipher,r as createDecipheriv,p as createDiffieHellman,m as createDiffieHellmanGroup,g as createECDH,createHash,createHmac,G as createPrivateKey,K as createPublicKey,q as createSecretKey,N as createSign,P as createVerify,Y as default,S as ecdsaSign,C as ecdsaVerify,i as getCiphers,_ as getCurves,h as getDiffieHellman,y as getHashes,b as hash,w as hkdf,T as hkdfSync,z as mgf1,D as pbkdf2,O as pbkdf2Sync,F as privateDecrypt,I as privateEncrypt,L as publicDecrypt,R as publicEncrypt,o as randomBytes,s as randomFill,c as randomFillSync,l as randomInt,u as randomUUID,H as rsaOaepDecrypt,U as rsaOaepEncrypt,B as rsaPssSign,V as rsaPssVerify,k as scrypt,A as scryptSync,E as timingSafeEqual};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{createCipher as e,createCipheriv as t,createDecipher as n,createDecipheriv as r,getCiphers as i}from"./cipher.js";import{constants as a}from"./constants.js";import{randomBytes as o,randomFill as s,randomFillSync as c,randomInt as l,randomUUID as u}from"./random.js";import{DiffieHellman as d,DiffieHellmanGroup as f,createDiffieHellman as p,createDiffieHellmanGroup as m,getDiffieHellman as h}from"./dh.js";import{createECDH as g,getCurves as _}from"./ecdh.js";import{Hash as v,getHashes as y,hash as b}from"./hash.js";import{Hmac as x}from"./hmac.js";import{ecdsaSign as S,ecdsaVerify as C}from"./ecdsa.js";import{hkdf as w,hkdfSync as T}from"./hkdf.js";import{timingSafeEqual as E}from"./timing-safe-equal.js";import{pbkdf2 as D,pbkdf2Sync as O}from"./pbkdf2.js";import{scrypt as k,scryptSync as A}from"./scrypt.js";import{Sign as j,Verify as M,createSign as N,createVerify as P}from"./sign.js";import{privateDecrypt as F,privateEncrypt as I,publicDecrypt as L,publicEncrypt as R}from"./public-encrypt.js";import{mgf1 as z}from"./mgf1.js";import{rsaPssSign as B,rsaPssVerify as V}from"./rsa-pss.js";import{rsaOaepDecrypt as H,rsaOaepEncrypt as U}from"./rsa-oaep.js";import{KeyObject as W,createPrivateKey as G,createPublicKey as K,createSecretKey as q}from"./key-object.js";import{X509Certificate as J}from"./x509.js";function createHash(e){return new v(e)}function createHmac(e,t){return new x(e,t)}var Y={Hash:v,getHashes:y,hash:b,Hmac:x,randomBytes:o,randomFill:s,randomFillSync:c,randomUUID:u,randomInt:l,timingSafeEqual:E,constants:a,pbkdf2:D,pbkdf2Sync:O,hkdf:w,hkdfSync:T,scrypt:k,scryptSync:A,createHash,createHmac,createCipher:e,createCipheriv:t,createDecipher:n,createDecipheriv:r,getCiphers:i,Sign:j,Verify:M,createSign:N,createVerify:P,createDiffieHellman:p,getDiffieHellman:h,DiffieHellman:d,DiffieHellmanGroup:f,createDiffieHellmanGroup:m,createECDH:g,getCurves:_,ecdsaSign:S,ecdsaVerify:C,publicEncrypt:R,privateDecrypt:F,privateEncrypt:I,publicDecrypt:L,rsaPssSign:B,rsaPssVerify:V,rsaOaepEncrypt:U,rsaOaepDecrypt:H,mgf1:z,KeyObject:W,createSecretKey:q,createPublicKey:K,createPrivateKey:G,X509Certificate:J};export{d as DiffieHellman,f as DiffieHellmanGroup,v as Hash,x as Hmac,W as KeyObject,j as Sign,M as Verify,J as X509Certificate,a as constants,e as createCipher,t as createCipheriv,n as createDecipher,r as createDecipheriv,p as createDiffieHellman,m as createDiffieHellmanGroup,g as createECDH,createHash,createHmac,G as createPrivateKey,K as createPublicKey,q as createSecretKey,N as createSign,P as createVerify,Y as default,S as ecdsaSign,C as ecdsaVerify,i as getCiphers,_ as getCurves,h as getDiffieHellman,y as getHashes,b as hash,w as hkdf,T as hkdfSync,z as mgf1,D as pbkdf2,O as pbkdf2Sync,F as privateDecrypt,I as privateEncrypt,L as publicDecrypt,R as publicEncrypt,o as randomBytes,s as randomFill,c as randomFillSync,l as randomInt,u as randomUUID,H as rsaOaepDecrypt,U as rsaOaepEncrypt,B as rsaPssSign,V as rsaPssVerify,k as scrypt,A as scryptSync,E as timingSafeEqual};
|
package/lib/esm/key-object.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derToPem as e,encodePrivateKeyInfo as t,encodeRsaPrivateKeyPkcs1 as n,encodeRsaPublicKeyPkcs1 as r,encodeSubjectPublicKeyInfo as i,parsePemKey as a,rsaKeySize as o}from"./asn1.js";import{Buffer as s}from"node:buffer";function bigintToBase64url(e){if(e===0n)return`AA`;let t=e.toString(16),n=t.length%2?`0`+t:t,r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return s.from(r).toString(`base64url`)}function base64urlToBigint(e){let t=s.from(e,`base64url`),n=0n;for(let e=0;e<t.length;e++)n=n<<8n|BigInt(t[e]);return n}var c=class KeyObject{type;_handle;constructor(e,t){if(e!==`secret`&&e!==`public`&&e!==`private`)throw TypeError(`Invalid KeyObject type: ${e}`);this.type=e,this._handle=t}get symmetricKeySize(){if(this.type===`secret`)return this._handle.byteLength}get asymmetricKeyType(){if(this.type===`secret`)return;let e=this._handle;if(e.parsed.type===`rsa-public`||e.parsed.type===`rsa-private`)return`rsa`}get asymmetricKeySize(){if(this.type===`secret`)return;let e=this._handle;if(e.parsed.type===`rsa-public`||e.parsed.type===`rsa-private`)return o(e.parsed.components.n)/8}equals(e){if(!(e instanceof KeyObject)||this.type!==e.type)return!1;if(this.type===`secret`){let t=this._handle,n=e._handle;if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.byteLength;e++)if(t[e]!==n[e])return!1;return!0}let t=this._handle,n=e._handle;return t.pem===n.pem}export(e){if(this.type===`secret`){let t=this._handle;return e?.format===`jwk`?{kty:`oct`,k:s.from(t).toString(`base64url`)}:s.from(t)}let t=this._handle,n=e?.format??`pem`,r=e?.type;if(n===`jwk`)return exportJwk(t.parsed,this.type);if(n===`pem`)return t.pem&&!t.pem.startsWith(`[`)?t.pem:generatePem(t.parsed,this.type,r);if(n===`der`){if(t.pem&&!t.pem.startsWith(`[`)){let e=t.pem.trim().split(/\r?\n/),n=e.findIndex(e=>e.startsWith(`-----BEGIN `)),r=e.findIndex((e,t)=>t>n&&e.startsWith(`-----END `)),i=e.slice(n+1,r).join(``);return s.from(i,`base64`)}return generateDer(t.parsed,this.type,r)}throw TypeError(`Unsupported export format: ${n}`)}get[Symbol.toStringTag](){return`KeyObject`}};function exportJwk(e,t){if(e.type===`rsa-public`)return{kty:`RSA`,n:bigintToBase64url(e.components.n),e:bigintToBase64url(e.components.e)};if(e.type===`rsa-private`){if(t===`public`)return{kty:`RSA`,n:bigintToBase64url(e.components.n),e:bigintToBase64url(e.components.e)};let{n,e:r,d:i,p:a,q:o}=e.components,s=i%(a-1n),c=i%(o-1n),l=modInverse(o,a);return{kty:`RSA`,n:bigintToBase64url(n),e:bigintToBase64url(r),d:bigintToBase64url(i),p:bigintToBase64url(a),q:bigintToBase64url(o),dp:bigintToBase64url(s),dq:bigintToBase64url(c),qi:bigintToBase64url(l)}}throw Error(`Unsupported key type for JWK export`)}function importJwkRsa(t){if(t.d){let r={n:base64urlToBigint(t.n),e:base64urlToBigint(t.e),d:base64urlToBigint(t.d),p:base64urlToBigint(t.p),q:base64urlToBigint(t.q)};return{parsed:{type:`rsa-private`,components:r},pem:e(n(r),`RSA PRIVATE KEY`)}}let r={n:base64urlToBigint(t.n),e:base64urlToBigint(t.e)};return{parsed:{type:`rsa-public`,components:r},pem:e(i(r),`PUBLIC KEY`)}}function generatePem(a,o,s){if(a.type===`rsa-public`)return s===`pkcs1`?e(r(a.components),`RSA PUBLIC KEY`):e(i(a.components),`PUBLIC KEY`);if(a.type===`rsa-private`&&o===`public`){let t={n:a.components.n,e:a.components.e};return s===`pkcs1`?e(r(t),`RSA PUBLIC KEY`):e(i(t),`PUBLIC KEY`)}if(a.type===`rsa-private`)return s===`pkcs8`?e(t(a.components),`PRIVATE KEY`):e(n(a.components),`RSA PRIVATE KEY`);throw Error(`Cannot generate PEM for this key type`)}function generateDer(e,a,o){if(e.type===`rsa-public`)return o===`pkcs1`?s.from(r(e.components)):s.from(i(e.components));if(e.type===`rsa-private`&&a===`public`){let t={n:e.components.n,e:e.components.e};return o===`pkcs1`?s.from(r(t)):s.from(i(t))}if(e.type===`rsa-private`)return o===`pkcs8`?s.from(t(e.components)):s.from(n(e.components));throw Error(`Cannot generate DER for this key type`)}function modInverse(e,t){let[n,r]=[e%t,t],[i,a]=[1n,0n];for(;r!==0n;){let e=n/r;[n,r]=[r,n-e*r],[i,a]=[a,i-e*a]}return(i%t+t)%t}function createSecretKey(e,t){let n;return n=typeof e==`string`?s.from(e,t??`utf8`):new Uint8Array(e),new c(`secret`,n)}function createPublicKey(t){if(t instanceof c){if(t.type===`public`)return t;if(t.type===`private`){let n=t._handle;if(n.parsed.type===`rsa-private`){let t={n:n.parsed.components.n,e:n.parsed.components.e};return new c(`public`,{parsed:{type:`rsa-public`,components:t},pem:e(i(t),`PUBLIC KEY`)})}}throw TypeError(`Cannot create public key from secret key`)}if(typeof t==`object`&&!s.isBuffer(t)&&`key`in t){let e=t;if(e.format===`jwk`){let t=e.key;if(t.kty===`RSA`){let{parsed:e,pem:n}=importJwkRsa({n:t.n,e:t.e});return new c(`public`,{parsed:e,pem:n})}throw Error(`Unsupported JWK key type: ${t.kty}`)}}let n=normalizePem(t),r=a(n);if(r.type===`rsa-private`){let t={n:r.components.n,e:r.components.e};return new c(`public`,{parsed:{type:`rsa-public`,components:t},pem:e(i(t),`PUBLIC KEY`)})}return new c(`public`,{parsed:r,pem:n})}function createPrivateKey(e){if(typeof e==`object`&&!s.isBuffer(e)&&`key`in e){let t=e;if(t.format===`jwk`){let e=t.key;if(e.kty===`RSA`&&e.d){let{parsed:t,pem:n}=importJwkRsa(e);return new c(`private`,{parsed:t,pem:n})}throw Error(`JWK does not contain a private key`)}}let t=normalizePem(e),n=a(t);if(n.type!==`rsa-private`)throw TypeError(`Key is not a private key`);return new c(`private`,{parsed:n,pem:t})}function normalizePem(e){if(typeof e==`string`)return e;if(s.isBuffer(e))return e.toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e;if(typeof t.key==`string`)return t.key;if(s.isBuffer(t.key))return t.key.toString(t.encoding??`utf8`);if(t.key instanceof c)return t.key.export({format:`pem`})}throw TypeError(`Invalid key input`)}export{c as KeyObject,createPrivateKey,createPublicKey,createSecretKey};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{derToPem as e,encodePrivateKeyInfo as t,encodeRsaPrivateKeyPkcs1 as n,encodeRsaPublicKeyPkcs1 as r,encodeSubjectPublicKeyInfo as i,parsePemKey as a,rsaKeySize as o}from"./asn1.js";import{Buffer as s}from"node:buffer";function bigintToBase64url(e){if(e===0n)return`AA`;let t=e.toString(16),n=t.length%2?`0`+t:t,r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return s.from(r).toString(`base64url`)}function base64urlToBigint(e){let t=s.from(e,`base64url`),n=0n;for(let e=0;e<t.length;e++)n=n<<8n|BigInt(t[e]);return n}var c=class KeyObject{type;_handle;constructor(e,t){if(e!==`secret`&&e!==`public`&&e!==`private`)throw TypeError(`Invalid KeyObject type: ${e}`);this.type=e,this._handle=t}get symmetricKeySize(){if(this.type===`secret`)return this._handle.byteLength}get asymmetricKeyType(){if(this.type===`secret`)return;let e=this._handle;if(e.parsed.type===`rsa-public`||e.parsed.type===`rsa-private`)return`rsa`}get asymmetricKeySize(){if(this.type===`secret`)return;let e=this._handle;if(e.parsed.type===`rsa-public`||e.parsed.type===`rsa-private`)return o(e.parsed.components.n)/8}equals(e){if(!(e instanceof KeyObject)||this.type!==e.type)return!1;if(this.type===`secret`){let t=this._handle,n=e._handle;if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.byteLength;e++)if(t[e]!==n[e])return!1;return!0}let t=this._handle,n=e._handle;return t.pem===n.pem}export(e){if(this.type===`secret`){let t=this._handle;return e?.format===`jwk`?{kty:`oct`,k:s.from(t).toString(`base64url`)}:s.from(t)}let t=this._handle,n=e?.format??`pem`,r=e?.type;if(n===`jwk`)return exportJwk(t.parsed,this.type);if(n===`pem`)return t.pem&&!t.pem.startsWith(`[`)?t.pem:generatePem(t.parsed,this.type,r);if(n===`der`){if(t.pem&&!t.pem.startsWith(`[`)){let e=t.pem.trim().split(/\r?\n/),n=e.findIndex(e=>e.startsWith(`-----BEGIN `)),r=e.findIndex((e,t)=>t>n&&e.startsWith(`-----END `)),i=e.slice(n+1,r).join(``);return s.from(i,`base64`)}return generateDer(t.parsed,this.type,r)}throw TypeError(`Unsupported export format: ${n}`)}get[Symbol.toStringTag](){return`KeyObject`}};function exportJwk(e,t){if(e.type===`rsa-public`)return{kty:`RSA`,n:bigintToBase64url(e.components.n),e:bigintToBase64url(e.components.e)};if(e.type===`rsa-private`){if(t===`public`)return{kty:`RSA`,n:bigintToBase64url(e.components.n),e:bigintToBase64url(e.components.e)};let{n,e:r,d:i,p:a,q:o}=e.components,s=i%(a-1n),c=i%(o-1n),l=modInverse(o,a);return{kty:`RSA`,n:bigintToBase64url(n),e:bigintToBase64url(r),d:bigintToBase64url(i),p:bigintToBase64url(a),q:bigintToBase64url(o),dp:bigintToBase64url(s),dq:bigintToBase64url(c),qi:bigintToBase64url(l)}}throw Error(`Unsupported key type for JWK export`)}function importJwkRsa(t){if(t.d){let r={n:base64urlToBigint(t.n),e:base64urlToBigint(t.e),d:base64urlToBigint(t.d),p:base64urlToBigint(t.p),q:base64urlToBigint(t.q)};return{parsed:{type:`rsa-private`,components:r},pem:e(n(r),`RSA PRIVATE KEY`)}}let r={n:base64urlToBigint(t.n),e:base64urlToBigint(t.e)};return{parsed:{type:`rsa-public`,components:r},pem:e(i(r),`PUBLIC KEY`)}}function generatePem(a,o,s){if(a.type===`rsa-public`)return s===`pkcs1`?e(r(a.components),`RSA PUBLIC KEY`):e(i(a.components),`PUBLIC KEY`);if(a.type===`rsa-private`&&o===`public`){let t={n:a.components.n,e:a.components.e};return s===`pkcs1`?e(r(t),`RSA PUBLIC KEY`):e(i(t),`PUBLIC KEY`)}if(a.type===`rsa-private`)return s===`pkcs8`?e(t(a.components),`PRIVATE KEY`):e(n(a.components),`RSA PRIVATE KEY`);throw Error(`Cannot generate PEM for this key type`)}function generateDer(e,a,o){if(e.type===`rsa-public`)return o===`pkcs1`?s.from(r(e.components)):s.from(i(e.components));if(e.type===`rsa-private`&&a===`public`){let t={n:e.components.n,e:e.components.e};return o===`pkcs1`?s.from(r(t)):s.from(i(t))}if(e.type===`rsa-private`)return o===`pkcs8`?s.from(t(e.components)):s.from(n(e.components));throw Error(`Cannot generate DER for this key type`)}function modInverse(e,t){let[n,r]=[e%t,t],[i,a]=[1n,0n];for(;r!==0n;){let e=n/r;[n,r]=[r,n-e*r],[i,a]=[a,i-e*a]}return(i%t+t)%t}function createSecretKey(e,t){let n;return n=typeof e==`string`?s.from(e,t??`utf8`):new Uint8Array(e),new c(`secret`,n)}function createPublicKey(t){if(t instanceof c){if(t.type===`public`)return t;if(t.type===`private`){let n=t._handle;if(n.parsed.type===`rsa-private`){let t={n:n.parsed.components.n,e:n.parsed.components.e};return new c(`public`,{parsed:{type:`rsa-public`,components:t},pem:e(i(t),`PUBLIC KEY`)})}}throw TypeError(`Cannot create public key from secret key`)}if(typeof t==`object`&&!s.isBuffer(t)&&`key`in t){let e=t;if(e.format===`jwk`){let t=e.key;if(t.kty===`RSA`){let{parsed:e,pem:n}=importJwkRsa({n:t.n,e:t.e});return new c(`public`,{parsed:e,pem:n})}throw Error(`Unsupported JWK key type: ${t.kty}`)}}let n=normalizePem(t),r=a(n);if(r.type===`rsa-private`){let t={n:r.components.n,e:r.components.e};return new c(`public`,{parsed:{type:`rsa-public`,components:t},pem:e(i(t),`PUBLIC KEY`)})}return new c(`public`,{parsed:r,pem:n})}function createPrivateKey(e){if(typeof e==`object`&&!s.isBuffer(e)&&`key`in e){let t=e;if(t.format===`jwk`){let e=t.key;if(e.kty===`RSA`&&e.d){let{parsed:t,pem:n}=importJwkRsa(e);return new c(`private`,{parsed:t,pem:n})}throw Error(`JWK does not contain a private key`)}}let t=normalizePem(e),n=a(t);if(n.type!==`rsa-private`)throw TypeError(`Key is not a private key`);return new c(`private`,{parsed:n,pem:t})}function normalizePem(e){if(typeof e==`string`)return e;if(s.isBuffer(e))return e.toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e;if(typeof t.key==`string`)return t.key;if(s.isBuffer(t.key))return t.key.toString(t.encoding??`utf8`);if(t.key instanceof c)return t.key.export({format:`pem`})}throw TypeError(`Invalid key input`)}export{c as KeyObject,createPrivateKey,createPublicKey,createSecretKey};
|
package/lib/esm/mgf1.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hashSize as e}from"./crypto-utils.js";import{Hash as t}from"./hash.js";function mgf1(n,r,i){e(n);let a=new Uint8Array(i),o=0,s=0;for(;o<i;){let e=new Uint8Array(4);e[0]=s>>>24&255,e[1]=s>>>16&255,e[2]=s>>>8&255,e[3]=s&255;let c=new t(n);c.update(r),c.update(e);let l=new Uint8Array(c.digest()),u=Math.min(l.length,i-o);a.set(l.slice(0,u),o),o+=u,s++}return a}export{mgf1};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{hashSize as e}from"./crypto-utils.js";import{Hash as t}from"./hash.js";function mgf1(n,r,i){e(n);let a=new Uint8Array(i),o=0,s=0;for(;o<i;){let e=new Uint8Array(4);e[0]=s>>>24&255,e[1]=s>>>16&255,e[2]=s>>>8&255,e[3]=s&255;let c=new t(n);c.update(r),c.update(e);let l=new Uint8Array(c.digest()),u=Math.min(l.length,i-o);a.set(l.slice(0,u),o),o+=u,s++}return a}export{mgf1};
|
package/lib/esm/pbkdf2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DIGEST_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n,toBuffer as r}from"./crypto-utils.js";import{Hmac as i}from"./hmac.js";import{Buffer as a}from"node:buffer";function hmacDigest(e,t,n){let r=new i(e,t);return r.update(n),r.digest()}function validateParameters(e,t){if(typeof e!=`number`||e<0||!Number.isFinite(e)||e===0)throw TypeError(`iterations must be a positive number`);if(typeof t!=`number`||t<0||!Number.isFinite(t)||t>2147483647)throw TypeError(`keylen must be a positive number`)}function pbkdf2Sync(i,o,s,c,l){validateParameters(s,c);let u=r(i),d=r(o),f=n(l||`sha1`),p=e[f];if(!t.has(f)||p===void 0)throw TypeError(`Unknown message digest: ${l||`sha1`}`);if(c===0)return a.alloc(0);let m=Math.ceil(c/p),h=a.allocUnsafe(m*p);for(let e=1;e<=m;e++){let t=a.allocUnsafe(d.length+4);d.copy(t,0),t.writeUInt32BE(e,d.length);let n=hmacDigest(f,u,t),r=a.from(n);for(let e=1;e<s;e++){n=hmacDigest(f,u,n);for(let e=0;e<p;e++)r[e]^=n[e]}r.copy(h,(e-1)*p)}return a.from(h.buffer,h.byteOffset,c)}function pbkdf2(e,t,n,r,i,a){try{validateParameters(n,r)}catch(e){throw e}setTimeout(()=>{try{a(null,pbkdf2Sync(e,t,n,r,i))}catch(e){a(e instanceof Error?e:Error(String(e)))}},0)}export{pbkdf2,pbkdf2Sync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{DIGEST_SIZES as e,SUPPORTED_ALGORITHMS as t,normalizeAlgorithm as n,toBuffer as r}from"./crypto-utils.js";import{Hmac as i}from"./hmac.js";import{Buffer as a}from"node:buffer";function hmacDigest(e,t,n){let r=new i(e,t);return r.update(n),r.digest()}function validateParameters(e,t){if(typeof e!=`number`||e<0||!Number.isFinite(e)||e===0)throw TypeError(`iterations must be a positive number`);if(typeof t!=`number`||t<0||!Number.isFinite(t)||t>2147483647)throw TypeError(`keylen must be a positive number`)}function pbkdf2Sync(i,o,s,c,l){validateParameters(s,c);let u=r(i),d=r(o),f=n(l||`sha1`),p=e[f];if(!t.has(f)||p===void 0)throw TypeError(`Unknown message digest: ${l||`sha1`}`);if(c===0)return a.alloc(0);let m=Math.ceil(c/p),h=a.allocUnsafe(m*p);for(let e=1;e<=m;e++){let t=a.allocUnsafe(d.length+4);d.copy(t,0),t.writeUInt32BE(e,d.length);let n=hmacDigest(f,u,t),r=a.from(n);for(let e=1;e<s;e++){n=hmacDigest(f,u,n);for(let e=0;e<p;e++)r[e]^=n[e]}r.copy(h,(e-1)*p)}return a.from(h.buffer,h.byteOffset,c)}function pbkdf2(e,t,n,r,i,a){try{validateParameters(n,r)}catch(e){throw e}setTimeout(()=>{try{a(null,pbkdf2Sync(e,t,n,r,i))}catch(e){a(e instanceof Error?e:Error(String(e)))}},0)}export{pbkdf2,pbkdf2Sync};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{randomBytes as a}from"./random.js";import{Buffer as o}from"node:buffer";function extractPem(e){if(typeof e==`string`)return e;if(o.isBuffer(e)||e instanceof Uint8Array)return o.from(e).toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e.key;if(typeof t==`string`)return t;if(o.isBuffer(t)||t instanceof Uint8Array)return o.from(t).toString(`utf8`)}throw TypeError(`Invalid key argument`)}function pkcs1v15Type2Pad(e,t){let n=t-11;if(e.length>n)throw Error(`Data too long for key size. Max ${n} bytes, got ${e.length}`);let r=t-e.length-3,i=new Uint8Array(t);i[0]=0,i[1]=2;let o=a(r);for(let e=0;e<r;e++){for(;o[e]===0;)o[e]=a(1)[0];i[2+e]=o[e]}return i[2+r]=0,i.set(e,3+r),i}function pkcs1v15Type1Pad(e,t){let n=t-11;if(e.length>n)throw Error(`Data too long for key size. Max ${n} bytes, got ${e.length}`);let r=t-e.length-3,i=new Uint8Array(t);i[0]=0,i[1]=1;for(let e=2;e<2+r;e++)i[e]=255;return i[2+r]=0,i.set(e,3+r),i}function pkcs1v15Type2Unpad(e){if(e.length<11)throw Error(`Decryption error: message too short`);if(e[0]!==0||e[1]!==2)throw Error(`Decryption error: invalid padding`);let t=2;for(;t<e.length&&e[t]!==0;)t++;if(t>=e.length||t<10)throw Error(`Decryption error: invalid padding`);return e.slice(t+1)}function pkcs1v15Type1Unpad(e){if(e.length<11)throw Error(`Decryption error: message too short`);if(e[0]!==0||e[1]!==1)throw Error(`Decryption error: invalid padding`);let t=2;for(;t<e.length&&e[t]===255;)t++;if(t>=e.length||e[t]!==0||t<10)throw Error(`Decryption error: invalid padding`);return e.slice(t+1)}function publicEncrypt(a,s){let c=e(extractPem(a)),l,u;if(c.type===`rsa-public`)l=c.components.n,u=c.components.e;else if(c.type===`rsa-private`)l=c.components.n,u=c.components.e;else throw Error(`Key must be an RSA public or private key`);let d=t(l),f=i(r(pkcs1v15Type2Pad(s instanceof Uint8Array?s:o.from(s),d)),u,l);return o.from(n(f,d))}function privateDecrypt(a,s){let c=e(extractPem(a));if(c.type!==`rsa-private`)throw Error(`Key must be an RSA private key`);let{n:l,d:u}=c.components,d=t(l),f=s instanceof Uint8Array?s:o.from(s);if(f.length!==d)throw Error(`Data length (${f.length}) does not match key length (${d})`);let p=r(f);if(p>=l)throw Error(`Decryption error: cipher value out of range`);let m=n(i(p,u,l),d);return o.from(pkcs1v15Type2Unpad(m))}function privateEncrypt(a,s){let c=e(extractPem(a));if(c.type!==`rsa-private`)throw Error(`Key must be an RSA private key`);let{n:l,d:u}=c.components,d=t(l),f=i(r(pkcs1v15Type1Pad(s instanceof Uint8Array?s:o.from(s),d)),u,l);return o.from(n(f,d))}function publicDecrypt(a,s){let c=e(extractPem(a)),l,u;if(c.type===`rsa-public`)l=c.components.n,u=c.components.e;else if(c.type===`rsa-private`)l=c.components.n,u=c.components.e;else throw Error(`Key must be an RSA public or private key`);let d=t(l),f=s instanceof Uint8Array?s:o.from(s);if(f.length!==d)throw Error(`Data length (${f.length}) does not match key length (${d})`);let p=r(f);if(p>=l)throw Error(`Decryption error: cipher value out of range`);let m=n(i(p,u,l),d);return o.from(pkcs1v15Type1Unpad(m))}export{privateDecrypt,privateEncrypt,publicDecrypt,publicEncrypt};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{randomBytes as a}from"./random.js";import{Buffer as o}from"node:buffer";function extractPem(e){if(typeof e==`string`)return e;if(o.isBuffer(e)||e instanceof Uint8Array)return o.from(e).toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e.key;if(typeof t==`string`)return t;if(o.isBuffer(t)||t instanceof Uint8Array)return o.from(t).toString(`utf8`)}throw TypeError(`Invalid key argument`)}function pkcs1v15Type2Pad(e,t){let n=t-11;if(e.length>n)throw Error(`Data too long for key size. Max ${n} bytes, got ${e.length}`);let r=t-e.length-3,i=new Uint8Array(t);i[0]=0,i[1]=2;let o=a(r);for(let e=0;e<r;e++){for(;o[e]===0;)o[e]=a(1)[0];i[2+e]=o[e]}return i[2+r]=0,i.set(e,3+r),i}function pkcs1v15Type1Pad(e,t){let n=t-11;if(e.length>n)throw Error(`Data too long for key size. Max ${n} bytes, got ${e.length}`);let r=t-e.length-3,i=new Uint8Array(t);i[0]=0,i[1]=1;for(let e=2;e<2+r;e++)i[e]=255;return i[2+r]=0,i.set(e,3+r),i}function pkcs1v15Type2Unpad(e){if(e.length<11)throw Error(`Decryption error: message too short`);if(e[0]!==0||e[1]!==2)throw Error(`Decryption error: invalid padding`);let t=2;for(;t<e.length&&e[t]!==0;)t++;if(t>=e.length||t<10)throw Error(`Decryption error: invalid padding`);return e.slice(t+1)}function pkcs1v15Type1Unpad(e){if(e.length<11)throw Error(`Decryption error: message too short`);if(e[0]!==0||e[1]!==1)throw Error(`Decryption error: invalid padding`);let t=2;for(;t<e.length&&e[t]===255;)t++;if(t>=e.length||e[t]!==0||t<10)throw Error(`Decryption error: invalid padding`);return e.slice(t+1)}function publicEncrypt(a,s){let c=e(extractPem(a)),l,u;if(c.type===`rsa-public`)l=c.components.n,u=c.components.e;else if(c.type===`rsa-private`)l=c.components.n,u=c.components.e;else throw Error(`Key must be an RSA public or private key`);let d=t(l),f=i(r(pkcs1v15Type2Pad(s instanceof Uint8Array?s:o.from(s),d)),u,l);return o.from(n(f,d))}function privateDecrypt(a,s){let c=e(extractPem(a));if(c.type!==`rsa-private`)throw Error(`Key must be an RSA private key`);let{n:l,d:u}=c.components,d=t(l),f=s instanceof Uint8Array?s:o.from(s);if(f.length!==d)throw Error(`Data length (${f.length}) does not match key length (${d})`);let p=r(f);if(p>=l)throw Error(`Decryption error: cipher value out of range`);let m=n(i(p,u,l),d);return o.from(pkcs1v15Type2Unpad(m))}function privateEncrypt(a,s){let c=e(extractPem(a));if(c.type!==`rsa-private`)throw Error(`Key must be an RSA private key`);let{n:l,d:u}=c.components,d=t(l),f=i(r(pkcs1v15Type1Pad(s instanceof Uint8Array?s:o.from(s),d)),u,l);return o.from(n(f,d))}function publicDecrypt(a,s){let c=e(extractPem(a)),l,u;if(c.type===`rsa-public`)l=c.components.n,u=c.components.e;else if(c.type===`rsa-private`)l=c.components.n,u=c.components.e;else throw Error(`Key must be an RSA public or private key`);let d=t(l),f=s instanceof Uint8Array?s:o.from(s);if(f.length!==d)throw Error(`Data length (${f.length}) does not match key length (${d})`);let p=r(f);if(p>=l)throw Error(`Decryption error: cipher value out of range`);let m=n(i(p,u,l),d);return o.from(pkcs1v15Type1Unpad(m))}export{privateDecrypt,privateEncrypt,publicDecrypt,publicEncrypt};
|
package/lib/esm/random.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as e}from"node:buffer";const t=globalThis.crypto!==void 0&&typeof globalThis.crypto.getRandomValues==`function`;function fillRandom(e){if(t)for(let t=0;t<e.length;t+=65536){let n=Math.min(e.length-t,65536),r=new Uint8Array(e.buffer,e.byteOffset+t,n);globalThis.crypto.getRandomValues(r)}else try{let t=imports.gi.GLib;for(let n=0;n<e.length;n++)e[n]=t.random_int_range(0,256)}catch{for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}}function randomBytes(t,n){if(typeof t!=`number`||t<0||!Number.isInteger(t))throw TypeError(`The "size" argument must be a non-negative integer. Received ${t}`);try{let r=e.alloc(t);if(t>0&&fillRandom(new Uint8Array(r.buffer,r.byteOffset,r.byteLength)),n)n(null,r);else return r}catch(t){if(n)n(t,e.alloc(0));else throw t}}function randomFillSync(t,n=0,r){let i=r??t.length-n;if(n<0||n>t.length)throw RangeError(`The value of "offset" is out of range. Received ${n}`);if(i<0||n+i>t.length)throw RangeError(`The value of "size" is out of range. Received ${i}`);if(i>0){let r=(t instanceof e,t.byteOffset);fillRandom(new Uint8Array(t.buffer,r+n,i))}return t}function randomFill(e,t,n,r){let i,a,o;typeof t==`function`?(o=t,i=0,a=e.length):typeof n==`function`?(o=n,i=t,a=e.length-t):(o=r,i=t,a=n);try{randomFillSync(e,i,a),o(null,e)}catch(t){o(t,e)}}function randomUUID(){if(t&&typeof globalThis.crypto.randomUUID==`function`)return globalThis.crypto.randomUUID();let e=new Uint8Array(16);fillRandom(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function randomInt(e,t,n){let r,i,a;if(typeof t==`function`?(a=t,i=e,r=0):typeof t==`number`?(r=e,i=t,a=n):(i=e,r=0,a=n),!Number.isInteger(r))throw TypeError(`The "min" argument must be a safe integer. Received ${r}`);if(!Number.isInteger(i))throw TypeError(`The "max" argument must be a safe integer. Received ${i}`);if(r>=i)throw RangeError(`The value of "min" must be less than "max". Received min: ${r}, max: ${i}`);let o=i-r,s=new Uint32Array(1);fillRandom(new Uint8Array(s.buffer));let c=r+s[0]%o;if(a)a(null,c);else return c}export{randomBytes,randomFill,randomFillSync,randomInt,randomUUID};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Buffer as e}from"node:buffer";const t=globalThis.crypto!==void 0&&typeof globalThis.crypto.getRandomValues==`function`;function fillRandom(e){if(t)for(let t=0;t<e.length;t+=65536){let n=Math.min(e.length-t,65536),r=new Uint8Array(e.buffer,e.byteOffset+t,n);globalThis.crypto.getRandomValues(r)}else try{let t=imports.gi.GLib;for(let n=0;n<e.length;n++)e[n]=t.random_int_range(0,256)}catch{for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}}function randomBytes(t,n){if(typeof t!=`number`||t<0||!Number.isInteger(t))throw TypeError(`The "size" argument must be a non-negative integer. Received ${t}`);try{let r=e.alloc(t);if(t>0&&fillRandom(new Uint8Array(r.buffer,r.byteOffset,r.byteLength)),n)n(null,r);else return r}catch(t){if(n)n(t,e.alloc(0));else throw t}}function randomFillSync(t,n=0,r){let i=r??t.length-n;if(n<0||n>t.length)throw RangeError(`The value of "offset" is out of range. Received ${n}`);if(i<0||n+i>t.length)throw RangeError(`The value of "size" is out of range. Received ${i}`);if(i>0){let r=(t instanceof e,t.byteOffset);fillRandom(new Uint8Array(t.buffer,r+n,i))}return t}function randomFill(e,t,n,r){let i,a,o;typeof t==`function`?(o=t,i=0,a=e.length):typeof n==`function`?(o=n,i=t,a=e.length-t):(o=r,i=t,a=n);try{randomFillSync(e,i,a),o(null,e)}catch(t){o(t,e)}}function randomUUID(){if(t&&typeof globalThis.crypto.randomUUID==`function`)return globalThis.crypto.randomUUID();let e=new Uint8Array(16);fillRandom(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;let n=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}function randomInt(e,t,n){let r,i,a;if(typeof t==`function`?(a=t,i=e,r=0):typeof t==`number`?(r=e,i=t,a=n):(i=e,r=0,a=n),!Number.isInteger(r))throw TypeError(`The "min" argument must be a safe integer. Received ${r}`);if(!Number.isInteger(i))throw TypeError(`The "max" argument must be a safe integer. Received ${i}`);if(r>=i)throw RangeError(`The value of "min" must be less than "max". Received min: ${r}, max: ${i}`);let o=i-r,s=new Uint32Array(1);fillRandom(new Uint8Array(s.buffer));let c=r+s[0]%o;if(a)a(null,c);else return c}export{randomBytes,randomFill,randomFillSync,randomInt,randomUUID};
|
package/lib/esm/rsa-oaep.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{hashSize as a}from"./crypto-utils.js";import{randomBytes as o}from"./random.js";import{Hash as s}from"./hash.js";import{mgf1 as c}from"./mgf1.js";function hashDigest(e,t){let n=new s(e);return n.update(t),new Uint8Array(n.digest())}function rsaOaepEncrypt(s,l,u,d){let f=e(l),p,m;if(f.type===`rsa-public`)({n:p,e:m}=f.components);else if(f.type===`rsa-private`)({n:p,e:m}=f.components);else throw Error(`RSA-OAEP: expected RSA key`);let h=Math.ceil(t(p)/8),g=a(s);if(u.length>h-2*g-2)throw Error(`RSA-OAEP: message too long`);let _=hashDigest(s,d||new Uint8Array),v=h-g-1,y=new Uint8Array(v);y.set(_,0),y[v-u.length-1]=1,y.set(u,v-u.length);let b=new Uint8Array(o(g)),x=c(s,b,v),S=new Uint8Array(v);for(let e=0;e<v;e++)S[e]=y[e]^x[e];let C=c(s,S,g),w=new Uint8Array(g);for(let e=0;e<g;e++)w[e]=b[e]^C[e];let T=new Uint8Array(h);return T[0]=0,T.set(w,1),T.set(S,1+g),n(i(r(T),m,p),h)}function rsaOaepDecrypt(o,s,l,u){let d=e(s);if(d.type!==`rsa-private`)throw Error(`RSA-OAEP: expected RSA private key`);let{n:f,d:p}=d.components,m=Math.ceil(t(f)/8),h=a(o);if(l.length!==m||m<2*h+2)throw Error(`RSA-OAEP: decryption error`);let g=n(i(r(l),p,f),m),_=g[0],v=g.slice(1,1+h),y=g.slice(1+h),b=m-h-1,x=c(o,y,h),S=new Uint8Array(h);for(let e=0;e<h;e++)S[e]=v[e]^x[e];let C=c(o,S,b),w=new Uint8Array(b);for(let e=0;e<b;e++)w[e]=y[e]^C[e];let T=hashDigest(o,u||new Uint8Array),E=w.slice(0,h),D=+(_===0);for(let e=0;e<h;e++)D&=+(T[e]===E[e]);let O=-1;for(let e=h;e<b;e++)if(w[e]===1){O=e;break}else if(w[e]!==0){D=0;break}if(O===-1&&(D=0),!D)throw Error(`RSA-OAEP: decryption error`);return w.slice(O+1)}export{rsaOaepDecrypt,rsaOaepEncrypt};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{hashSize as a}from"./crypto-utils.js";import{randomBytes as o}from"./random.js";import{Hash as s}from"./hash.js";import{mgf1 as c}from"./mgf1.js";function hashDigest(e,t){let n=new s(e);return n.update(t),new Uint8Array(n.digest())}function rsaOaepEncrypt(s,l,u,d){let f=e(l),p,m;if(f.type===`rsa-public`)({n:p,e:m}=f.components);else if(f.type===`rsa-private`)({n:p,e:m}=f.components);else throw Error(`RSA-OAEP: expected RSA key`);let h=Math.ceil(t(p)/8),g=a(s);if(u.length>h-2*g-2)throw Error(`RSA-OAEP: message too long`);let _=hashDigest(s,d||new Uint8Array),v=h-g-1,y=new Uint8Array(v);y.set(_,0),y[v-u.length-1]=1,y.set(u,v-u.length);let b=new Uint8Array(o(g)),x=c(s,b,v),S=new Uint8Array(v);for(let e=0;e<v;e++)S[e]=y[e]^x[e];let C=c(s,S,g),w=new Uint8Array(g);for(let e=0;e<g;e++)w[e]=b[e]^C[e];let T=new Uint8Array(h);return T[0]=0,T.set(w,1),T.set(S,1+g),n(i(r(T),m,p),h)}function rsaOaepDecrypt(o,s,l,u){let d=e(s);if(d.type!==`rsa-private`)throw Error(`RSA-OAEP: expected RSA private key`);let{n:f,d:p}=d.components,m=Math.ceil(t(f)/8),h=a(o);if(l.length!==m||m<2*h+2)throw Error(`RSA-OAEP: decryption error`);let g=n(i(r(l),p,f),m),_=g[0],v=g.slice(1,1+h),y=g.slice(1+h),b=m-h-1,x=c(o,y,h),S=new Uint8Array(h);for(let e=0;e<h;e++)S[e]=v[e]^x[e];let C=c(o,S,b),w=new Uint8Array(b);for(let e=0;e<b;e++)w[e]=y[e]^C[e];let T=hashDigest(o,u||new Uint8Array),E=w.slice(0,h),D=+(_===0);for(let e=0;e<h;e++)D&=+(T[e]===E[e]);let O=-1;for(let e=h;e<b;e++)if(w[e]===1){O=e;break}else if(w[e]!==0){D=0;break}if(O===-1&&(D=0),!D)throw Error(`RSA-OAEP: decryption error`);return w.slice(O+1)}export{rsaOaepDecrypt,rsaOaepEncrypt};
|
package/lib/esm/rsa-pss.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{hashSize as a}from"./crypto-utils.js";import{randomBytes as o}from"./random.js";import{Hash as s}from"./hash.js";import{mgf1 as c}from"./mgf1.js";function hashDigest(e,t){let n=new s(e);return n.update(t),new Uint8Array(n.digest())}function emsaPssEncode(e,t,n,r){let i=a(n),s=Math.ceil(t/8);if(s<i+r+2)throw Error(`RSA-PSS: encoding error — key too short`);let l=r>0?new Uint8Array(o(r)):new Uint8Array,u=new Uint8Array(8+i+r);u.set(e,8),u.set(l,8+i);let d=hashDigest(n,u),f=s-i-1,p=new Uint8Array(f);p[f-r-1]=1,p.set(l,f-r);let m=c(n,d,f),h=new Uint8Array(f);for(let e=0;e<f;e++)h[e]=p[e]^m[e];let g=8*s-t;g>0&&(h[0]&=255>>>g);let _=new Uint8Array(s);return _.set(h,0),_.set(d,f),_[s-1]=188,_}function emsaPssVerify(e,t,n,r,i){let o=a(r),s=Math.ceil(n/8);if(s<o+i+2||t[s-1]!==188)return!1;let l=s-o-1,u=t.slice(0,l),d=t.slice(l,l+o),f=8*s-n;if(f>0&&u[0]&255<<8-f)return!1;let p=c(r,d,l),m=new Uint8Array(l);for(let e=0;e<l;e++)m[e]=u[e]^p[e];f>0&&(m[0]&=255>>>f);for(let e=0;e<l-i-1;e++)if(m[e]!==0)return!1;if(m[l-i-1]!==1)return!1;let h=m.slice(l-i),g=new Uint8Array(8+o+i);g.set(e,8),g.set(h,8+o);let _=hashDigest(r,g);if(d.length!==_.length)return!1;let v=0;for(let e=0;e<d.length;e++)v|=d[e]^_[e];return v===0}function rsaPssSign(a,o,s,c){let l=e(o);if(l.type!==`rsa-private`)throw Error(`RSA-PSS: expected RSA private key`);let{n:u,d}=l.components,f=t(u),p=Math.ceil(f/8);return n(i(r(emsaPssEncode(hashDigest(a,s),f-1,a,c)),d,u),p)}function rsaPssVerify(a,o,s,c,l){let u=e(o),d,f;if(u.type===`rsa-public`)({n:d,e:f}=u.components);else if(u.type===`rsa-private`)({n:d,e:f}=u.components);else throw Error(`RSA-PSS: expected RSA key`);let p=t(d),m=Math.ceil(p/8);if(s.length!==m)return!1;let h=n(i(r(s),f,d),Math.ceil((p-1)/8));return emsaPssVerify(hashDigest(a,c),h,p-1,a,l)}export{rsaPssSign,rsaPssVerify};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{hashSize as a}from"./crypto-utils.js";import{randomBytes as o}from"./random.js";import{Hash as s}from"./hash.js";import{mgf1 as c}from"./mgf1.js";function hashDigest(e,t){let n=new s(e);return n.update(t),new Uint8Array(n.digest())}function emsaPssEncode(e,t,n,r){let i=a(n),s=Math.ceil(t/8);if(s<i+r+2)throw Error(`RSA-PSS: encoding error — key too short`);let l=r>0?new Uint8Array(o(r)):new Uint8Array,u=new Uint8Array(8+i+r);u.set(e,8),u.set(l,8+i);let d=hashDigest(n,u),f=s-i-1,p=new Uint8Array(f);p[f-r-1]=1,p.set(l,f-r);let m=c(n,d,f),h=new Uint8Array(f);for(let e=0;e<f;e++)h[e]=p[e]^m[e];let g=8*s-t;g>0&&(h[0]&=255>>>g);let _=new Uint8Array(s);return _.set(h,0),_.set(d,f),_[s-1]=188,_}function emsaPssVerify(e,t,n,r,i){let o=a(r),s=Math.ceil(n/8);if(s<o+i+2||t[s-1]!==188)return!1;let l=s-o-1,u=t.slice(0,l),d=t.slice(l,l+o),f=8*s-n;if(f>0&&u[0]&255<<8-f)return!1;let p=c(r,d,l),m=new Uint8Array(l);for(let e=0;e<l;e++)m[e]=u[e]^p[e];f>0&&(m[0]&=255>>>f);for(let e=0;e<l-i-1;e++)if(m[e]!==0)return!1;if(m[l-i-1]!==1)return!1;let h=m.slice(l-i),g=new Uint8Array(8+o+i);g.set(e,8),g.set(h,8+o);let _=hashDigest(r,g);if(d.length!==_.length)return!1;let v=0;for(let e=0;e<d.length;e++)v|=d[e]^_[e];return v===0}function rsaPssSign(a,o,s,c){let l=e(o);if(l.type!==`rsa-private`)throw Error(`RSA-PSS: expected RSA private key`);let{n:u,d}=l.components,f=t(u),p=Math.ceil(f/8);return n(i(r(emsaPssEncode(hashDigest(a,s),f-1,a,c)),d,u),p)}function rsaPssVerify(a,o,s,c,l){let u=e(o),d,f;if(u.type===`rsa-public`)({n:d,e:f}=u.components);else if(u.type===`rsa-private`)({n:d,e:f}=u.components);else throw Error(`RSA-PSS: expected RSA key`);let p=t(d),m=Math.ceil(p/8);if(s.length!==m)return!1;let h=n(i(r(s),f,d),Math.ceil((p-1)/8));return emsaPssVerify(hashDigest(a,c),h,p-1,a,l)}export{rsaPssSign,rsaPssVerify};
|
package/lib/esm/scrypt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pbkdf2Sync as e}from"./pbkdf2.js";import{Buffer as t}from"node:buffer";function R(e,t){return(e<<t|e>>>32-t)>>>0}function salsa20_8(e){let t=new Uint32Array(16);for(let n=0;n<16;n++)t[n]=e[n];for(let e=0;e<4;e++)t[4]^=R(t[0]+t[12],7),t[8]^=R(t[4]+t[0],9),t[12]^=R(t[8]+t[4],13),t[0]^=R(t[12]+t[8],18),t[9]^=R(t[5]+t[1],7),t[13]^=R(t[9]+t[5],9),t[1]^=R(t[13]+t[9],13),t[5]^=R(t[1]+t[13],18),t[14]^=R(t[10]+t[6],7),t[2]^=R(t[14]+t[10],9),t[6]^=R(t[2]+t[14],13),t[10]^=R(t[6]+t[2],18),t[3]^=R(t[15]+t[11],7),t[7]^=R(t[3]+t[15],9),t[11]^=R(t[7]+t[3],13),t[15]^=R(t[11]+t[7],18),t[1]^=R(t[0]+t[3],7),t[2]^=R(t[1]+t[0],9),t[3]^=R(t[2]+t[1],13),t[0]^=R(t[3]+t[2],18),t[6]^=R(t[5]+t[4],7),t[7]^=R(t[6]+t[5],9),t[4]^=R(t[7]+t[6],13),t[5]^=R(t[4]+t[7],18),t[11]^=R(t[10]+t[9],7),t[8]^=R(t[11]+t[10],9),t[9]^=R(t[8]+t[11],13),t[10]^=R(t[9]+t[8],18),t[12]^=R(t[15]+t[14],7),t[13]^=R(t[12]+t[15],9),t[14]^=R(t[13]+t[12],13),t[15]^=R(t[14]+t[13],18);for(let n=0;n<16;n++)e[n]=e[n]+t[n]>>>0}function blockMix(e,t){let n=2*t*16,r=new Uint32Array(16);for(let t=0;t<16;t++)r[t]=e[n-16+t];let i=new Uint32Array(n);for(let n=0;n<2*t;n++){for(let t=0;t<16;t++)r[t]^=e[n*16+t];salsa20_8(r);for(let e=0;e<16;e++)i[n*16+e]=r[e]}for(let n=0;n<t;n++)for(let t=0;t<16;t++)e[n*16+t]=i[2*n*16+t];for(let n=0;n<t;n++)for(let r=0;r<16;r++)e[(t+n)*16+r]=i[(2*n+1)*16+r]}function roMix(e,t,n){let r=2*n*16,i=Array(t);for(let r=0;r<t;r++)i[r]=new Uint32Array(e),blockMix(e,n);for(let a=0;a<t;a++){let a=e[r-16]&t-1;for(let t=0;t<r;t++)e[t]^=i[a][t];blockMix(e,n)}}function bytesToWords(e){let t=new Uint32Array(e.length/4);for(let n=0;n<t.length;n++)t[n]=e[n*4]|e[n*4+1]<<8|e[n*4+2]<<16|e[n*4+3]<<24;return t}function wordsToBytes(e){let t=new Uint8Array(e.length*4);for(let n=0;n<e.length;n++)t[n*4]=e[n]&255,t[n*4+1]=e[n]>>8&255,t[n*4+2]=e[n]>>16&255,t[n*4+3]=e[n]>>24&255;return t}function scryptCore(t,n,r,i,a,o){let s=128*i,c=e(t,n,1,a*s,`sha256`);for(let e=0;e<a;e++){let t=new Uint8Array(c.buffer,c.byteOffset+e*s,s),n=bytesToWords(t);roMix(n,r,i);let a=wordsToBytes(n);t.set(a)}return e(t,c,1,o,`sha256`)}function scryptSync(e,n,r,i){let a=t.from(e),o=t.from(n),s=i?.N??16384,c=i?.r??8,l=i?.p??1;if(s<=0||s&s-1)throw Error(`N must be a positive power of 2`);return scryptCore(a,o,s,c,l,r)}function scrypt(e,n,r,i,a){let o={},s;typeof i==`function`?s=i:(o=i,s=a);try{let t=scryptSync(e,n,r,o);setTimeout(()=>s(null,t),0)}catch(e){setTimeout(()=>s(e instanceof Error?e:Error(String(e)),t.alloc(0)),0)}}export{scrypt,scryptSync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{pbkdf2Sync as e}from"./pbkdf2.js";import{Buffer as t}from"node:buffer";function R(e,t){return(e<<t|e>>>32-t)>>>0}function salsa20_8(e){let t=new Uint32Array(16);for(let n=0;n<16;n++)t[n]=e[n];for(let e=0;e<4;e++)t[4]^=R(t[0]+t[12],7),t[8]^=R(t[4]+t[0],9),t[12]^=R(t[8]+t[4],13),t[0]^=R(t[12]+t[8],18),t[9]^=R(t[5]+t[1],7),t[13]^=R(t[9]+t[5],9),t[1]^=R(t[13]+t[9],13),t[5]^=R(t[1]+t[13],18),t[14]^=R(t[10]+t[6],7),t[2]^=R(t[14]+t[10],9),t[6]^=R(t[2]+t[14],13),t[10]^=R(t[6]+t[2],18),t[3]^=R(t[15]+t[11],7),t[7]^=R(t[3]+t[15],9),t[11]^=R(t[7]+t[3],13),t[15]^=R(t[11]+t[7],18),t[1]^=R(t[0]+t[3],7),t[2]^=R(t[1]+t[0],9),t[3]^=R(t[2]+t[1],13),t[0]^=R(t[3]+t[2],18),t[6]^=R(t[5]+t[4],7),t[7]^=R(t[6]+t[5],9),t[4]^=R(t[7]+t[6],13),t[5]^=R(t[4]+t[7],18),t[11]^=R(t[10]+t[9],7),t[8]^=R(t[11]+t[10],9),t[9]^=R(t[8]+t[11],13),t[10]^=R(t[9]+t[8],18),t[12]^=R(t[15]+t[14],7),t[13]^=R(t[12]+t[15],9),t[14]^=R(t[13]+t[12],13),t[15]^=R(t[14]+t[13],18);for(let n=0;n<16;n++)e[n]=e[n]+t[n]>>>0}function blockMix(e,t){let n=2*t*16,r=new Uint32Array(16);for(let t=0;t<16;t++)r[t]=e[n-16+t];let i=new Uint32Array(n);for(let n=0;n<2*t;n++){for(let t=0;t<16;t++)r[t]^=e[n*16+t];salsa20_8(r);for(let e=0;e<16;e++)i[n*16+e]=r[e]}for(let n=0;n<t;n++)for(let t=0;t<16;t++)e[n*16+t]=i[2*n*16+t];for(let n=0;n<t;n++)for(let r=0;r<16;r++)e[(t+n)*16+r]=i[(2*n+1)*16+r]}function roMix(e,t,n){let r=2*n*16,i=Array(t);for(let r=0;r<t;r++)i[r]=new Uint32Array(e),blockMix(e,n);for(let a=0;a<t;a++){let a=e[r-16]&t-1;for(let t=0;t<r;t++)e[t]^=i[a][t];blockMix(e,n)}}function bytesToWords(e){let t=new Uint32Array(e.length/4);for(let n=0;n<t.length;n++)t[n]=e[n*4]|e[n*4+1]<<8|e[n*4+2]<<16|e[n*4+3]<<24;return t}function wordsToBytes(e){let t=new Uint8Array(e.length*4);for(let n=0;n<e.length;n++)t[n*4]=e[n]&255,t[n*4+1]=e[n]>>8&255,t[n*4+2]=e[n]>>16&255,t[n*4+3]=e[n]>>24&255;return t}function scryptCore(t,n,r,i,a,o){let s=128*i,c=e(t,n,1,a*s,`sha256`);for(let e=0;e<a;e++){let t=new Uint8Array(c.buffer,c.byteOffset+e*s,s),n=bytesToWords(t);roMix(n,r,i);let a=wordsToBytes(n);t.set(a)}return e(t,c,1,o,`sha256`)}function scryptSync(e,n,r,i){let a=t.from(e),o=t.from(n),s=i?.N??16384,c=i?.r??8,l=i?.p??1;if(s<=0||s&s-1)throw Error(`N must be a positive power of 2`);return scryptCore(a,o,s,c,l,r)}function scrypt(e,n,r,i,a){let o={},s;typeof i==`function`?s=i:(o=i,s=a);try{let t=scryptSync(e,n,r,o);setTimeout(()=>s(null,t),0)}catch(e){setTimeout(()=>s(e instanceof Error?e:Error(String(e)),t.alloc(0)),0)}}export{scrypt,scryptSync};
|
package/lib/esm/sign.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{Hash as a}from"./hash.js";import{Buffer as o}from"node:buffer";const s={sha1:new Uint8Array([48,33,48,9,6,5,43,14,3,2,26,5,0,4,20]),sha256:new Uint8Array([48,49,48,13,6,9,96,134,72,1,101,3,4,2,1,5,0,4,32]),sha512:new Uint8Array([48,81,48,13,6,9,96,134,72,1,101,3,4,2,3,5,0,4,64])};function normalizeSignAlgorithm(e){let t=e.toLowerCase().replace(/-/g,``);if(t.startsWith(`rsa`)&&(t=t.slice(3)),!s[t])throw Error(`Unsupported algorithm: ${e}. Supported: RSA-SHA1, RSA-SHA256, RSA-SHA512`);return t}function extractPem(e){if(typeof e==`string`)return e;if(o.isBuffer(e)||e instanceof Uint8Array)return o.from(e).toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e.key;if(typeof t==`string`)return t;if(o.isBuffer(t)||t instanceof Uint8Array)return o.from(t).toString(`utf8`)}throw TypeError(`Invalid key argument`)}var Sign=class{_algorithm;_hash;_finalized=!1;constructor(e){this._algorithm=normalizeSignAlgorithm(e),this._hash=new a(this._algorithm)}update(e,t){if(this._finalized)throw Error(`Sign was already finalized`);return this._hash.update(e,t),this}sign(a,c){if(this._finalized)throw Error(`Sign was already finalized`);this._finalized=!0;let l=this._hash.digest(),u=e(extractPem(a));if(u.type!==`rsa-private`)throw Error(`privateKey must be an RSA private key`);let{n:d,e:f,d:p}=u.components,m=t(d),h=s[this._algorithm],g=new Uint8Array(h.length+l.length);g.set(h,0),g.set(l,h.length);let _=m-g.length-3;if(_<8)throw Error(`Key is too short for the specified hash algorithm`);let v=new Uint8Array(m);v[0]=0,v[1]=1;for(let e=2;e<2+_;e++)v[e]=255;v[2+_]=0,v.set(g,3+_);let y=n(i(r(v),p,d),m),b=o.from(y);return c?b.toString(c):b}},Verify=class{_algorithm;_hash;_finalized=!1;constructor(e){this._algorithm=normalizeSignAlgorithm(e),this._hash=new a(this._algorithm)}update(e,t){if(this._finalized)throw Error(`Verify was already finalized`);return this._hash.update(e,t),this}verify(a,c,l){if(this._finalized)throw Error(`Verify was already finalized`);this._finalized=!0;let u=this._hash.digest(),d=e(extractPem(a)),f,p;if(d.type===`rsa-public`)f=d.components.n,p=d.components.e;else if(d.type===`rsa-private`)f=d.components.n,p=d.components.e;else throw Error(`publicKey must be an RSA public or private key`);let m=t(f),h;if(h=typeof c==`string`?o.from(c,l||`base64`):c instanceof Uint8Array?c:o.from(c),h.length!==m)return!1;let g=r(h);if(g>=f)return!1;let _=n(i(g,p,f),m);if(_[0]!==0||_[1]!==1)return!1;let v=2;for(;v<_.length&&_[v]===255;)v++;if(v>=_.length||_[v]!==0||v-2<8)return!1;v++;let y=_.slice(v),b=s[this._algorithm],x=new Uint8Array(b.length+u.length);if(x.set(b,0),x.set(u,b.length),y.length!==x.length)return!1;let S=0;for(let e=0;e<y.length;e++)S|=y[e]^x[e];return S===0}};function createSign(e){return new Sign(e)}function createVerify(e){return new Verify(e)}export{Sign,Verify,createSign,createVerify};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parsePemKey as e,rsaKeySize as t}from"./asn1.js";import{bigIntToBytes as n,bytesToBigInt as r,modPow as i}from"./bigint-math.js";import{Hash as a}from"./hash.js";import{Buffer as o}from"node:buffer";const s={sha1:new Uint8Array([48,33,48,9,6,5,43,14,3,2,26,5,0,4,20]),sha256:new Uint8Array([48,49,48,13,6,9,96,134,72,1,101,3,4,2,1,5,0,4,32]),sha512:new Uint8Array([48,81,48,13,6,9,96,134,72,1,101,3,4,2,3,5,0,4,64])};function normalizeSignAlgorithm(e){let t=e.toLowerCase().replace(/-/g,``);if(t.startsWith(`rsa`)&&(t=t.slice(3)),!s[t])throw Error(`Unsupported algorithm: ${e}. Supported: RSA-SHA1, RSA-SHA256, RSA-SHA512`);return t}function extractPem(e){if(typeof e==`string`)return e;if(o.isBuffer(e)||e instanceof Uint8Array)return o.from(e).toString(`utf8`);if(e&&typeof e==`object`&&`key`in e){let t=e.key;if(typeof t==`string`)return t;if(o.isBuffer(t)||t instanceof Uint8Array)return o.from(t).toString(`utf8`)}throw TypeError(`Invalid key argument`)}var Sign=class{_algorithm;_hash;_finalized=!1;constructor(e){this._algorithm=normalizeSignAlgorithm(e),this._hash=new a(this._algorithm)}update(e,t){if(this._finalized)throw Error(`Sign was already finalized`);return this._hash.update(e,t),this}sign(a,c){if(this._finalized)throw Error(`Sign was already finalized`);this._finalized=!0;let l=this._hash.digest(),u=e(extractPem(a));if(u.type!==`rsa-private`)throw Error(`privateKey must be an RSA private key`);let{n:d,e:f,d:p}=u.components,m=t(d),h=s[this._algorithm],g=new Uint8Array(h.length+l.length);g.set(h,0),g.set(l,h.length);let _=m-g.length-3;if(_<8)throw Error(`Key is too short for the specified hash algorithm`);let v=new Uint8Array(m);v[0]=0,v[1]=1;for(let e=2;e<2+_;e++)v[e]=255;v[2+_]=0,v.set(g,3+_);let y=n(i(r(v),p,d),m),b=o.from(y);return c?b.toString(c):b}},Verify=class{_algorithm;_hash;_finalized=!1;constructor(e){this._algorithm=normalizeSignAlgorithm(e),this._hash=new a(this._algorithm)}update(e,t){if(this._finalized)throw Error(`Verify was already finalized`);return this._hash.update(e,t),this}verify(a,c,l){if(this._finalized)throw Error(`Verify was already finalized`);this._finalized=!0;let u=this._hash.digest(),d=e(extractPem(a)),f,p;if(d.type===`rsa-public`)f=d.components.n,p=d.components.e;else if(d.type===`rsa-private`)f=d.components.n,p=d.components.e;else throw Error(`publicKey must be an RSA public or private key`);let m=t(f),h;if(h=typeof c==`string`?o.from(c,l||`base64`):c instanceof Uint8Array?c:o.from(c),h.length!==m)return!1;let g=r(h);if(g>=f)return!1;let _=n(i(g,p,f),m);if(_[0]!==0||_[1]!==1)return!1;let v=2;for(;v<_.length&&_[v]===255;)v++;if(v>=_.length||_[v]!==0||v-2<8)return!1;v++;let y=_.slice(v),b=s[this._algorithm],x=new Uint8Array(b.length+u.length);if(x.set(b,0),x.set(u,b.length),y.length!==x.length)return!1;let S=0;for(let e=0;e<y.length;e++)S|=y[e]^x[e];return S===0}};function createSign(e){return new Sign(e)}function createVerify(e){return new Verify(e)}export{Sign,Verify,createSign,createVerify};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function timingSafeEqual(e,t){if(e.length!==t.length)throw RangeError(`Input buffers must have the same byte length`);let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}export{timingSafeEqual};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function timingSafeEqual(e,t){if(e.length!==t.length)throw RangeError(`Input buffers must have the same byte length`);let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}export{timingSafeEqual};
|
package/lib/esm/x509.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derToPem as e,encodeSubjectPublicKeyInfo as t,parseX509 as n,parseX509Der as r}from"./asn1.js";import{KeyObject as i}from"./key-object.js";import{createHash as a}from"./index.js";import{Buffer as o}from"node:buffer";var X509Certificate=class{_components;_pem;constructor(t){if(typeof t==`string`)this._pem=t,this._components=n(t);else{let i=o.isBuffer(t)?t:o.from(t),a=i.toString(`utf8`);a.includes(`-----BEGIN CERTIFICATE-----`)?(this._pem=a,this._components=n(a)):(this._components=r(new Uint8Array(i.buffer,i.byteOffset,i.byteLength)),this._pem=e(this._components.raw,`CERTIFICATE`))}}get raw(){return o.from(this._components.raw)}get serialNumber(){return this._components.serialNumber.toString(16).toUpperCase()}get subject(){return this._components.subject}get issuer(){return this._components.issuer}get validFrom(){return this._components.validFrom.toUTCString()}get validTo(){return this._components.validTo.toUTCString()}get fingerprint(){return formatFingerprint(a(`sha1`).update(this._components.raw).digest())}get fingerprint256(){return formatFingerprint(a(`sha256`).update(this._components.raw).digest())}get fingerprint512(){return formatFingerprint(a(`sha512`).update(this._components.raw).digest())}get publicKey(){if(!this._components.publicKey)throw Error(`Certificate does not contain a supported public key type`);let n=e(t(this._components.publicKey),`PUBLIC KEY`);return new i(`public`,{parsed:{type:`rsa-public`,components:this._components.publicKey},pem:n})}get subjectAltName(){if(!(!this._components.subjectAltName||this._components.subjectAltName.length===0))return this._components.subjectAltName.join(`, `)}get keyUsage(){}get infoAccess(){}get ca(){return!1}checkHost(e){let t=this._components.subject.match(/CN=([^,]+)/);if(t){let n=t[1].trim();if(matchHostname(n,e))return n}if(this._components.subjectAltName){for(let t of this._components.subjectAltName)if(t.startsWith(`DNS:`)){let n=t.substring(4);if(matchHostname(n,e))return n}}}checkEmail(e){let t=e.toLowerCase(),n=this._components.subject.match(/emailAddress=([^,]+)/);if(n&&n[1].toLowerCase()===t)return n[1]}checkIP(e){if(this._components.subjectAltName){for(let t of this._components.subjectAltName)if(t.startsWith(`IP Address:`)&&t.substring(11)===e)return e}}verify(e){return!0}checkIssued(e){return this.issuer===e.subject}toLegacyObject(){return{subject:parseDNToObject(this._components.subject),issuer:parseDNToObject(this._components.issuer),valid_from:this.validFrom,valid_to:this.validTo,serialNumber:this.serialNumber,fingerprint:this.fingerprint,fingerprint256:this.fingerprint256}}toString(){return this._pem}toJSON(){return this._pem}get[Symbol.toStringTag](){return`X509Certificate`}};function formatFingerprint(e){let t=e.toString(`hex`).toUpperCase(),n=[];for(let e=0;e<t.length;e+=2)n.push(t.substring(e,e+2));return n.join(`:`)}function matchHostname(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(n===r)return!0;if(n.startsWith(`*.`)){let e=n.substring(2),t=r.split(`.`);if(t.length>=2)return t.slice(1).join(`.`)===e}return!1}function parseDNToObject(e){let t={},n=e.split(`, `);for(let e of n){let n=e.indexOf(`=`);n>0&&(t[e.substring(0,n)]=e.substring(n+1))}return t}export{X509Certificate};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{derToPem as e,encodeSubjectPublicKeyInfo as t,parseX509 as n,parseX509Der as r}from"./asn1.js";import{KeyObject as i}from"./key-object.js";import{createHash as a}from"./index.js";import{Buffer as o}from"node:buffer";var X509Certificate=class{_components;_pem;constructor(t){if(typeof t==`string`)this._pem=t,this._components=n(t);else{let i=o.isBuffer(t)?t:o.from(t),a=i.toString(`utf8`);a.includes(`-----BEGIN CERTIFICATE-----`)?(this._pem=a,this._components=n(a)):(this._components=r(new Uint8Array(i.buffer,i.byteOffset,i.byteLength)),this._pem=e(this._components.raw,`CERTIFICATE`))}}get raw(){return o.from(this._components.raw)}get serialNumber(){return this._components.serialNumber.toString(16).toUpperCase()}get subject(){return this._components.subject}get issuer(){return this._components.issuer}get validFrom(){return this._components.validFrom.toUTCString()}get validTo(){return this._components.validTo.toUTCString()}get fingerprint(){return formatFingerprint(a(`sha1`).update(this._components.raw).digest())}get fingerprint256(){return formatFingerprint(a(`sha256`).update(this._components.raw).digest())}get fingerprint512(){return formatFingerprint(a(`sha512`).update(this._components.raw).digest())}get publicKey(){if(!this._components.publicKey)throw Error(`Certificate does not contain a supported public key type`);let n=e(t(this._components.publicKey),`PUBLIC KEY`);return new i(`public`,{parsed:{type:`rsa-public`,components:this._components.publicKey},pem:n})}get subjectAltName(){if(!(!this._components.subjectAltName||this._components.subjectAltName.length===0))return this._components.subjectAltName.join(`, `)}get keyUsage(){}get infoAccess(){}get ca(){return!1}checkHost(e){let t=this._components.subject.match(/CN=([^,]+)/);if(t){let n=t[1].trim();if(matchHostname(n,e))return n}if(this._components.subjectAltName){for(let t of this._components.subjectAltName)if(t.startsWith(`DNS:`)){let n=t.substring(4);if(matchHostname(n,e))return n}}}checkEmail(e){let t=e.toLowerCase(),n=this._components.subject.match(/emailAddress=([^,]+)/);if(n&&n[1].toLowerCase()===t)return n[1]}checkIP(e){if(this._components.subjectAltName){for(let t of this._components.subjectAltName)if(t.startsWith(`IP Address:`)&&t.substring(11)===e)return e}}verify(e){return!0}checkIssued(e){return this.issuer===e.subject}toLegacyObject(){return{subject:parseDNToObject(this._components.subject),issuer:parseDNToObject(this._components.issuer),valid_from:this.validFrom,valid_to:this.validTo,serialNumber:this.serialNumber,fingerprint:this.fingerprint,fingerprint256:this.fingerprint256}}toString(){return this._pem}toJSON(){return this._pem}get[Symbol.toStringTag](){return`X509Certificate`}};function formatFingerprint(e){let t=e.toString(`hex`).toUpperCase(),n=[];for(let e=0;e<t.length;e+=2)n.push(t.substring(e,e+2));return n.join(`:`)}function matchHostname(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(n===r)return!0;if(n.startsWith(`*.`)){let e=n.substring(2),t=r.split(`.`);if(t.length>=2)return t.slice(1).join(`.`)===e}return!1}function parseDNToObject(e){let t={},n=e.split(`, `);for(let e of n){let n=e.indexOf(`=`);n>0&&(t[e.substring(0,n)]=e.substring(n+1))}return t}export{X509Certificate};
|
package/package.json
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"name": "@gjsify/crypto",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "Node.js crypto module for Gjs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "lib/esm/index.js",
|
|
7
|
+
"types": "lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
19
|
+
"check": "tsc --noEmit",
|
|
20
|
+
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
21
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
22
|
+
"build:types": "tsc",
|
|
23
|
+
"build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
|
|
24
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
25
|
+
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
26
|
+
"test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
|
|
27
|
+
"test:gjs": "gjsify run test.gjs.mjs",
|
|
28
|
+
"test:node": "node test.node.mjs"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"gjs",
|
|
32
|
+
"node",
|
|
33
|
+
"crypto"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@gjsify/cli": "workspace:^",
|
|
37
|
+
"@gjsify/unit": "workspace:^",
|
|
38
|
+
"@types/diffie-hellman": "^5.0.3",
|
|
39
|
+
"@types/node": "^25.6.2",
|
|
40
|
+
"typescript": "^6.0.3"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
|
|
44
|
+
"@gjsify/buffer": "workspace:^",
|
|
45
|
+
"@gjsify/stream": "workspace:^",
|
|
46
|
+
"@gjsify/utils": "workspace:^"
|
|
12
47
|
}
|
|
13
|
-
|
|
14
|
-
"scripts": {
|
|
15
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
16
|
-
"check": "tsc --noEmit",
|
|
17
|
-
"build": "yarn build:gjsify && yarn build:types",
|
|
18
|
-
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
19
|
-
"build:types": "tsc",
|
|
20
|
-
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
21
|
-
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
22
|
-
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
23
|
-
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
24
|
-
"test:gjs": "gjsify run test.gjs.mjs",
|
|
25
|
-
"test:node": "node test.node.mjs"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"gjs",
|
|
29
|
-
"node",
|
|
30
|
-
"crypto"
|
|
31
|
-
],
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@gjsify/cli": "^0.3.21",
|
|
34
|
-
"@gjsify/unit": "^0.3.21",
|
|
35
|
-
"@types/diffie-hellman": "^5.0.3",
|
|
36
|
-
"@types/node": "^25.6.2",
|
|
37
|
-
"typescript": "^6.0.3"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
|
|
41
|
-
"@gjsify/buffer": "^0.3.21",
|
|
42
|
-
"@gjsify/stream": "^0.3.21",
|
|
43
|
-
"@gjsify/utils": "^0.3.21"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
48
|
+
}
|