Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: switch from stablelib to noble #185

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions browser/window-getters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"@types/bn.js": "4.11.6",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
},
"dependencies": {
"mocha": "10.7.0"
}
}
7 changes: 4 additions & 3 deletions browser/window-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
"format": "prettier --config ../../.prettierrc --write {src,test}/**/*.ts"
},
"dependencies": {
"@walletconnect/window-getters": "^1.0.1"
"@walletconnect/window-getters": "^1.0.1",
"mocha": "10.7.0"
},
"devDependencies": {
"@types/bn.js": "4.11.6",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
13 changes: 6 additions & 7 deletions crypto/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,25 @@
"format": "prettier --config ../../.prettierrc --write {src,test}/**/*.ts"
},
"dependencies": {
"@noble/ciphers": "0.5.3",
"@noble/hashes": "1.4.0",
"@walletconnect/encoding": "^1.0.2",
"@walletconnect/environment": "^1.0.1",
"@walletconnect/randombytes": "^1.0.3",
"aes-js": "^3.1.2",
"hash.js": "^1.1.7",
"tslib": "1.14.1"
},
"devDependencies": {
"@peculiar/webcrypto": "^1.1.7",
"@types/aes-js": "^3.1.1",
"@types/chai": "^4.2.14",
"@types/jest": "^26.0.15",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.7",
"@types/randombytes": "^2.0.0",
"chai": "^4.2.0",
"jsdom": "^16.6.0",
"jsdom": "^24.0.0",
"jsdom-global": "^3.0.2",
"mocha": "^8.1.3",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"mocha": "10.7.0",
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
45 changes: 12 additions & 33 deletions crypto/crypto/src/lib/fallback.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,33 @@
import aesJs from "aes-js";
import { hexToArray } from "@walletconnect/encoding";
import * as hash from "hash.js";

import { HEX_ENC, SHA256_NODE_ALGO, SHA512_NODE_ALGO } from "../constants";
import { pkcs7 } from "../helpers";
import { cbc } from "@noble/ciphers/aes";
import { hmac } from "@noble/hashes/hmac";
import { sha256 } from "@noble/hashes/sha256";
import { sha512 } from "@noble/hashes/sha512";
import { ripemd160 } from "@noble/hashes/ripemd160";

export function fallbackAesEncrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array) {
// eslint-disable-next-line new-cap
const aesCbc = new aesJs.ModeOfOperation.cbc(key, iv);
const padded = pkcs7.pad(data);
const encryptedBytes = aesCbc.encrypt(padded);
return new Uint8Array(encryptedBytes);
return cbc(key, iv).encrypt(data);
}

export function fallbackAesDecrypt(iv: Uint8Array, key: Uint8Array, data: Uint8Array) {
// eslint-disable-next-line new-cap
const aesCbc = new aesJs.ModeOfOperation.cbc(key, iv);
const encryptedBytes = aesCbc.decrypt(data);
const padded = new Uint8Array(encryptedBytes);
const result = pkcs7.unpad(padded);
return result;
return cbc(key, iv).decrypt(data);
}

export function fallbackHmacSha256Sign(key: Uint8Array, data: Uint8Array): Uint8Array {
const result = hash
.hmac((hash as any)[SHA256_NODE_ALGO], key)
.update(data)
.digest(HEX_ENC);
return hexToArray(result);
return hmac(sha256, key, data);
}

export function fallbackHmacSha512Sign(key: Uint8Array, data: Uint8Array): Uint8Array {
const result = hash
.hmac((hash as any)[SHA512_NODE_ALGO], key)
.update(data)
.digest(HEX_ENC);
return hexToArray(result);
return hmac(sha512, key, data);
}

export function fallbackSha256(msg: Uint8Array): Uint8Array {
const result = hash.sha256().update(msg).digest(HEX_ENC);
return hexToArray(result);
return sha256(msg);
}

export function fallbackSha512(msg: Uint8Array): Uint8Array {
const result = hash.sha512().update(msg).digest(HEX_ENC);
return hexToArray(result);
return sha512(msg);
}

export function fallbackRipemd160(msg: Uint8Array): Uint8Array {
const result = hash.ripemd160().update(msg).digest(HEX_ENC);
return hexToArray(result);
return ripemd160(msg);
}
3 changes: 2 additions & 1 deletion crypto/crypto/test/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
} from "./common";
import { concatArrays, hexToArray, utf8ToArray } from "@walletconnect/encoding";

global.crypto = new Crypto();
// New node already has crypto API, use if available
if (global.crypto === undefined) global.crypto = new Crypto();

