@talismn/crypto 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/encryption/encryptKemAead.d.ts +1 -0
- package/dist/declarations/src/encryption/index.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/talismn-crypto.cjs.dev.js +18 -0
- package/dist/talismn-crypto.cjs.prod.js +18 -0
- package/dist/talismn-crypto.esm.js +18 -1
- package/package.json +5 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const encryptKemAead: (publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./encryptKemAead";
|
|
@@ -16,6 +16,9 @@ var bip32 = require('@scure/bip32');
|
|
|
16
16
|
var hmac = require('@noble/hashes/hmac');
|
|
17
17
|
var sha512 = require('@noble/hashes/sha512');
|
|
18
18
|
var microSr25519 = require('micro-sr25519');
|
|
19
|
+
var chacha_js = require('@noble/ciphers/chacha.js');
|
|
20
|
+
var utils_js = require('@noble/ciphers/utils.js');
|
|
21
|
+
var mlkem = require('mlkem');
|
|
19
22
|
|
|
20
23
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
24
|
|
|
@@ -700,6 +703,20 @@ const getAccountPlatformFromAddress = address => {
|
|
|
700
703
|
return getAccountPlatformFromEncoding(encoding);
|
|
701
704
|
};
|
|
702
705
|
|
|
706
|
+
const encryptKemAead = async (publicKey, plaintext) => {
|
|
707
|
+
const kem = new mlkem.MlKem768();
|
|
708
|
+
const [kemCt, sharedSecret] = await kem.encap(publicKey);
|
|
709
|
+
if (sharedSecret.length !== 32) {
|
|
710
|
+
throw new Error(`Expected 32-byte shared secret, got ${sharedSecret.length}`);
|
|
711
|
+
}
|
|
712
|
+
const nonce = crypto.getRandomValues(new Uint8Array(24));
|
|
713
|
+
const aead = chacha_js.xchacha20poly1305(sharedSecret, nonce);
|
|
714
|
+
const aeadCt = aead.encrypt(plaintext);
|
|
715
|
+
const kemLen = new Uint8Array(2);
|
|
716
|
+
new DataView(kemLen.buffer).setUint16(0, kemCt.length, true);
|
|
717
|
+
return utils_js.concatBytes(kemLen, kemCt, nonce, aeadCt);
|
|
718
|
+
};
|
|
719
|
+
|
|
703
720
|
Object.defineProperty(exports, "base58", {
|
|
704
721
|
enumerable: true,
|
|
705
722
|
get: function () { return base.base58; }
|
|
@@ -736,6 +753,7 @@ exports.encodeAddressEthereum = encodeAddressEthereum;
|
|
|
736
753
|
exports.encodeAddressSolana = encodeAddressSolana;
|
|
737
754
|
exports.encodeAddressSs58 = encodeAddressSs58;
|
|
738
755
|
exports.encodeAnyAddress = encodeAnyAddress;
|
|
756
|
+
exports.encryptKemAead = encryptKemAead;
|
|
739
757
|
exports.entropyToMnemonic = entropyToMnemonic;
|
|
740
758
|
exports.entropyToSeed = entropyToSeed;
|
|
741
759
|
exports.fromBase58Check = fromBase58Check;
|
|
@@ -16,6 +16,9 @@ var bip32 = require('@scure/bip32');
|
|
|
16
16
|
var hmac = require('@noble/hashes/hmac');
|
|
17
17
|
var sha512 = require('@noble/hashes/sha512');
|
|
18
18
|
var microSr25519 = require('micro-sr25519');
|
|
19
|
+
var chacha_js = require('@noble/ciphers/chacha.js');
|
|
20
|
+
var utils_js = require('@noble/ciphers/utils.js');
|
|
21
|
+
var mlkem = require('mlkem');
|
|
19
22
|
|
|
20
23
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
24
|
|
|
@@ -700,6 +703,20 @@ const getAccountPlatformFromAddress = address => {
|
|
|
700
703
|
return getAccountPlatformFromEncoding(encoding);
|
|
701
704
|
};
|
|
702
705
|
|
|
706
|
+
const encryptKemAead = async (publicKey, plaintext) => {
|
|
707
|
+
const kem = new mlkem.MlKem768();
|
|
708
|
+
const [kemCt, sharedSecret] = await kem.encap(publicKey);
|
|
709
|
+
if (sharedSecret.length !== 32) {
|
|
710
|
+
throw new Error(`Expected 32-byte shared secret, got ${sharedSecret.length}`);
|
|
711
|
+
}
|
|
712
|
+
const nonce = crypto.getRandomValues(new Uint8Array(24));
|
|
713
|
+
const aead = chacha_js.xchacha20poly1305(sharedSecret, nonce);
|
|
714
|
+
const aeadCt = aead.encrypt(plaintext);
|
|
715
|
+
const kemLen = new Uint8Array(2);
|
|
716
|
+
new DataView(kemLen.buffer).setUint16(0, kemCt.length, true);
|
|
717
|
+
return utils_js.concatBytes(kemLen, kemCt, nonce, aeadCt);
|
|
718
|
+
};
|
|
719
|
+
|
|
703
720
|
Object.defineProperty(exports, "base58", {
|
|
704
721
|
enumerable: true,
|
|
705
722
|
get: function () { return base.base58; }
|
|
@@ -736,6 +753,7 @@ exports.encodeAddressEthereum = encodeAddressEthereum;
|
|
|
736
753
|
exports.encodeAddressSolana = encodeAddressSolana;
|
|
737
754
|
exports.encodeAddressSs58 = encodeAddressSs58;
|
|
738
755
|
exports.encodeAnyAddress = encodeAnyAddress;
|
|
756
|
+
exports.encryptKemAead = encryptKemAead;
|
|
739
757
|
exports.entropyToMnemonic = entropyToMnemonic;
|
|
740
758
|
exports.entropyToSeed = entropyToSeed;
|
|
741
759
|
exports.fromBase58Check = fromBase58Check;
|
|
@@ -16,6 +16,9 @@ import { HDKey } from '@scure/bip32';
|
|
|
16
16
|
import { hmac } from '@noble/hashes/hmac';
|
|
17
17
|
import { sha512 } from '@noble/hashes/sha512';
|
|
18
18
|
import { getPublicKey, HDKD, secretFromSeed } from 'micro-sr25519';
|
|
19
|
+
import { xchacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
20
|
+
import { concatBytes } from '@noble/ciphers/utils.js';
|
|
21
|
+
import { MlKem768 } from 'mlkem';
|
|
19
22
|
|
|
20
23
|
const pbkdf2 = async (hash, entropy, salt, iterations, outputLenBytes) => {
|
|
21
24
|
// NOTE: react-native-quick-crypto (our `global.crypto` polyfill on Talisman Mobile) doesn't support `crypto.subtle.deriveKey`.
|
|
@@ -696,4 +699,18 @@ const getAccountPlatformFromAddress = address => {
|
|
|
696
699
|
return getAccountPlatformFromEncoding(encoding);
|
|
697
700
|
};
|
|
698
701
|
|
|
699
|
-
|
|
702
|
+
const encryptKemAead = async (publicKey, plaintext) => {
|
|
703
|
+
const kem = new MlKem768();
|
|
704
|
+
const [kemCt, sharedSecret] = await kem.encap(publicKey);
|
|
705
|
+
if (sharedSecret.length !== 32) {
|
|
706
|
+
throw new Error(`Expected 32-byte shared secret, got ${sharedSecret.length}`);
|
|
707
|
+
}
|
|
708
|
+
const nonce = crypto.getRandomValues(new Uint8Array(24));
|
|
709
|
+
const aead = xchacha20poly1305(sharedSecret, nonce);
|
|
710
|
+
const aeadCt = aead.encrypt(plaintext);
|
|
711
|
+
const kemLen = new Uint8Array(2);
|
|
712
|
+
new DataView(kemLen.buffer).setUint16(0, kemCt.length, true);
|
|
713
|
+
return concatBytes(kemLen, kemCt, nonce, aeadCt);
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
export { DEV_MNEMONIC_ETHEREUM, DEV_MNEMONIC_POLKADOT, addressEncodingFromCurve, addressFromMnemonic, addressFromPublicKey, blake2b256, blake2b512, blake3, checksumEthereumAddress, decodeSs58Address, deriveKeypair, detectAddressEncoding, encodeAddressEthereum, encodeAddressSolana, encodeAddressSs58, encodeAnyAddress, encryptKemAead, entropyToMnemonic, entropyToSeed, fromBase58Check, fromBech32, fromBech32m, generateMnemonic, getAccountPlatformFromAddress, getAccountPlatformFromCurve, getAccountPlatformFromEncoding, getDevSeed, getPublicKeyFromSecret, getSafeHash, isAddressEqual, isAddressValid, isBase58CheckAddress, isBech32Address, isBech32mAddress, isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSs58Address, isValidDerivationPath, isValidMnemonic, mnemonicToEntropy, normalizeAddress, parseSecretKey, pbkdf2, removeHexPrefix };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talismn/crypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "Talisman",
|
|
5
5
|
"homepage": "https://talisman.xyz",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@noble/ciphers": "2.0.1",
|
|
24
25
|
"@noble/curves": "1.9.2",
|
|
25
26
|
"@noble/hashes": "1.8.0",
|
|
26
27
|
"@scure/base": "1.2.6",
|
|
@@ -29,16 +30,18 @@
|
|
|
29
30
|
"bech32": "2.0.0",
|
|
30
31
|
"bs58check": "4.0.0",
|
|
31
32
|
"micro-sr25519": "0.1.3",
|
|
33
|
+
"mlkem": "2.5.0",
|
|
32
34
|
"scale-ts": "1.6.1"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@types/jest": "^29.5.14",
|
|
38
|
+
"@swc/jest": "^0.2.36",
|
|
36
39
|
"eslint": "^8.57.1",
|
|
37
40
|
"jest": "^29.7.0",
|
|
38
41
|
"ts-jest": "^29.2.5",
|
|
39
42
|
"typescript": "^5.6.3",
|
|
40
43
|
"@talismn/eslint-config": "0.0.3",
|
|
41
|
-
"@talismn/tsconfig": "0.0.
|
|
44
|
+
"@talismn/tsconfig": "0.0.3"
|
|
42
45
|
},
|
|
43
46
|
"preconstruct": {
|
|
44
47
|
"entrypoints": [
|