Update wasm-crypto to latest (#389)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# 0.76.1
|
||||
|
||||
- Swap DB interfaces to optional LRU, removing transactionAsync (client-only changes)
|
||||
- Swap out `wasm-schnorrkel` & `wasm-ed25519` for combined version with `wasm-crypto`
|
||||
|
||||
# 0.75.1
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.4.0",
|
||||
"@polkadot/dev": "^0.28.1",
|
||||
"@polkadot/dev": "^0.29.0-beta.0",
|
||||
"@polkadot/ts": "^0.1.56",
|
||||
"gh-pages": "^2.0.1"
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.4.0",
|
||||
"@polkadot/util": "^0.76.0-beta.0",
|
||||
"@polkadot/wasm-crypto": "^0.6.1",
|
||||
"@polkadot/wasm-dalek-ed25519": "^0.6.1",
|
||||
"@polkadot/wasm-schnorrkel": "^0.6.1",
|
||||
"@polkadot/wasm-crypto": "^0.8.0-beta.0",
|
||||
"@types/bip39": "^2.4.2",
|
||||
"@types/pbkdf2": "^3.0.0",
|
||||
"@types/secp256k1": "^3.5.0",
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
import './polyfill';
|
||||
|
||||
import wasmCrypto from '@polkadot/wasm-crypto';
|
||||
import wasmEd25519 from '@polkadot/wasm-dalek-ed25519';
|
||||
import wasmSr25519 from '@polkadot/wasm-schnorrkel';
|
||||
|
||||
export * from './blake2';
|
||||
export * from './keccak';
|
||||
@@ -20,14 +18,8 @@ export * from './sha512';
|
||||
export * from './xxhash';
|
||||
|
||||
export function cryptoWaitReady (): Promise<boolean> {
|
||||
// this is a bit convoluted, but since we can do the same for libsodium,
|
||||
// prepare for multiples, easy to adapt without thinking
|
||||
return Promise
|
||||
.all([
|
||||
wasmCrypto.waitReady(),
|
||||
wasmEd25519.waitReady(),
|
||||
wasmSr25519.waitReady()
|
||||
])
|
||||
return wasmCrypto
|
||||
.waitReady()
|
||||
.then(() => true)
|
||||
.catch((error) => {
|
||||
console.error('Unable to initialize @polkadot/util-crypto', error);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import ed25519 from '@polkadot/wasm-dalek-ed25519';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { naclKeypairFromSeed } from '..';
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('naclKeypairFromSeed', () => {
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
await ed25519.waitReady();
|
||||
await waitReady();
|
||||
});
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (u8a)', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { Keypair } from '../../types';
|
||||
|
||||
import nacl from 'tweetnacl';
|
||||
import { isReady, keypairFromSeed } from '@polkadot/wasm-dalek-ed25519';
|
||||
import { isReady, ed25519KeypairFromSeed } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
* @name naclKeypairFromSeed
|
||||
@@ -23,7 +23,7 @@ import { isReady, keypairFromSeed } from '@polkadot/wasm-dalek-ed25519';
|
||||
*/
|
||||
export default function naclKeypairFromSeed (seed: Uint8Array): Keypair {
|
||||
if (isReady()) {
|
||||
const full = keypairFromSeed(seed);
|
||||
const full = ed25519KeypairFromSeed(seed);
|
||||
|
||||
return {
|
||||
publicKey: full.slice(32),
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import ed25519 from '@polkadot/wasm-dalek-ed25519';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { naclSign, naclKeypairFromSeed } from '.';
|
||||
|
||||
describe('naclSign', () => {
|
||||
beforeEach(async () => {
|
||||
await ed25519.waitReady();
|
||||
await waitReady();
|
||||
});
|
||||
|
||||
it('returns a valid signature for the message', () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Keypair } from '../types';
|
||||
|
||||
import nacl from 'tweetnacl';
|
||||
import { assert } from '@polkadot/util';
|
||||
import { isReady, sign } from '@polkadot/wasm-dalek-ed25519';
|
||||
import { isReady, ed25519Sign } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
* @name naclSign
|
||||
@@ -26,6 +26,6 @@ export default function naclSign (message: Uint8Array, { publicKey, secretKey }:
|
||||
assert(secretKey, 'Expected valid secretKey');
|
||||
|
||||
return isReady()
|
||||
? sign(publicKey as Uint8Array, (secretKey as Uint8Array).subarray(0, 32), message)
|
||||
? ed25519Sign(publicKey as Uint8Array, (secretKey as Uint8Array).subarray(0, 32), message)
|
||||
: nacl.sign.detached(message, secretKey as Uint8Array);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import ed25519 from '@polkadot/wasm-dalek-ed25519';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { naclVerify, naclKeypairFromSeed } from '.';
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('naclSign', () => {
|
||||
let signature: Uint8Array;
|
||||
|
||||
beforeEach(async () => {
|
||||
await ed25519.waitReady();
|
||||
await waitReady();
|
||||
|
||||
publicKey = naclKeypairFromSeed(
|
||||
stringToU8a('12345678901234567890123456789012')
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import nacl from 'tweetnacl';
|
||||
import { isReady, verify } from '@polkadot/wasm-dalek-ed25519';
|
||||
import { isReady, ed25519Verify } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
* @name naclSign
|
||||
@@ -21,6 +21,6 @@ import { isReady, verify } from '@polkadot/wasm-dalek-ed25519';
|
||||
*/
|
||||
export default function naclVerify (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean {
|
||||
return isReady()
|
||||
? verify(signature, message, publicKey)
|
||||
? ed25519Verify(signature, message, publicKey)
|
||||
: nacl.sign.detached.verify(message, signature, publicKey);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import { Keypair } from '../types';
|
||||
|
||||
import '../polyfill';
|
||||
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { sr25519DeriveKeypairHard } from '@polkadot/wasm-crypto';
|
||||
|
||||
import keypairFromU8a from './keypair/fromU8a';
|
||||
import keypairToU8a from './keypair/toU8a';
|
||||
|
||||
export default function deriveHard (keypair: Keypair, chainCode: Uint8Array): Keypair {
|
||||
return keypairFromU8a(
|
||||
schnorrkel.deriveKeypairHard(keypairToU8a(keypair), chainCode)
|
||||
sr25519DeriveKeypairHard(keypairToU8a(keypair), chainCode)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import { Keypair } from '../types';
|
||||
|
||||
import '../polyfill';
|
||||
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { sr25519DeriveKeypairSoft } from '@polkadot/wasm-crypto';
|
||||
|
||||
import keypairFromU8a from './keypair/fromU8a';
|
||||
import keypairToU8a from './keypair/toU8a';
|
||||
|
||||
export default function deriveSoft (keypair: Keypair, chainCode: Uint8Array): Keypair {
|
||||
return keypairFromU8a(
|
||||
schnorrkel.deriveKeypairSoft(keypairToU8a(keypair), chainCode)
|
||||
sr25519DeriveKeypairSoft(keypairToU8a(keypair), chainCode)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a, u8aToHex } from '@polkadot/util';
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { mnemonicToMiniSecret } from '../../mnemonic';
|
||||
import { schnorrkelKeypairFromSeed } from '..';
|
||||
@@ -17,7 +17,7 @@ describe('schnorrkelKeypairFromSeed', () => {
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
return schnorrkel.waitReady();
|
||||
return waitReady();
|
||||
});
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (u8a)', () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Keypair } from '../../types';
|
||||
|
||||
import '../../polyfill';
|
||||
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { sr25519KeypairFromSeed } from '@polkadot/wasm-crypto';
|
||||
|
||||
import keypairFromU8a from './fromU8a';
|
||||
|
||||
@@ -16,6 +16,6 @@ import keypairFromU8a from './fromU8a';
|
||||
*/
|
||||
export default function schnorrkelKeypairFromSeed (seed: Uint8Array): Keypair {
|
||||
return keypairFromU8a(
|
||||
schnorrkel.keypairFromSeed(seed)
|
||||
sr25519KeypairFromSeed(seed)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Keypair } from '../types';
|
||||
import '../polyfill';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { sr25519Sign } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
* @name schnorrkelSign
|
||||
@@ -17,5 +17,5 @@ export default function schnorrkelSign (message: Uint8Array, { publicKey, secret
|
||||
assert(publicKey && publicKey.length === 32, 'Expected valid publicKey, 32-bytes');
|
||||
assert(secretKey && secretKey.length === 64, 'Expected valid secretKey, 64-bytes');
|
||||
|
||||
return schnorrkel.sign(publicKey as Uint8Array, secretKey as Uint8Array, message);
|
||||
return sr25519Sign(publicKey as Uint8Array, secretKey as Uint8Array, message);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import randomAsU8a from '../random/asU8a';
|
||||
import pairFromSeed from './keypair/fromSeed';
|
||||
@@ -14,7 +14,7 @@ const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
describe('sign and verify', () => {
|
||||
beforeEach(async () => {
|
||||
return schnorrkel.waitReady();
|
||||
return waitReady();
|
||||
});
|
||||
|
||||
it('has 64-byte signatures', () => {
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
import '../polyfill';
|
||||
|
||||
import schnorrkel from '@polkadot/wasm-schnorrkel';
|
||||
import { sr25519Verify } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
* @name schnorrkelVerify
|
||||
* @description Verifies the signature of `message`, using the supplied pair
|
||||
*/
|
||||
export default function schnorrkelVerify (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean {
|
||||
return schnorrkel.verify(signature, message, publicKey);
|
||||
return sr25519Verify(signature, message, publicKey);
|
||||
}
|
||||
|
||||
@@ -1543,10 +1543,10 @@
|
||||
universal-user-agent "^2.0.0"
|
||||
url-template "^2.0.8"
|
||||
|
||||
"@polkadot/dev@^0.28.1":
|
||||
version "0.28.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.28.1.tgz#c9b53a5948252c4f11686a13cd5990d84687f9a6"
|
||||
integrity sha512-x2Yh/KFaTfiQNOs2A1cBJyZRAA5sk/hKerghfj2BubnWm9M+Qx112aoApKUL+s0KMOyKU3ZQjiGSuGyGn6TtqA==
|
||||
"@polkadot/dev@^0.29.0-beta.0":
|
||||
version "0.29.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.29.0-beta.0.tgz#ec4296b7365b1fb2c788cf78ea2ed97d1631b9e1"
|
||||
integrity sha512-kKhTshLED1XvpecJ3ECBQARFAmRRw3xPxvHvV5+EaPZvN0XTGn7DRi3QfP9IugAsDbT5kVWLokojkBgjgiFstg==
|
||||
dependencies:
|
||||
"@babel/cli" "^7.2.3"
|
||||
"@babel/core" "^7.4.0"
|
||||
@@ -1584,20 +1584,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.56.tgz#ffd6e9c95704a7fb90b918193b9dc5c440114b27"
|
||||
integrity sha512-wnt4zXxZXyz6WaubTO/I+nUElwV2DogFzdl6CrKfVn2PTWp8uHN06W9s40FH57ORtmQfDr9rLRP8Nq+oIyElbg==
|
||||
|
||||
"@polkadot/wasm-crypto@^0.6.1":
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-0.6.1.tgz#34e14cf6946060e50bc6f423afa6a11b8eadec4e"
|
||||
integrity sha512-Qpyzu4EQEKgO6S1sAxuVsqB10OoP3mi7QIygR68g/IregfzrFgz1lOEBoG3RJPhDZf4tNwNNIta7orm4GHAs4Q==
|
||||
|
||||
"@polkadot/wasm-dalek-ed25519@^0.6.1":
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/wasm-dalek-ed25519/-/wasm-dalek-ed25519-0.6.1.tgz#59f385ae55c080c88851b8d6399a26e7c5e3949b"
|
||||
integrity sha512-rJuHLJeQGVxOm1BlG8nmeNGVA+rOjZCQE0rKzEdZyFHO8huoSpLyKo96nLyOhbE/xb2FMVj7Kk1vSHe2e8MenA==
|
||||
|
||||
"@polkadot/wasm-schnorrkel@^0.6.1":
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/wasm-schnorrkel/-/wasm-schnorrkel-0.6.1.tgz#68d0cebd063fd5294ba5757f167c814613344310"
|
||||
integrity sha512-XlDPqKqFGYLwkd4FjjaDgvrQCrTfUfIMski6+LNyRwbpsIHhkGoEWXE/byIsB6FTcHBUDpXq9ZFdaddmXfV8pg==
|
||||
"@polkadot/wasm-crypto@^0.8.0-beta.0":
|
||||
version "0.8.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-0.8.0-beta.0.tgz#52f7dae87f55a9232273dbedb97c0557689d0fab"
|
||||
integrity sha512-eFZaC5AV0XKsTTKx8xnTIOGOgyVLwZSjNRNhRcYMPAhADqmhp7PCNcqRGoT39XyKgAka9Mx8IsbbaLLDArdVWQ==
|
||||
|
||||
"@types/babel__core@^7.1.0":
|
||||
version "7.1.0"
|
||||
|
||||
Reference in New Issue
Block a user