describe("Browser", () => {
describe("isBrowserCryptoAvailable", () => {
Expand Down
3 changes: 2 additions & 1 deletion crypto/crypto/test/fallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
} from "./common";
import { concatArrays, hexToArray, utf8ToArray } from "@walletconnect/encoding";

global.crypto = new Crypto();
// New node already has crypto API, use if available
if (global.crypto === undefined) global.crypto = new Crypto();

describe("Fallback", () => {
describe("AES", () => {
Expand Down
3 changes: 2 additions & 1 deletion crypto/crypto/test/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
TEST_HMAC_SIG,
} from "./common";

global.crypto = new Crypto();
// New node already has crypto API, use if available
if (global.crypto === undefined) global.crypto = new Crypto();

describe("NodeJS", () => {
describe("isNode", () => {
Expand Down
8 changes: 4 additions & 4 deletions crypto/ecies-25519/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"format": "prettier --config ../../.prettierrc --write {src,test}/**/*.ts"
},
"dependencies": {
"@stablelib/x25519": "^1.0.2",
"@noble/curves": "1.4.2",
"@walletconnect/crypto": "^1.0.3",
"@walletconnect/encoding": "^1.0.2",
"tslib": "1.14.1"
Expand All @@ -65,8 +65,8 @@
"chai": "^4.2.0",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
"mocha": "^8.1.3",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"mocha": "10.7.0",
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
13 changes: 6 additions & 7 deletions crypto/ecies-25519/src/ecies/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as x25519 from "@stablelib/x25519";
import { x25519 } from "@noble/curves/ed25519";
import { concatArrays } from "@walletconnect/encoding";
import {
KeyPair,
Expand All @@ -12,7 +12,7 @@ import {
} from "@walletconnect/crypto";

export function derive(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array {
return x25519.sharedKey(privateKey, publicKey);
return x25519.getSharedSecret(privateKey, publicKey);
}

export function generatePnrgFromEntropy(entropy: Uint8Array): PNRG {
Expand All @@ -22,12 +22,11 @@ export function generatePnrgFromEntropy(entropy: Uint8Array): PNRG {
};
}

export function generateKeyPair(entropy?: Uint8Array): KeyPair {
const prng = typeof entropy !== "undefined" ? generatePnrgFromEntropy(entropy) : undefined;
const keyPair = x25519.generateKeyPair(prng);
export function generateKeyPair(privKey?: Uint8Array): KeyPair {
const privateKey = privKey ? privKey : x25519.utils.randomPrivateKey();
return {
publicKey: keyPair.publicKey,
privateKey: keyPair.secretKey,
publicKey: x25519.getPublicKey(privateKey),
privateKey,
};
}

Expand Down
9 changes: 4 additions & 5 deletions crypto/randombytes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"format": "prettier --config ../../.prettierrc --write {src,test}/**/*.ts"
},
"dependencies": {
"@noble/hashes": "1.4.0",
"@walletconnect/encoding": "^1.0.2",
"@walletconnect/environment": "^1.0.1",
"randombytes": "^2.1.0",
"tslib": "1.14.1"
},
"devDependencies": {
Expand All @@ -53,12 +53,11 @@
"@types/jest": "^26.0.15",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.7",
"@types/randombytes": "^2.0.0",
"chai": "^4.2.0",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
"mocha": "^8.1.3",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"mocha": "10.7.0",
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
6 changes: 2 additions & 4 deletions crypto/randombytes/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import crypto from "crypto";
import { bufferToArray } from "@walletconnect/encoding";
import { randomBytes as rb } from "@noble/hashes/utils";

export function randomBytes(length: number): Uint8Array {
const buf = crypto.randomBytes(length);
return bufferToArray(buf);
return rb(length);
}
6 changes: 3 additions & 3 deletions jsonrpc/http-connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"core-js": "^3.6.5",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
6 changes: 3 additions & 3 deletions jsonrpc/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"core-js": "^3.6.5",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
2 changes: 1 addition & 1 deletion jsonrpc/provider/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HttpConnection from "@walletconnect/jsonrpc-http-connection";
import WsConnection from "@walletconnect/jsonrpc-ws-connection";
import * as relayAuth from "@walletconnect/relay-auth";
import { toString } from "uint8arrays";
import { randomBytes } from "@stablelib/random";
import { randomBytes } from "@noble/hashes/utils";
import utils, { formatRelayRpcUrl } from "@walletconnect/utils";
import { version } from "@walletconnect/utils/package.json";

Expand Down
6 changes: 3 additions & 3 deletions jsonrpc/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"@types/node": "^14.14.7",
"chai": "^4.2.0",
"core-js": "^3.6.5",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
6 changes: 3 additions & 3 deletions jsonrpc/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
"chai": "^4.2.0",
"core-js": "^3.6.5",
"lodash.isequal": "4.5.0",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"ts-node": "^9.0.0",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
10 changes: 5 additions & 5 deletions jsonrpc/ws-connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@
"@types/jest": "^26.0.15",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.7",
"@walletconnect/relay-auth": "^1.0.3",
"@walletconnect/utils": "^2.1.3",
"@walletconnect/relay-api": "^1.0.9",
"@walletconnect/relay-auth": "^1.0.3",
"@walletconnect/safe-json": "^1.0.2",
"@walletconnect/time": "^1.0.2",
"@walletconnect/utils": "^2.1.3",
"@walletconnect/window-getters": "^1.0.1",
"@walletconnect/window-metadata": "^1.0.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"core-js": "^3.6.5",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
2 changes: 1 addition & 1 deletion jsonrpc/ws-connection/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WsConnection } from "./../src/ws";
import { RELAY_URL } from "./shared/values";
import * as relayAuth from "@walletconnect/relay-auth";
import { toString } from "uint8arrays";
import { randomBytes } from "@stablelib/random";
import { randomBytes } from "@noble/hashes/utils";
import { formatRelayRpcUrl } from "@walletconnect/utils";
import { version } from "@walletconnect/utils/package.json";
import { fromString } from "uint8arrays/from-string";
Expand Down
5 changes: 3 additions & 2 deletions misc/encoding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"@types/typedarray-to-buffer": "^4.0.0",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
},
"dependencies": {
"is-typedarray": "1.0.0",
"mocha": "10.7.0",
"typedarray-to-buffer": "4.0.0"
}
}
7 changes: 5 additions & 2 deletions misc/environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
},
"dependencies": {
"mocha": "10.7.0"
}
}
6 changes: 3 additions & 3 deletions misc/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"@types/node": "^14.14.7",
"chai": "^4.2.0",
"core-js": "^3.6.5",
"mocha": "^8.1.3",
"mocha": "10.7.0",
"npm-run-all": "^4.1.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11"
"webpack": "5.93.0",
"webpack-cli": "5.1.4"
}
}
Loading