@left-curve/crypto
Advanced tools
+0
-19
@@ -44,20 +44,1 @@ "use strict"; | ||
| var import_signature = require("./signature/index.js"); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Ed25519, | ||
| Keccak256, | ||
| Ripemd160, | ||
| Secp256k1, | ||
| Sha256, | ||
| Sha512, | ||
| ed25519VerifySignature, | ||
| ethHashMessage, | ||
| keccak256, | ||
| ripemd160, | ||
| secp256k1CompressPubKey, | ||
| secp256k1RecoverPubKey, | ||
| secp256k1VerifySignature, | ||
| sha256, | ||
| sha512, | ||
| ...require("./webauthn/index.js") | ||
| }); |
+14
-29
@@ -6,5 +6,2 @@ "use strict"; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __export = (target, all) => { | ||
@@ -23,6 +20,2 @@ for (var name in all) | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| var ed25519_exports = {}; | ||
@@ -37,3 +30,2 @@ __export(ed25519_exports, { | ||
| var import_bip39 = require("@scure/bip39"); | ||
| var _privateKey; | ||
| function ed25519VerifySignature(messageHash, signature, publicKey) { | ||
@@ -45,10 +37,4 @@ if (messageHash.length !== 32) { | ||
| } | ||
| const _Ed25519 = class _Ed25519 { | ||
| constructor(privateKey) { | ||
| __privateAdd(this, _privateKey); | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| __privateSet(this, _privateKey, privateKey); | ||
| } | ||
| class Ed25519 { | ||
| #privateKey; | ||
| /** | ||
@@ -60,3 +46,3 @@ * Generate a new ed25519 key pair. | ||
| const privateKey = import_ed25519.ed25519.utils.randomPrivateKey(); | ||
| return new _Ed25519(privateKey); | ||
| return new Ed25519(privateKey); | ||
| } | ||
@@ -74,9 +60,15 @@ /** | ||
| if (!privateKey) throw new Error("Failed to derive private key from mnemonic"); | ||
| return new _Ed25519(privateKey); | ||
| return new Ed25519(privateKey); | ||
| } | ||
| constructor(privateKey) { | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| this.#privateKey = privateKey; | ||
| } | ||
| getPublicKey() { | ||
| return import_ed25519.ed25519.getPublicKey(__privateGet(this, _privateKey)); | ||
| return import_ed25519.ed25519.getPublicKey(this.#privateKey); | ||
| } | ||
| get privateKey() { | ||
| return __privateGet(this, _privateKey); | ||
| return this.#privateKey; | ||
| } | ||
@@ -95,3 +87,3 @@ /** | ||
| } | ||
| return import_ed25519.ed25519.sign(messageHash, __privateGet(this, _privateKey)); | ||
| return import_ed25519.ed25519.sign(messageHash, this.#privateKey); | ||
| } | ||
@@ -107,9 +99,2 @@ /** | ||
| } | ||
| }; | ||
| _privateKey = new WeakMap(); | ||
| let Ed25519 = _Ed25519; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Ed25519, | ||
| ed25519VerifySignature | ||
| }); | ||
| } |
@@ -27,3 +27,3 @@ import { KeyPair } from './keypair.cjs'; | ||
| getPublicKey(): Uint8Array; | ||
| get privateKey(): Uint8Array; | ||
| get privateKey(): Uint8Array<ArrayBufferLike>; | ||
| /** | ||
@@ -30,0 +30,0 @@ * Sign a message hash with the private key. |
@@ -27,3 +27,3 @@ import { KeyPair } from './keypair.js'; | ||
| getPublicKey(): Uint8Array; | ||
| get privateKey(): Uint8Array; | ||
| get privateKey(): Uint8Array<ArrayBufferLike>; | ||
| /** | ||
@@ -30,0 +30,0 @@ * Sign a message hash with the private key. |
+14
-24
@@ -1,9 +0,1 @@ | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| var _privateKey; | ||
| import { ed25519 } from "@noble/curves/ed25519"; | ||
@@ -18,10 +10,4 @@ import { HDKey } from "@scure/bip32"; | ||
| } | ||
| const _Ed25519 = class _Ed25519 { | ||
| constructor(privateKey) { | ||
| __privateAdd(this, _privateKey); | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| __privateSet(this, _privateKey, privateKey); | ||
| } | ||
| class Ed25519 { | ||
| #privateKey; | ||
| /** | ||
@@ -33,3 +19,3 @@ * Generate a new ed25519 key pair. | ||
| const privateKey = ed25519.utils.randomPrivateKey(); | ||
| return new _Ed25519(privateKey); | ||
| return new Ed25519(privateKey); | ||
| } | ||
@@ -47,9 +33,15 @@ /** | ||
| if (!privateKey) throw new Error("Failed to derive private key from mnemonic"); | ||
| return new _Ed25519(privateKey); | ||
| return new Ed25519(privateKey); | ||
| } | ||
| constructor(privateKey) { | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| this.#privateKey = privateKey; | ||
| } | ||
| getPublicKey() { | ||
| return ed25519.getPublicKey(__privateGet(this, _privateKey)); | ||
| return ed25519.getPublicKey(this.#privateKey); | ||
| } | ||
| get privateKey() { | ||
| return __privateGet(this, _privateKey); | ||
| return this.#privateKey; | ||
| } | ||
@@ -68,3 +60,3 @@ /** | ||
| } | ||
| return ed25519.sign(messageHash, __privateGet(this, _privateKey)); | ||
| return ed25519.sign(messageHash, this.#privateKey); | ||
| } | ||
@@ -80,5 +72,3 @@ /** | ||
| } | ||
| }; | ||
| _privateKey = new WeakMap(); | ||
| let Ed25519 = _Ed25519; | ||
| } | ||
| export { | ||
@@ -85,0 +75,0 @@ Ed25519, |
@@ -31,10 +31,1 @@ "use strict"; | ||
| var import_ed25519 = require("./ed25519.js"); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Ed25519, | ||
| Secp256k1, | ||
| ed25519VerifySignature, | ||
| secp256k1CompressPubKey, | ||
| secp256k1RecoverPubKey, | ||
| secp256k1VerifySignature | ||
| }); |
| type KeyPair = { | ||
| getPublicKey(compressed?: boolean): Uint8Array; | ||
| createSignature: (hash: Uint8Array) => Uint8Array; | ||
| createSignature: (hash: Uint8Array, recoveryId?: boolean) => Uint8Array; | ||
| verifySignature: (hash: Uint8Array, signature: Uint8Array) => boolean; | ||
@@ -5,0 +5,0 @@ }; |
| type KeyPair = { | ||
| getPublicKey(compressed?: boolean): Uint8Array; | ||
| createSignature: (hash: Uint8Array) => Uint8Array; | ||
| createSignature: (hash: Uint8Array, recoveryId?: boolean) => Uint8Array; | ||
| verifySignature: (hash: Uint8Array, signature: Uint8Array) => boolean; | ||
@@ -5,0 +5,0 @@ }; |
+18
-34
@@ -6,5 +6,2 @@ "use strict"; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __export = (target, all) => { | ||
@@ -23,6 +20,2 @@ for (var name in all) | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| var secp256k1_exports = {}; | ||
@@ -36,7 +29,6 @@ __export(secp256k1_exports, { | ||
| module.exports = __toCommonJS(secp256k1_exports); | ||
| var import_encoding = require("@left-curve/encoding"); | ||
| var import_secp256k1 = require("@noble/curves/secp256k1"); | ||
| var import_bip32 = require("@scure/bip32"); | ||
| var import_bip39 = require("@scure/bip39"); | ||
| var _privateKey; | ||
| var import_encoding = require("@left-curve/encoding"); | ||
| async function secp256k1RecoverPubKey(hash, _signature_, compressed = false) { | ||
@@ -76,10 +68,4 @@ const hashHex = (0, import_encoding.isHex)(hash) ? hash.replace("0x", "") : (0, import_encoding.encodeHex)(hash); | ||
| } | ||
| const _Secp256k1 = class _Secp256k1 { | ||
| constructor(privateKey) { | ||
| __privateAdd(this, _privateKey); | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| __privateSet(this, _privateKey, privateKey); | ||
| } | ||
| class Secp256k1 { | ||
| #privateKey; | ||
| /** | ||
@@ -91,3 +77,3 @@ * Generate a new secp256k1 key pair. | ||
| const privateKey = import_secp256k1.secp256k1.utils.randomPrivateKey(); | ||
| return new _Secp256k1(privateKey); | ||
| return new Secp256k1(privateKey); | ||
| } | ||
@@ -105,9 +91,15 @@ /** | ||
| if (!privateKey) throw new Error("Failed to derive private key from mnemonic"); | ||
| return new _Secp256k1(privateKey); | ||
| return new Secp256k1(privateKey); | ||
| } | ||
| constructor(privateKey) { | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| this.#privateKey = privateKey; | ||
| } | ||
| getPublicKey(compressed = true) { | ||
| return import_secp256k1.secp256k1.getPublicKey(__privateGet(this, _privateKey), compressed); | ||
| return import_secp256k1.secp256k1.getPublicKey(this.#privateKey, compressed); | ||
| } | ||
| get privateKey() { | ||
| return __privateGet(this, _privateKey); | ||
| return this.#privateKey; | ||
| } | ||
@@ -119,3 +111,3 @@ /** | ||
| */ | ||
| createSignature(messageHash) { | ||
| createSignature(messageHash, recovery = false) { | ||
| if (messageHash.length === 0) { | ||
@@ -127,4 +119,5 @@ throw new Error("Message hash must not be empty"); | ||
| } | ||
| const signature = import_secp256k1.secp256k1.sign(messageHash, __privateGet(this, _privateKey), { lowS: true }); | ||
| return signature.toCompactRawBytes(); | ||
| const signature = import_secp256k1.secp256k1.sign(messageHash, this.#privateKey, { lowS: true }); | ||
| if (!recovery) return signature.toCompactRawBytes(); | ||
| return new Uint8Array([...signature.toCompactRawBytes(), signature.recovery]); | ||
| } | ||
@@ -140,11 +133,2 @@ /** | ||
| } | ||
| }; | ||
| _privateKey = new WeakMap(); | ||
| let Secp256k1 = _Secp256k1; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Secp256k1, | ||
| secp256k1CompressPubKey, | ||
| secp256k1RecoverPubKey, | ||
| secp256k1VerifySignature | ||
| }); | ||
| } |
@@ -1,2 +0,2 @@ | ||
| import { Hex, Signature } from '@left-curve/types'; | ||
| import { Hex, RawSignature } from '@left-curve/types'; | ||
| import { KeyPair } from './keypair.cjs'; | ||
@@ -11,3 +11,3 @@ | ||
| */ | ||
| declare function secp256k1RecoverPubKey(hash: Hex | Uint8Array, _signature_: Hex | Uint8Array | Signature, compressed?: boolean): Promise<Uint8Array>; | ||
| declare function secp256k1RecoverPubKey(hash: Hex | Uint8Array, _signature_: Hex | Uint8Array | RawSignature, compressed?: boolean): Promise<Uint8Array>; | ||
| /** | ||
@@ -44,3 +44,3 @@ * Compress or uncompress a secp256k1 public key. | ||
| getPublicKey(compressed?: boolean): Uint8Array; | ||
| get privateKey(): Uint8Array; | ||
| get privateKey(): Uint8Array<ArrayBufferLike>; | ||
| /** | ||
@@ -51,3 +51,3 @@ * Sign a message hash with the private key. | ||
| */ | ||
| createSignature(messageHash: Uint8Array): Uint8Array; | ||
| createSignature(messageHash: Uint8Array, recovery?: boolean): Uint8Array; | ||
| /** | ||
@@ -54,0 +54,0 @@ * Verify a signature of a message hash. |
@@ -1,2 +0,2 @@ | ||
| import { Hex, Signature } from '@left-curve/types'; | ||
| import { Hex, RawSignature } from '@left-curve/types'; | ||
| import { KeyPair } from './keypair.js'; | ||
@@ -11,3 +11,3 @@ | ||
| */ | ||
| declare function secp256k1RecoverPubKey(hash: Hex | Uint8Array, _signature_: Hex | Uint8Array | Signature, compressed?: boolean): Promise<Uint8Array>; | ||
| declare function secp256k1RecoverPubKey(hash: Hex | Uint8Array, _signature_: Hex | Uint8Array | RawSignature, compressed?: boolean): Promise<Uint8Array>; | ||
| /** | ||
@@ -44,3 +44,3 @@ * Compress or uncompress a secp256k1 public key. | ||
| getPublicKey(compressed?: boolean): Uint8Array; | ||
| get privateKey(): Uint8Array; | ||
| get privateKey(): Uint8Array<ArrayBufferLike>; | ||
| /** | ||
@@ -51,3 +51,3 @@ * Sign a message hash with the private key. | ||
| */ | ||
| createSignature(messageHash: Uint8Array): Uint8Array; | ||
| createSignature(messageHash: Uint8Array, recovery?: boolean): Uint8Array; | ||
| /** | ||
@@ -54,0 +54,0 @@ * Verify a signature of a message hash. |
+18
-27
@@ -1,13 +0,5 @@ | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| var _privateKey; | ||
| import { encodeHex, hexToBigInt, isHex } from "@left-curve/encoding"; | ||
| import { secp256k1 } from "@noble/curves/secp256k1"; | ||
| import { HDKey } from "@scure/bip32"; | ||
| import { mnemonicToSeedSync } from "@scure/bip39"; | ||
| import { encodeHex, hexToBigInt, isHex } from "@left-curve/encoding"; | ||
| async function secp256k1RecoverPubKey(hash, _signature_, compressed = false) { | ||
@@ -47,10 +39,4 @@ const hashHex = isHex(hash) ? hash.replace("0x", "") : encodeHex(hash); | ||
| } | ||
| const _Secp256k1 = class _Secp256k1 { | ||
| constructor(privateKey) { | ||
| __privateAdd(this, _privateKey); | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| __privateSet(this, _privateKey, privateKey); | ||
| } | ||
| class Secp256k1 { | ||
| #privateKey; | ||
| /** | ||
@@ -62,3 +48,3 @@ * Generate a new secp256k1 key pair. | ||
| const privateKey = secp256k1.utils.randomPrivateKey(); | ||
| return new _Secp256k1(privateKey); | ||
| return new Secp256k1(privateKey); | ||
| } | ||
@@ -76,9 +62,15 @@ /** | ||
| if (!privateKey) throw new Error("Failed to derive private key from mnemonic"); | ||
| return new _Secp256k1(privateKey); | ||
| return new Secp256k1(privateKey); | ||
| } | ||
| constructor(privateKey) { | ||
| if (privateKey.length !== 32) { | ||
| throw new Error(`Private key length must be 32 bytes: ${privateKey.length}`); | ||
| } | ||
| this.#privateKey = privateKey; | ||
| } | ||
| getPublicKey(compressed = true) { | ||
| return secp256k1.getPublicKey(__privateGet(this, _privateKey), compressed); | ||
| return secp256k1.getPublicKey(this.#privateKey, compressed); | ||
| } | ||
| get privateKey() { | ||
| return __privateGet(this, _privateKey); | ||
| return this.#privateKey; | ||
| } | ||
@@ -90,3 +82,3 @@ /** | ||
| */ | ||
| createSignature(messageHash) { | ||
| createSignature(messageHash, recovery = false) { | ||
| if (messageHash.length === 0) { | ||
@@ -98,4 +90,5 @@ throw new Error("Message hash must not be empty"); | ||
| } | ||
| const signature = secp256k1.sign(messageHash, __privateGet(this, _privateKey), { lowS: true }); | ||
| return signature.toCompactRawBytes(); | ||
| const signature = secp256k1.sign(messageHash, this.#privateKey, { lowS: true }); | ||
| if (!recovery) return signature.toCompactRawBytes(); | ||
| return new Uint8Array([...signature.toCompactRawBytes(), signature.recovery]); | ||
| } | ||
@@ -111,5 +104,3 @@ /** | ||
| } | ||
| }; | ||
| _privateKey = new WeakMap(); | ||
| let Secp256k1 = _Secp256k1; | ||
| } | ||
| export { | ||
@@ -116,0 +107,0 @@ Secp256k1, |
+2
-7
@@ -27,5 +27,5 @@ "use strict"; | ||
| class Ripemd160 { | ||
| blockSize = 512 / 8; | ||
| impl = import_ripemd160.ripemd160.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 512 / 8; | ||
| this.impl = import_ripemd160.ripemd160.create(); | ||
| if (firstData) { | ||
@@ -46,6 +46,1 @@ this.update(firstData); | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Ripemd160, | ||
| ripemd160 | ||
| }); |
+2
-2
| import { ripemd160 as nobleRipemd160 } from "@noble/hashes/ripemd160"; | ||
| class Ripemd160 { | ||
| blockSize = 512 / 8; | ||
| impl = nobleRipemd160.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 512 / 8; | ||
| this.impl = nobleRipemd160.create(); | ||
| if (firstData) { | ||
@@ -7,0 +7,0 @@ this.update(firstData); |
+12
-31
@@ -6,5 +6,2 @@ "use strict"; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __export = (target, all) => { | ||
@@ -23,5 +20,2 @@ for (var name in all) | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var sha_exports = {}; | ||
@@ -40,7 +34,6 @@ __export(sha_exports, { | ||
| var import_sha512 = require("@noble/hashes/sha512"); | ||
| var _impl, _impl2, _impl3; | ||
| class Keccak256 { | ||
| blockSize = 136; | ||
| #impl = import_sha3.keccak_256.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 136; | ||
| __privateAdd(this, _impl, import_sha3.keccak_256.create()); | ||
| if (firstData) { | ||
@@ -51,10 +44,9 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl = new WeakMap(); | ||
| function keccak256(data) { | ||
@@ -64,5 +56,5 @@ return new Keccak256(data).digest(); | ||
| class Sha256 { | ||
| blockSize = 512 / 8; | ||
| #impl = import_sha256.sha256.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 512 / 8; | ||
| __privateAdd(this, _impl2, import_sha256.sha256.create()); | ||
| if (firstData) { | ||
@@ -73,10 +65,9 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl2).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl2).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl2 = new WeakMap(); | ||
| function sha256(data) { | ||
@@ -86,5 +77,5 @@ return new Sha256(data).digest(); | ||
| class Sha512 { | ||
| blockSize = 1024 / 8; | ||
| #impl = import_sha512.sha512.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 1024 / 8; | ||
| __privateAdd(this, _impl3, import_sha512.sha512.create()); | ||
| if (firstData) { | ||
@@ -95,21 +86,11 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl3).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl3).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl3 = new WeakMap(); | ||
| function sha512(data) { | ||
| return new Sha512(data).digest(); | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Keccak256, | ||
| Sha256, | ||
| Sha512, | ||
| keccak256, | ||
| sha256, | ||
| sha512 | ||
| }); |
+12
-22
@@ -1,8 +0,1 @@ | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var _impl, _impl2, _impl3; | ||
| import { keccak_256 as nobleKeccak256 } from "@noble/hashes/sha3"; | ||
@@ -12,5 +5,5 @@ import { sha256 as nobleSha256 } from "@noble/hashes/sha256"; | ||
| class Keccak256 { | ||
| blockSize = 136; | ||
| #impl = nobleKeccak256.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 136; | ||
| __privateAdd(this, _impl, nobleKeccak256.create()); | ||
| if (firstData) { | ||
@@ -21,10 +14,9 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl = new WeakMap(); | ||
| function keccak256(data) { | ||
@@ -34,5 +26,5 @@ return new Keccak256(data).digest(); | ||
| class Sha256 { | ||
| blockSize = 512 / 8; | ||
| #impl = nobleSha256.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 512 / 8; | ||
| __privateAdd(this, _impl2, nobleSha256.create()); | ||
| if (firstData) { | ||
@@ -43,10 +35,9 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl2).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl2).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl2 = new WeakMap(); | ||
| function sha256(data) { | ||
@@ -56,5 +47,5 @@ return new Sha256(data).digest(); | ||
| class Sha512 { | ||
| blockSize = 1024 / 8; | ||
| #impl = nobleSha512.create(); | ||
| constructor(firstData) { | ||
| this.blockSize = 1024 / 8; | ||
| __privateAdd(this, _impl3, nobleSha512.create()); | ||
| if (firstData) { | ||
@@ -65,10 +56,9 @@ this.update(firstData); | ||
| update(data) { | ||
| __privateGet(this, _impl3).update(data); | ||
| this.#impl.update(data); | ||
| return this; | ||
| } | ||
| digest() { | ||
| return __privateGet(this, _impl3).digest(); | ||
| return this.#impl.digest(); | ||
| } | ||
| } | ||
| _impl3 = new WeakMap(); | ||
| function sha512(data) { | ||
@@ -75,0 +65,0 @@ return new Sha512(data).digest(); |
@@ -27,3 +27,3 @@ "use strict"; | ||
| const presignMessagePrefix = "Ethereum Signed Message:\n"; | ||
| function ethHashMessage(_message_) { | ||
| function ethHashMessage(_message_, hex = true) { | ||
| const message = (() => { | ||
@@ -38,7 +38,3 @@ if (_message_ instanceof Uint8Array) return _message_; | ||
| ]); | ||
| return (0, import_encoding.encodeHex)((0, import_sha.keccak256)(messageHash)); | ||
| return hex ? (0, import_encoding.encodeHex)((0, import_sha.keccak256)(messageHash)) : (0, import_sha.keccak256)(messageHash); | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| ethHashMessage | ||
| }); |
@@ -1,5 +0,6 @@ | ||
| import { EthPersonalMessage, Hex } from '@left-curve/types'; | ||
| import { Hex } from '@left-curve/types'; | ||
| declare function ethHashMessage(_message_: EthPersonalMessage): Hex; | ||
| type EthPersonalMessage = Hex | string | Uint8Array; | ||
| declare function ethHashMessage<T extends boolean = true>(_message_: EthPersonalMessage, hex?: T): T extends true ? Hex : Uint8Array; | ||
| export { ethHashMessage }; | ||
| export { type EthPersonalMessage, ethHashMessage }; |
@@ -1,5 +0,6 @@ | ||
| import { EthPersonalMessage, Hex } from '@left-curve/types'; | ||
| import { Hex } from '@left-curve/types'; | ||
| declare function ethHashMessage(_message_: EthPersonalMessage): Hex; | ||
| type EthPersonalMessage = Hex | string | Uint8Array; | ||
| declare function ethHashMessage<T extends boolean = true>(_message_: EthPersonalMessage, hex?: T): T extends true ? Hex : Uint8Array; | ||
| export { ethHashMessage }; | ||
| export { type EthPersonalMessage, ethHashMessage }; |
| import { decodeHex, encodeHex, encodeUtf8, isHex } from "@left-curve/encoding"; | ||
| import { keccak256 } from "../sha.js"; | ||
| const presignMessagePrefix = "Ethereum Signed Message:\n"; | ||
| function ethHashMessage(_message_) { | ||
| function ethHashMessage(_message_, hex = true) { | ||
| const message = (() => { | ||
@@ -14,3 +14,3 @@ if (_message_ instanceof Uint8Array) return _message_; | ||
| ]); | ||
| return encodeHex(keccak256(messageHash)); | ||
| return hex ? encodeHex(keccak256(messageHash)) : keccak256(messageHash); | ||
| } | ||
@@ -17,0 +17,0 @@ export { |
@@ -25,5 +25,1 @@ "use strict"; | ||
| var import_ethHashMessage = require("./ethHashMessage.js"); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| ethHashMessage | ||
| }); |
@@ -36,5 +36,5 @@ "use strict"; | ||
| module.exports = __toCommonJS(create_exports); | ||
| var import_cbor_x = require("cbor-x"); | ||
| var import_encoding = require("@left-curve/encoding"); | ||
| var import_cbor_x = require("cbor-x"); | ||
| var import_ripemd = require("../ripemd.js"); | ||
| var import_sha = require("../sha.js"); | ||
| function createChallenge() { | ||
@@ -64,3 +64,3 @@ return crypto.getRandomValues(new Uint8Array(16)); | ||
| }; | ||
| } catch (error) { | ||
| } catch (_error) { | ||
| throw new Error("credential creation failed."); | ||
@@ -108,3 +108,3 @@ } | ||
| user: { | ||
| id: user.id ?? (0, import_ripemd.ripemd160)((0, import_encoding.encodeUtf8)(user.name)), | ||
| id: user.id ?? (0, import_sha.sha256)((0, import_encoding.encodeUtf8)(user.name)), | ||
| name: user.name, | ||
@@ -125,7 +125,1 @@ displayName: user.displayName ?? user.name | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| createChallenge, | ||
| createWebAuthnCredential, | ||
| getCredentialCreationOptions | ||
| }); |
@@ -0,4 +1,4 @@ | ||
| import { decode } from "cbor-x"; | ||
| import { encodeUtf8 } from "@left-curve/encoding"; | ||
| import { decode } from "cbor-x"; | ||
| import { ripemd160 } from "../ripemd.js"; | ||
| import { sha256 } from "../sha.js"; | ||
| function createChallenge() { | ||
@@ -28,3 +28,3 @@ return crypto.getRandomValues(new Uint8Array(16)); | ||
| }; | ||
| } catch (error) { | ||
| } catch (_error) { | ||
| throw new Error("credential creation failed."); | ||
@@ -72,3 +72,3 @@ } | ||
| user: { | ||
| id: user.id ?? ripemd160(encodeUtf8(user.name)), | ||
| id: user.id ?? sha256(encodeUtf8(user.name)), | ||
| name: user.name, | ||
@@ -75,0 +75,0 @@ displayName: user.displayName ?? user.name |
@@ -21,7 +21,1 @@ "use strict"; | ||
| __reExport(webauthn_exports, require("./verify.js"), module.exports); | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| ...require("./create.js"), | ||
| ...require("./signature.js"), | ||
| ...require("./verify.js") | ||
| }); |
@@ -42,3 +42,3 @@ "use strict"; | ||
| }; | ||
| } catch (error) { | ||
| } catch (_error) { | ||
| throw new Error("credential request failed."); | ||
@@ -78,7 +78,1 @@ } | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| getCredentialSignRequestOptions, | ||
| parseAsn1Signature, | ||
| requestWebAuthnSignature | ||
| }); |
@@ -17,3 +17,3 @@ import { decodeBase64Url } from "@left-curve/encoding"; | ||
| }; | ||
| } catch (error) { | ||
| } catch (_error) { | ||
| throw new Error("credential request failed."); | ||
@@ -20,0 +20,0 @@ } |
@@ -48,5 +48,1 @@ "use strict"; | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| verifyWebAuthnSignature | ||
| }); |
+23
-18
| { | ||
| "name": "@left-curve/crypto", | ||
| "version": "0.1.0", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "publishConfig": { | ||
| "registry": "https://registry.npmjs.org/", | ||
| "access": "public" | ||
| }, | ||
| "sideEffects": false, | ||
| "main": "./build/index.cjs", | ||
| "module": "./build/index.js", | ||
| "types": "./build/index.d.ts", | ||
| "typings": "./build/index.d.ts", | ||
| "sideEffects": false, | ||
| "files": [ | ||
| "build" | ||
| ], | ||
| "exports": { | ||
| ".": { | ||
| "source": "./src/index.ts", | ||
| "types": "./build/index.d.ts", | ||
| "import": "./build/index.js", | ||
| "default": "./build/index.cjs" | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
| "vitest": "^2.0.5", | ||
| "@left-curve/config": "^0.1.0", | ||
| "@left-curve/types": "^0.1.0", | ||
| "@left-curve/encoding": "^0.1.0" | ||
| "vitest": "2.1.1", | ||
| "@left-curve/config": "^1.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "cbor-x": "^1.6.0", | ||
| "@noble/curves": "^1.6.0", | ||
@@ -24,9 +34,11 @@ "@noble/hashes": "^1.4.0", | ||
| "@scure/bip39": "^1.3.0", | ||
| "cbor-x": "^1.6.0" | ||
| "@left-curve/types": "^1.0.0", | ||
| "@left-curve/encoding": "^1.0.0" | ||
| }, | ||
| "license": "TBD", | ||
| "homepage": "https://grug.build", | ||
| "homepage": "https://dango.exchange", | ||
| "repository": "left-curve/left-curve", | ||
| "keywords": [ | ||
| "grug", | ||
| "dango", | ||
| "smart-contracts", | ||
@@ -39,13 +51,6 @@ "blockchain", | ||
| "scripts": { | ||
| "ci": "pnpm lint", | ||
| "clean": "rm -rf ./build && rm -rf node_modules", | ||
| "clean:build": "rm -rf ./build", | ||
| "lint": "pnpm biome check --write src", | ||
| "lint:fix": "pnpm biome ci ./src", | ||
| "build": "pnpm tsup --clean", | ||
| "test": "pnpm vitest run", | ||
| "test:watch": "pnpm vitest", | ||
| "pre-dev": "tsc", | ||
| "dev": "tsc -w", | ||
| "build": "pnpm tsup --clean" | ||
| "lint": "pnpm biome check --write src" | ||
| } | ||
| } |
+59
-1
| # @left-curve/crypto | ||
| It includes various cryptographic functions and utilities for encryption, decryption, hashing, and more used in other @left-curve libraries. | ||
| Cryptographic primitives for the [Dango](https://dango.exchange) ecosystem. | ||
| ## Installation | ||
| ```bash | ||
| npm install @left-curve/crypto | ||
| ``` | ||
| ## Usage | ||
| ```typescript | ||
| import { sha256, Secp256k1, Ed25519 } from "@left-curve/crypto"; | ||
| const hash = sha256(new Uint8Array([1, 2, 3])); | ||
| const keypair = Secp256k1.fromMnemonic("your mnemonic ..."); | ||
| const pubkey = keypair.publicKey(); | ||
| ``` | ||
| ## API | ||
| ### Hash Functions | ||
| - `sha256(data)` / `Sha256` - SHA-256 | ||
| - `sha512(data)` / `Sha512` - SHA-512 | ||
| - `keccak256(data)` / `Keccak256` - Keccak-256 | ||
| - `ripemd160(data)` / `Ripemd160` - RIPEMD-160 | ||
| ### Key Pairs | ||
| - `Secp256k1` - secp256k1 elliptic curve key pair | ||
| - `Secp256k1.fromMnemonic(mnemonic)` - derive from BIP-39 mnemonic | ||
| - `Secp256k1.fromPrivateKey(key)` - from raw private key | ||
| - `.publicKey()`, `.sign(data)`, `.verify(data, signature)` | ||
| - `Ed25519` - Ed25519 key pair | ||
| - `.publicKey()`, `.sign(data)`, `.verify(data, signature)` | ||
| ### Utilities | ||
| - `secp256k1RecoverPubKey(hash, signature, recoveryId)` - recover public key | ||
| - `secp256k1CompressPubKey(pubkey)` - compress public key | ||
| - `secp256k1VerifySignature(pubkey, hash, signature)` - verify signature | ||
| - `ed25519VerifySignature(pubkey, hash, signature)` - verify signature | ||
| - `ethHashMessage(message)` - EIP-191 message hashing | ||
| ### WebAuthn | ||
| - `createWebAuthnCredential(options)` - create passkey credential | ||
| - `signWithWebAuthn(credential, challenge)` - sign with passkey | ||
| - `verifyWebAuthn(credential, signature)` - verify passkey signature | ||
| ## Dependencies | ||
| Built on audited libraries: | ||
| - [`@noble/curves`](https://github.com/paulmillr/noble-curves) - elliptic curves | ||
| - [`@noble/hashes`](https://github.com/paulmillr/noble-hashes) - hash functions | ||
| - [`@scure/bip32`](https://github.com/paulmillr/scure-bip32) - HD key derivation | ||
| - [`@scure/bip39`](https://github.com/paulmillr/scure-bip39) - mnemonic generation | ||
| ## License | ||
| TBD |
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
2
-50%0
-100%66
725%77856
-5.44%7
40%1644
-7.9%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added