3.2 (#663)
This commit is contained in:
+3
-1
@@ -1,9 +1,11 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 3.2.0-beta.x
|
||||
## 3.2.1 Aug 17, 2020
|
||||
|
||||
- Allow for (optional, default blake2) hasher to secp256k1 sign/verify functions
|
||||
- Utilities for secp256k1 publicKey expansion and compression
|
||||
- Add basic Ethereum address utils (encode with checksum & checksum verification)
|
||||
- Add Ethereum-compatible `mnemonicToBip39` seed creation function
|
||||
|
||||
## 3.1.1 Aug 10, 2020
|
||||
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "3.2.0-beta.4"
|
||||
"version": "3.2.0"
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,5 +26,5 @@
|
||||
"@polkadot/ts": "^0.3.38",
|
||||
"@types/jest": "^26.0.9"
|
||||
},
|
||||
"version": "3.2.0-beta.4"
|
||||
"version": "3.2.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/keyring",
|
||||
"version": "3.2.0-beta.4",
|
||||
"version": "3.2.0",
|
||||
"description": "Keyring management",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
@@ -28,7 +28,7 @@
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/util": "3.2.0-beta.4",
|
||||
"@polkadot/util-crypto": "3.2.0-beta.4"
|
||||
"@polkadot/util": "3.2.0",
|
||||
"@polkadot/util-crypto": "3.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import Pairs from './pairs';
|
||||
const keypairFromSeed = {
|
||||
ecdsa: (seed: Uint8Array): Keypair => secp256k1FromSeed(seed),
|
||||
ed25519: (seed: Uint8Array): Keypair => naclFromSeed(seed),
|
||||
// FIXME This is not Ethereum-compatible
|
||||
ethereum: (seed: Uint8Array): Keypair => secp256k1FromSeed(seed),
|
||||
sr25519: (seed: Uint8Array): Keypair => schnorrkelFromSeed(seed)
|
||||
};
|
||||
|
||||
@@ -19,59 +19,60 @@ interface Setup {
|
||||
}
|
||||
|
||||
const SIG_TYPE_NONE = new Uint8Array();
|
||||
const SIG_TYPE_ED25519 = new Uint8Array([0]);
|
||||
const SIG_TYPE_SR25519 = new Uint8Array([1]);
|
||||
const SIG_TYPE_ECDSA = new Uint8Array([2]);
|
||||
const SIG_TYPE_ETHEREUM = SIG_TYPE_ECDSA;
|
||||
|
||||
const TYPE_FROM_SEED = {
|
||||
ecdsa: secp256k1FromSeed,
|
||||
ed25519: naclFromSeed,
|
||||
ethereum: secp256k1FromSeed,
|
||||
sr25519: schnorrkelFromSeed
|
||||
};
|
||||
|
||||
const TYPE_PREFIX = {
|
||||
ecdsa: new Uint8Array([2]),
|
||||
ed25519: new Uint8Array([0]),
|
||||
ethereum: new Uint8Array([2]),
|
||||
sr25519: new Uint8Array([1])
|
||||
};
|
||||
|
||||
const TYPE_SIGNATURE = {
|
||||
ecdsa: (message: Uint8Array, pair: Partial<Keypair>) =>
|
||||
secp256k1Sign(message, pair, 'blake2'),
|
||||
ed25519: naclSign,
|
||||
ethereum: (message: Uint8Array, pair: Partial<Keypair>) =>
|
||||
secp256k1Sign(message, pair, 'keccak'),
|
||||
sr25519: schnorrkelSign
|
||||
};
|
||||
|
||||
const TYPE_VERIFY = {
|
||||
ecdsa: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) =>
|
||||
secp256k1Verify(message, signature, blake2AsU8a(publicKey), 'blake2'),
|
||||
ed25519: naclVerify,
|
||||
ethereum: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) =>
|
||||
secp256k1Verify(message, signature, keccakAsU8a(publicKey), 'keccak'),
|
||||
sr25519: schnorrkelVerify
|
||||
};
|
||||
|
||||
function isEmpty (u8a: Uint8Array): boolean {
|
||||
return u8a.reduce((count, u8): number => count + u8, 0) === 0;
|
||||
}
|
||||
|
||||
function fromSeed (type: KeypairType, seed: Uint8Array): Keypair {
|
||||
return {
|
||||
ecdsa: (): Keypair => secp256k1FromSeed(seed),
|
||||
ed25519: (): Keypair => naclFromSeed(seed),
|
||||
// FIXME This needs to actually be Ethereum-compatible
|
||||
ethereum: (): Keypair => secp256k1FromSeed(seed),
|
||||
sr25519: (): Keypair => schnorrkelFromSeed(seed)
|
||||
}[type]();
|
||||
}
|
||||
|
||||
function multiSignaturePrefix (type: KeypairType): Uint8Array {
|
||||
return {
|
||||
ecdsa: SIG_TYPE_ECDSA,
|
||||
ed25519: SIG_TYPE_ED25519,
|
||||
ethereum: SIG_TYPE_ETHEREUM,
|
||||
sr25519: SIG_TYPE_SR25519
|
||||
}[type];
|
||||
return TYPE_FROM_SEED[type](seed);
|
||||
}
|
||||
|
||||
function sign (type: KeypairType, message: Uint8Array, pair: Partial<Keypair>, { withType = false }: SignOptions = {}): Uint8Array {
|
||||
const signature = {
|
||||
ecdsa: (): Uint8Array => secp256k1Sign(message, pair, 'blake2'),
|
||||
ed25519: (): Uint8Array => naclSign(message, pair),
|
||||
ethereum: (): Uint8Array => secp256k1Sign(message, pair, 'keccak'),
|
||||
sr25519: (): Uint8Array => schnorrkelSign(message, pair)
|
||||
}[type]();
|
||||
|
||||
return u8aConcat(
|
||||
// for multi-signatures, i.e. with indicator, append the signature type as per
|
||||
// the MultiSignature enum
|
||||
withType
|
||||
? multiSignaturePrefix(type)
|
||||
? TYPE_PREFIX[type]
|
||||
: SIG_TYPE_NONE,
|
||||
signature
|
||||
TYPE_SIGNATURE[type](message, pair)
|
||||
);
|
||||
}
|
||||
|
||||
function verify (type: KeypairType, message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean {
|
||||
return {
|
||||
ecdsa: (): boolean => secp256k1Verify(message, signature, blake2AsU8a(publicKey), 'blake2'),
|
||||
ed25519: (): boolean => naclVerify(message, signature, publicKey),
|
||||
ethereum: (): boolean => secp256k1Verify(message, signature, keccakAsU8a(publicKey), 'keccak'),
|
||||
sr25519: (): boolean => schnorrkelVerify(message, signature, publicKey)
|
||||
}[type]();
|
||||
return TYPE_VERIFY[type](message, signature, publicKey);
|
||||
}
|
||||
|
||||
function getAddress (type: KeypairType, publicKey: Uint8Array, isCompressed = false): Uint8Array {
|
||||
@@ -171,7 +172,7 @@ export default function createPair ({ toSS58, type }: Setup, { publicKey, secret
|
||||
encodePkcs8: (passphrase?: string): Uint8Array =>
|
||||
recode(passphrase),
|
||||
lock: (): void => {
|
||||
secretKey = new Uint8Array(0);
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional: KeyringPair$Meta): void => {
|
||||
meta = { ...meta, ...additional };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-crypto",
|
||||
"version": "3.2.0-beta.4",
|
||||
"version": "3.2.0",
|
||||
"description": "A collection of useful crypto utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,7 +26,7 @@
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/util": "3.2.0-beta.4",
|
||||
"@polkadot/util": "3.2.0",
|
||||
"@polkadot/wasm-crypto": "^1.3.1",
|
||||
"base-x": "^3.0.8",
|
||||
"bip39": "^3.0.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util",
|
||||
"version": "3.2.0-beta.4",
|
||||
"version": "3.2.0",
|
||||
"description": "A collection of useful utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
|
||||
@@ -2829,8 +2829,8 @@ __metadata:
|
||||
resolution: "@polkadot/keyring@workspace:packages/keyring"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/util": 3.2.0-beta.4
|
||||
"@polkadot/util-crypto": 3.2.0-beta.4
|
||||
"@polkadot/util": 3.2.0
|
||||
"@polkadot/util-crypto": 3.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -2843,12 +2843,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/util-crypto@3.2.0-beta.4, @polkadot/util-crypto@workspace:packages/util-crypto":
|
||||
"@polkadot/util-crypto@3.2.0, @polkadot/util-crypto@workspace:packages/util-crypto":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/util-crypto@workspace:packages/util-crypto"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.11.2
|
||||
"@polkadot/util": 3.2.0-beta.4
|
||||
"@polkadot/util": 3.2.0
|
||||
"@polkadot/wasm-crypto": ^1.3.1
|
||||
"@types/bn.js": ^4.11.6
|
||||
"@types/elliptic": ^6.4.12
|
||||
@@ -2868,7 +2868,7 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util@3.2.0-beta.4, @polkadot/util@workspace:packages/util":
|
||||
"@polkadot/util@3.2.0, @polkadot/util@workspace:packages/util":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/util@workspace:packages/util"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user