@talismn/keyring 0.1.2 → 0.1.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.
@@ -45,19 +45,15 @@ const getAccountPlatform = account => {
45
45
  };
46
46
 
47
47
  // Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
48
- const deriveKey = async (password, salt) => {
49
- // Deriving 32-byte key using PBKDF2 with 100000 iterations and SHA-256
50
- const keyMaterial = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveKey"]);
51
- return crypto.subtle.deriveKey({
52
- name: "PBKDF2",
53
- salt,
54
- iterations: 100000,
55
- hash: "SHA-256"
56
- }, keyMaterial, {
57
- name: "AES-GCM",
58
- length: 256
59
- }, false, ["encrypt", "decrypt"]);
60
- };
48
+ const deriveKey = async (password, salt) =>
49
+ // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256
50
+ await crypto.subtle.importKey("raw", await crypto$1.pbkdf2("SHA-256", new TextEncoder().encode(password), salt, 100_000,
51
+ // 100,000 iterations
52
+ 32 // 32 bytes (32 * 8 == 256 bits)
53
+ ), {
54
+ name: "AES-GCM",
55
+ length: 256
56
+ }, false, ["encrypt", "decrypt"]);
61
57
  const encryptData = async (data, password) => {
62
58
  try {
63
59
  const salt = crypto.getRandomValues(new Uint8Array(16)); // 16 bytes of salt
@@ -337,7 +333,7 @@ class Keyring {
337
333
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
338
334
  if (!mnemonic) throw new Error("Mnemonic not found");
339
335
  const entropy = await decryptData(mnemonic.entropy, password);
340
- const seed = crypto$1.entropyToSeed(entropy, curve);
336
+ const seed = await crypto$1.entropyToSeed(entropy, curve);
341
337
  const pair = crypto$1.deriveKeypair(seed, derivationPath, curve);
342
338
  if (this.getAccount(pair.address)) throw new Error("Account already exists");
343
339
  const account = {
@@ -388,7 +384,7 @@ class Keyring {
388
384
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
389
385
  if (!mnemonic) throw new Error("Mnemonic not found");
390
386
  const entropy = await decryptData(mnemonic.entropy, password);
391
- const seed = crypto$1.entropyToSeed(entropy, curve);
387
+ const seed = await crypto$1.entropyToSeed(entropy, curve);
392
388
  const pair = crypto$1.deriveKeypair(seed, derivationPath, curve);
393
389
  return pair.address;
394
390
  }
@@ -45,19 +45,15 @@ const getAccountPlatform = account => {
45
45
  };
46
46
 
47
47
  // Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
48
- const deriveKey = async (password, salt) => {
49
- // Deriving 32-byte key using PBKDF2 with 100000 iterations and SHA-256
50
- const keyMaterial = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveKey"]);
51
- return crypto.subtle.deriveKey({
52
- name: "PBKDF2",
53
- salt,
54
- iterations: 100000,
55
- hash: "SHA-256"
56
- }, keyMaterial, {
57
- name: "AES-GCM",
58
- length: 256
59
- }, false, ["encrypt", "decrypt"]);
60
- };
48
+ const deriveKey = async (password, salt) =>
49
+ // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256
50
+ await crypto.subtle.importKey("raw", await crypto$1.pbkdf2("SHA-256", new TextEncoder().encode(password), salt, 100_000,
51
+ // 100,000 iterations
52
+ 32 // 32 bytes (32 * 8 == 256 bits)
53
+ ), {
54
+ name: "AES-GCM",
55
+ length: 256
56
+ }, false, ["encrypt", "decrypt"]);
61
57
  const encryptData = async (data, password) => {
62
58
  try {
63
59
  const salt = crypto.getRandomValues(new Uint8Array(16)); // 16 bytes of salt
@@ -337,7 +333,7 @@ class Keyring {
337
333
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
338
334
  if (!mnemonic) throw new Error("Mnemonic not found");
339
335
  const entropy = await decryptData(mnemonic.entropy, password);
340
- const seed = crypto$1.entropyToSeed(entropy, curve);
336
+ const seed = await crypto$1.entropyToSeed(entropy, curve);
341
337
  const pair = crypto$1.deriveKeypair(seed, derivationPath, curve);
342
338
  if (this.getAccount(pair.address)) throw new Error("Account already exists");
343
339
  const account = {
@@ -388,7 +384,7 @@ class Keyring {
388
384
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
389
385
  if (!mnemonic) throw new Error("Mnemonic not found");
390
386
  const entropy = await decryptData(mnemonic.entropy, password);
391
- const seed = crypto$1.entropyToSeed(entropy, curve);
387
+ const seed = await crypto$1.entropyToSeed(entropy, curve);
392
388
  const pair = crypto$1.deriveKeypair(seed, derivationPath, curve);
393
389
  return pair.address;
394
390
  }
@@ -1,4 +1,4 @@
1
- import { isEthereumAddress, detectAddressEncoding, platformFromCurve, platformFromAddress, stringToBytes, bytesToString, isValidMnemonic, mnemonicToEntropy, entropyToMnemonic, isAddressEqual, normalizeAddress, entropyToSeed, deriveKeypair, getPublicKeyFromSecret, addressEncodingFromCurve, addressFromPublicKey, blake3 } from '@talismn/crypto';
1
+ import { isEthereumAddress, detectAddressEncoding, platformFromCurve, platformFromAddress, pbkdf2, stringToBytes, bytesToString, isValidMnemonic, mnemonicToEntropy, entropyToMnemonic, isAddressEqual, normalizeAddress, entropyToSeed, deriveKeypair, getPublicKeyFromSecret, addressEncodingFromCurve, addressFromPublicKey, blake3 } from '@talismn/crypto';
2
2
 
3
3
  const isAccountOfType = (account, type) => {
4
4
  return account?.type === type;
@@ -43,19 +43,15 @@ const getAccountPlatform = account => {
43
43
  };
44
44
 
45
45
  // Derive a key generated with PBKDF2 that will be used for AES-GCM encryption
46
- const deriveKey = async (password, salt) => {
47
- // Deriving 32-byte key using PBKDF2 with 100000 iterations and SHA-256
48
- const keyMaterial = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveKey"]);
49
- return crypto.subtle.deriveKey({
50
- name: "PBKDF2",
51
- salt,
52
- iterations: 100000,
53
- hash: "SHA-256"
54
- }, keyMaterial, {
55
- name: "AES-GCM",
56
- length: 256
57
- }, false, ["encrypt", "decrypt"]);
58
- };
46
+ const deriveKey = async (password, salt) =>
47
+ // Deriving 32-byte key using PBKDF2 with 100,000 iterations and SHA-256
48
+ await crypto.subtle.importKey("raw", await pbkdf2("SHA-256", new TextEncoder().encode(password), salt, 100_000,
49
+ // 100,000 iterations
50
+ 32 // 32 bytes (32 * 8 == 256 bits)
51
+ ), {
52
+ name: "AES-GCM",
53
+ length: 256
54
+ }, false, ["encrypt", "decrypt"]);
59
55
  const encryptData = async (data, password) => {
60
56
  try {
61
57
  const salt = crypto.getRandomValues(new Uint8Array(16)); // 16 bytes of salt
@@ -335,7 +331,7 @@ class Keyring {
335
331
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
336
332
  if (!mnemonic) throw new Error("Mnemonic not found");
337
333
  const entropy = await decryptData(mnemonic.entropy, password);
338
- const seed = entropyToSeed(entropy, curve);
334
+ const seed = await entropyToSeed(entropy, curve);
339
335
  const pair = deriveKeypair(seed, derivationPath, curve);
340
336
  if (this.getAccount(pair.address)) throw new Error("Account already exists");
341
337
  const account = {
@@ -386,7 +382,7 @@ class Keyring {
386
382
  const mnemonic = this.#data.mnemonics.find(s => s.id === mnemonicId);
387
383
  if (!mnemonic) throw new Error("Mnemonic not found");
388
384
  const entropy = await decryptData(mnemonic.entropy, password);
389
- const seed = entropyToSeed(entropy, curve);
385
+ const seed = await entropyToSeed(entropy, curve);
390
386
  const pair = deriveKeypair(seed, derivationPath, curve);
391
387
  return pair.address;
392
388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/keyring",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -22,7 +22,7 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@talismn/crypto": "0.1.1"
25
+ "@talismn/crypto": "0.1.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/jest": "^29.5.14",