Compare commits

..
14 Commits
Author SHA1 Message Date
Github Actions cc4a579905 [CI Skip] release/stable 5.7.1
skip-checks: true
2021-02-21 08:13:58 +00:00
Jaco Greeff 450b7b8e8b 5.7 (#885)
* 5.7

* Update CHANGELOG.md
2021-02-21 09:08:07 +01:00
Github Actions a248bc9f96 [CI Skip] release/beta 5.6.4-1
skip-checks: true
2021-02-20 10:56:44 +00:00
Jaco Greeff 35f677f2e9 Additional substrate test vectors for ss58 (#884) 2021-02-20 11:50:56 +01:00
Github Actions fccba5d93d [CI Skip] release/beta 5.6.4-0
skip-checks: true
2021-02-19 09:48:00 +00:00
Jaco Greeff ae172e2c53 Pass publicKey through on verify (#883)
* Pass publicKey through on verify

* Some test fixes

* Adjust tests

* Explicit public

* Additional failing tests
2021-02-19 10:43:19 +01:00
Github Actions aa9bf0780b [CI Skip] release/stable 5.6.3
skip-checks: true
2021-02-16 11:22:45 +00:00
Jaco Greeff 11f1d8057b 5.6.3 (#882) 2021-02-16 12:17:13 +01:00
Github Actions e2f1e7c033 [CI Skip] release/beta 5.6.3-2
skip-checks: true
2021-02-10 07:22:11 +00:00
Jaco Greeff bb213425f8 Align 2258 with master registry (#879) 2021-02-10 08:16:27 +01:00
Github Actions 162596ed93 [CI Skip] release/beta 5.6.3-1
skip-checks: true
2021-02-10 06:51:55 +00:00
nahuseyoumandJaco Greeff aa3ba246a7 Reserving 65 for Aventus based on the new extended range (#871)
* Reserving 46 based on the new extended range

* Update index.ts

* Updating to match new prefix

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2021-02-10 07:45:53 +01:00
Github Actions baf65438fe [CI Skip] release/beta 5.6.3-0
skip-checks: true
2021-02-09 16:42:03 +00:00
Jaco Greeff 8b443dfa4b Add pair.unlock as equivalent to pair.lock (#877) 2021-02-09 17:35:59 +01:00
45 changed files with 597 additions and 369 deletions
+2 -1
View File
@@ -8,4 +8,5 @@
5.4.3
5.4.4
5.5.2
5.6.2
5.6.2
5.6.3
+24
View File
@@ -1,5 +1,29 @@
# CHANGELOG
## 5.7.1 Feb 21, 2021
**Breaking change** The signature of `pair.verify` now requires the signer public key as a parameter. If using `pair.verify` pass the publicKey (hex or Uint8Array) of the signer.
Changes:
- The signature on the keyring for `.verify` now explicitly requires the `publicKey` of the signer. Previously it only verified against an own public key.
- Add additional ss58 test vectors (against chains with >63 prefixes in the Substrate registry)
## 5.6.3 Feb 16, 2021
Contributed:
- Add ss58 information for Aventus (Thanks to https://github.com/nahuseyoum)
Changes:
- Add `unlock(password)` to keypair (less confusing than only having `decodePkcs8`, equivalent to `lock()`)
- Change use of `detectPackage` to use `packageInfo.ts`
- Align with upstream ss58 registry
- `@polkadot/wasm-crypto` 3.2.3
## 5.6.2 Feb 8, 2021
Changes:
+4 -4
View File
@@ -7,7 +7,7 @@
"packages/*"
],
"resolutions": {
"typescript": "^4.1.3"
"typescript": "^4.1.5"
},
"scripts": {
"build": "polkadot-dev-build-ts",
@@ -20,10 +20,10 @@
"test:one": "polkadot-dev-run-test"
},
"devDependencies": {
"@babel/core": "^7.12.13",
"@polkadot/dev": "^0.61.25",
"@babel/core": "^7.12.16",
"@polkadot/dev": "^0.61.26",
"@polkadot/ts": "^0.3.59",
"@types/jest": "^26.0.20"
},
"version": "5.6.2"
"version": "5.7.1"
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/hw-ledger-transports",
"version": "5.6.2",
"version": "5.7.1",
"repository": "github:polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
@@ -12,13 +12,13 @@
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.12.13",
"@ledgerhq/hw-transport-webusb": "^5.41.0"
"@ledgerhq/hw-transport-webusb": "^5.43.0"
},
"devDependencies": {
"@types/ledgerhq__hw-transport-node-hid": "^4.22.2",
"@types/ledgerhq__hw-transport-webusb": "^4.70.1"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-hid-singleton": "^5.41.0"
"@ledgerhq/hw-transport-node-hid-singleton": "^5.43.0"
}
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '5.7.1' };
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/hw-ledger",
"version": "5.6.2",
"version": "5.7.1",
"repository": "github:polkadot-js/common",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
@@ -10,8 +10,8 @@
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/hw-ledger-transports": "5.6.2",
"@polkadot/util": "^5.6.2",
"@zondax/ledger-polkadot": "^0.13.0"
"@polkadot/hw-ledger-transports": "5.7.1",
"@polkadot/util": "^5.7.1",
"@zondax/ledger-polkadot": "^0.13.1"
}
}
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/hw-ledger', version: '5.7.1' };
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/keyring",
"version": "5.6.2",
"version": "5.7.1",
"description": "Keyring management",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
@@ -16,11 +16,11 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/util": "5.6.2",
"@polkadot/util-crypto": "5.6.2"
"@polkadot/util": "5.7.1",
"@polkadot/util-crypto": "5.7.1"
},
"peerDependencies": {
"@polkadot/util": "5.6.2",
"@polkadot/util-crypto": "5.6.2"
"@polkadot/util": "5.7.1",
"@polkadot/util-crypto": "5.7.1"
}
}
+1 -1
View File
@@ -18,7 +18,7 @@
import { detectPackage } from '@polkadot/util';
import packageInfo from './package-info.json';
import { packageInfo } from './packageInfo';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
+31 -17
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { hexToU8a, stringToU8a } from '@polkadot/util';
import { cryptoWaitReady, encodeAddress, setSS58Format } from '@polkadot/util-crypto';
import { cryptoWaitReady, encodeAddress, randomAsU8a, setSS58Format } from '@polkadot/util-crypto';
import Keyring from '.';
@@ -83,8 +83,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(publicKeyOne);
const signature = pair.sign(MESSAGE);
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
it('signs and verifies (withType)', (): void => {
@@ -92,8 +93,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(publicKeyOne);
const signature = pair.sign(MESSAGE, { withType: true });
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
});
@@ -159,8 +161,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(publicKeyOne);
const signature = pair.sign(MESSAGE);
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
it('signs and verifies (withType)', (): void => {
@@ -168,8 +171,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(publicKeyOne);
const signature = pair.sign(MESSAGE, { withType: true });
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
});
@@ -264,8 +268,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(addressKeyOne);
const signature = pair.sign(MESSAGE);
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
it('signs and verifies (withType)', (): void => {
@@ -273,8 +278,9 @@ describe('keypair', (): void => {
const pair = keyring.getPair(addressKeyOne);
const signature = pair.sign(MESSAGE, { withType: true });
expect(pair.verify(MESSAGE, signature)).toBe(true);
expect(pair.verify(new Uint8Array(), signature)).toBe(false);
expect(pair.verify(MESSAGE, signature, pair.publicKey)).toBe(true);
expect(pair.verify(MESSAGE, signature, randomAsU8a())).toBe(false);
expect(pair.verify(new Uint8Array(), signature, pair.publicKey)).toBe(false);
});
});
@@ -328,9 +334,13 @@ describe('keypair', (): void => {
);
const signature = signer.sign(MESSAGE);
const dummyPublic = verifier.publicKey.slice();
expect(verifier.verify(MESSAGE, signature)).toBe(true);
expect(verifier.verify(new Uint8Array(), signature)).toBe(false);
dummyPublic[dummyPublic.length - 1] = 0;
expect(verifier.verify(MESSAGE, signature, signer.publicKey)).toBe(true);
expect(verifier.verify(MESSAGE, signature, dummyPublic)).toBe(false);
expect(verifier.verify(new Uint8Array(), signature, signer.publicKey)).toBe(false);
});
it('allows for signing/verification (withType)', (): void => {
@@ -341,9 +351,13 @@ describe('keypair', (): void => {
);
const signature = signer.sign(MESSAGE, { withType: true });
const dummyPublic = verifier.publicKey.slice();
expect(verifier.verify(MESSAGE, signature)).toBe(true);
expect(verifier.verify(new Uint8Array(), signature)).toBe(false);
dummyPublic[dummyPublic.length - 1] = 0;
expect(verifier.verify(MESSAGE, signature, signer.publicKey)).toBe(true);
expect(verifier.verify(MESSAGE, signature, dummyPublic)).toBe(false);
expect(verifier.verify(new Uint8Array(), signature, signer.publicKey)).toBe(false);
});
});
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/keyring', version: '5.7.1' };
+28 -3
View File
@@ -42,16 +42,28 @@ describe('pair', (): void => {
expect(
keyring.alice.verify(
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
SIGNATURE
SIGNATURE,
keyring.alice.publicKey
)
).toEqual(true);
});
it('fails a correctly signed message (signer changed)', (): void => {
expect(
keyring.alice.verify(
new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]),
SIGNATURE,
keyring.bob.publicKey
)
).toEqual(false);
});
it('fails a correctly signed message (message changed)', (): void => {
expect(
keyring.alice.verify(
new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]),
SIGNATURE
SIGNATURE,
keyring.alice.publicKey
)
).toEqual(false);
});
@@ -62,11 +74,24 @@ describe('pair', (): void => {
expect(
keyring.alice.vrfVerify(
message,
keyring.alice.vrfSign(message)
keyring.alice.vrfSign(message),
keyring.alice.publicKey
)
).toBe(true);
});
it('fails vrf sign and verify (publicKey changed)', (): void => {
const message = new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]);
expect(
keyring.alice.vrfVerify(
message,
keyring.alice.vrfSign(message),
keyring.bob.publicKey
)
).toBe(false);
});
it('allows setting/getting of meta', (): void => {
keyring.bob.setMeta({ foo: 'bar', something: 'else' });
+15 -9
View File
@@ -178,8 +178,11 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
},
verify: (message: string | Uint8Array, signature: Uint8Array): boolean => {
return signatureVerify(message, signature, TYPE_ADDRESS[type](publicKey)).isValid;
unlock: (passphrase?: string): void => {
return decodePkcs8(passphrase);
},
verify: (message: string | Uint8Array, signature: Uint8Array, _signerPublic: string | Uint8Array): boolean => {
return signatureVerify(message, signature, TYPE_ADDRESS[type](u8aToU8a(_signerPublic))).isValid;
},
vrfSign: (message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array => {
assert(!isLocked(secretKey), 'Cannot sign with a locked key pair');
@@ -192,13 +195,16 @@ export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: P
return u8aConcat(vrfHash(proof, context, extra), proof);
},
vrfVerify: (message: string | Uint8Array, vrfResult: Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean => {
return type === 'sr25519'
? schnorrkelVrfVerify(message, vrfResult, publicKey, context, extra)
: (
signatureVerify(message, u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](publicKey)).isValid &&
u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra))
);
vrfVerify: (message: string | Uint8Array, vrfResult: Uint8Array, _signerPublic: Uint8Array | string, context?: string | Uint8Array, extra?: string | Uint8Array): boolean => {
const signerPublic = TYPE_ADDRESS[type](u8aToU8a(_signerPublic));
if (type === 'sr25519') {
return schnorrkelVrfVerify(message, vrfResult, publicKey, context, extra);
}
const result = signatureVerify(message, u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), signerPublic);
return result.isValid && u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
}
};
}
+3
View File
@@ -52,6 +52,9 @@ export function nobody (): KeyringPair {
json,
type: 'ed25519',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
unlock: (passphrase?: string): void =>
undefined,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
verify: (message: Uint8Array, signature: Uint8Array): boolean =>
false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
+6 -6
View File
@@ -29,8 +29,8 @@ describe('vrf', (): void => {
const sig2 = ecdsa.vrfSign(MESSAGE, CONTEXT);
expect(u8aToHex(sig1)).toEqual(u8aToHex(sig2));
expect(ecdsa.vrfVerify(MESSAGE, sig1, CONTEXT)).toEqual(true);
expect(ecdsa.vrfVerify(MESSAGE, sig2, CONTEXT)).toEqual(true);
expect(ecdsa.vrfVerify(MESSAGE, sig1, ecdsa.publicKey, CONTEXT)).toEqual(true);
expect(ecdsa.vrfVerify(MESSAGE, sig2, ecdsa.publicKey, CONTEXT)).toEqual(true);
});
it('has deterministic signature values for ed25519', (): void => {
@@ -38,8 +38,8 @@ describe('vrf', (): void => {
const sig2 = ed25519.vrfSign(MESSAGE, CONTEXT);
expect(u8aToHex(sig1)).toEqual(u8aToHex(sig2));
expect(ed25519.vrfVerify(MESSAGE, sig1, CONTEXT)).toEqual(true);
expect(ed25519.vrfVerify(MESSAGE, sig2, CONTEXT)).toEqual(true);
expect(ed25519.vrfVerify(MESSAGE, sig1, ed25519.publicKey, CONTEXT)).toEqual(true);
expect(ed25519.vrfVerify(MESSAGE, sig2, ed25519.publicKey, CONTEXT)).toEqual(true);
});
it('has deterministic signature values for sr25519', (): void => {
@@ -47,7 +47,7 @@ describe('vrf', (): void => {
const sig2 = sr25519.vrfSign(MESSAGE, CONTEXT);
expect(u8aToHex(sig1.slice(0, 32))).toEqual(u8aToHex(sig2.slice(0, 32)));
expect(sr25519.vrfVerify(MESSAGE, sig1, CONTEXT)).toEqual(true);
expect(sr25519.vrfVerify(MESSAGE, sig2, CONTEXT)).toEqual(true);
expect(sr25519.vrfVerify(MESSAGE, sig1, sr25519.publicKey, CONTEXT)).toEqual(true);
expect(sr25519.vrfVerify(MESSAGE, sig2, sr25519.publicKey, CONTEXT)).toEqual(true);
});
});
+8 -7
View File
@@ -40,16 +40,17 @@ export interface KeyringPair {
readonly publicKey: Uint8Array;
readonly type: KeypairType;
decodePkcs8: (passphrase?: string, encoded?: Uint8Array) => void;
derive: (suri: string, meta?: KeyringPair$Meta) => KeyringPair;
encodePkcs8: (passphrase?: string) => Uint8Array;
lock: () => void;
setMeta: (meta: KeyringPair$Meta) => void;
decodePkcs8 (passphrase?: string, encoded?: Uint8Array): void;
derive (suri: string, meta?: KeyringPair$Meta): KeyringPair;
encodePkcs8 (passphrase?: string): Uint8Array;
lock (): void;
setMeta (meta: KeyringPair$Meta): void;
sign (message: string | Uint8Array, options?: SignOptions): Uint8Array;
toJson (passphrase?: string): KeyringPair$Json;
verify (message: string | Uint8Array, signature: Uint8Array): boolean;
unlock (passphrase?: string): void;
verify (message: string | Uint8Array, signature: Uint8Array, signerPublic: string | Uint8Array): boolean;
vrfSign (message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array;
vrfVerify (message: string | Uint8Array, vrfResult: Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
vrfVerify (message: string | Uint8Array, vrfResult: Uint8Array, signerPublic: Uint8Array | string, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
}
export interface KeyringPairs {
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/networks",
"version": "5.6.2",
"version": "5.7.1",
"description": "A list of all available Substrate networks and their applicable prefixes",
"main": "index.js",
"sideEffects": false,
@@ -15,7 +15,7 @@
"@babel/runtime": "^7.12.13"
},
"devDependencies": {
"@polkadot/util": "5.6.2",
"@polkadot/x-fetch": "5.6.2"
"@polkadot/util": "5.7.1",
"@polkadot/x-fetch": "5.7.1"
}
}
+28 -1
View File
@@ -344,6 +344,15 @@ const all: NetworkFromSubstrate[] = [
symbols: null,
website: null
},
{
decimals: [12],
displayName: 'Ares Protocol',
network: 'ares',
prefix: 34,
standardAccount: '*25519',
symbols: ['ARES'],
website: 'https://www.aresprotocol.com/'
},
{
decimals: [15],
displayName: 'Valiu Liquidity Network',
@@ -437,7 +446,25 @@ const all: NetworkFromSubstrate[] = [
website: 'https://uniarts.me'
},
createReserved(46, 'This prefix is reserved.', 'reserved46'),
createReserved(47, 'This prefix is reserved.', 'reserved47')
createReserved(47, 'This prefix is reserved.', 'reserved47'),
{
decimals: [18],
displayName: 'AvN Mainnet',
network: 'aventus',
prefix: 65,
standardAccount: '*25519',
symbols: ['AVT'],
website: 'https://aventus.io'
},
{
decimals: [12],
displayName: 'Crust Network',
network: 'crust',
prefix: 66,
standardAccount: '*25519',
symbols: ['CRU'],
website: 'https://crust.network'
}
];
// The list of available/claimed prefixes
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/networks', version: '5.7.1' };
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util-crypto",
"version": "5.6.2",
"version": "5.7.1",
"description": "A collection of useful crypto utilities for @polkadot",
"main": "index.js",
"sideEffects": [
@@ -16,10 +16,10 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/networks": "5.6.2",
"@polkadot/util": "5.6.2",
"@polkadot/wasm-crypto": "^3.2.2",
"@polkadot/x-randomvalues": "5.6.2",
"@polkadot/networks": "5.7.1",
"@polkadot/util": "5.7.1",
"@polkadot/wasm-crypto": "^3.2.3",
"@polkadot/x-randomvalues": "5.7.1",
"base-x": "^3.0.8",
"blakejs": "^1.1.0",
"bn.js": "^4.11.9",
@@ -39,6 +39,6 @@
"@types/xxhashjs": "^0.2.2"
},
"peerDependencies": {
"@polkadot/util": "5.6.2"
"@polkadot/util": "5.7.1"
}
}
@@ -11,7 +11,13 @@ describe('checkAddressChecksum', (): void => {
).toEqual([true, 33, 1, 2]);
});
it('correctly extracts the info from a 2-byte-prefix address', (): void => {
it('correctly extracts the info from a 2-byte-prefix address (66)', (): void => {
expect(
checkAddressChecksum(base58Decode('cTGShekJ1L1UKFZR9xmv9UTJod7vqjFAPo4sDhXih2c3y1yLS'))
).toEqual([true, 34, 2, 66]);
});
it('correctly extracts the info from a 2-byte-prefix address (255)', (): void => {
expect(
checkAddressChecksum(base58Decode('yGHU8YKprxHbHdEv7oUK4rzMZXtsdhcXVG2CAMyC9WhzhjH2k'))
).toEqual([true, 34, 2, 255]);
@@ -81,7 +81,15 @@ describe('decodeAddress', (): void => {
);
});
it('decodes a 2-byte prefix', (): void => {
it('decodes a 2-byte prefix (65)', (): void => {
expect(
decodeAddress('cLtA6nCDyvwKcEHH4QkZDSHMhS9s78BvUJUsKUbUAn1Jc2SCF')
).toEqual(
hexToU8a('0x08e8969768fc14399930d4b8d693f68a2ff6c6a597325d6946095e5e9d9d1b0e')
);
});
it('decodes a 2-byte prefix (255)', (): void => {
expect(
decodeAddress('yGHU8YKprxHbHdEv7oUK4rzMZXtsdhcXVG2CAMyC9WhzhjH2k')
).toEqual(
@@ -9,10 +9,23 @@ const keyring = createTestPairs({ type: 'ed25519' }, false);
const SUBKEY = [
{
// substrate default
address: '5DA4D4GL5iakrn22h5uKoevgvo18Pqj5BcdEUv8etEDPdijA',
publicKey: '0x3050f8456519829fe03302da802d22d3233a5f4037b9a3e2bcc403ccfcb2d735',
ss58Format: 42
},
{
// aventus
address: 'cLtA6nCDyvwKcEHH4QkZDSHMhS9s78BvUJUsKUbUAn1Jc2SCF',
publicKey: '0x08e8969768fc14399930d4b8d693f68a2ff6c6a597325d6946095e5e9d9d1b0e',
ss58Format: 65
},
{
// crust
address: 'cTGShekJ1L1UKFZR9xmv9UTJod7vqjFAPo4sDhXih2c3y1yLS',
publicKey: '0x04a047d52fe542484c69bc528990cfeaf3a663dded0638ee1b51cf78bacd1072',
ss58Format: 66
},
{
// ecdsa
address: '4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV',
@@ -121,7 +134,7 @@ describe('encode', (): void => {
});
SUBKEY.forEach(({ address, publicKey, ss58Format }, index): void => {
it(`encodes with Subkey equality (${index})`, (): void => {
it(`encodes with Subkey equality (${index} - ${ss58Format})`, (): void => {
expect(
encodeAddress(publicKey, ss58Format)
).toEqual(address);
+1 -1
View File
@@ -18,7 +18,7 @@
import { detectPackage } from '@polkadot/util';
import packageInfo from './package-info.json';
import { packageInfo } from './packageInfo';
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/util-crypto', version: '5.7.1' };
@@ -36,21 +36,24 @@ describe('signatureVerify', (): void => {
it('verifies an ed25519 signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_ED, ADDR_ED)).toEqual({
crypto: 'ed25519',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_ED)
});
});
it('verifies an ecdsa signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_EC, ADDR_EC)).toEqual({
crypto: 'ecdsa',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_EC)
});
});
it('verifies an ethereum signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_ET, ADDR_ET)).toEqual({
crypto: 'ethereum',
isValid: true
isValid: true,
publicKey: hexToU8a(ADDR_ET)
});
});
@@ -63,35 +66,40 @@ describe('signatureVerify', (): void => {
'0x002309df96687e44280bb72c3818358faeeb699c'
)).toEqual({
crypto: 'ethereum',
isValid: true
isValid: true,
publicKey: hexToU8a('0x002309df96687e44280bb72c3818358faeeb699c')
});
});
it('fails on invalid ethereum signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_EC, ADDR_ET)).toEqual({
crypto: 'none',
isValid: false
isValid: false,
publicKey: hexToU8a(ADDR_ET)
});
});
it('verifies an sr25519 signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_SR, ADDR_SR)).toEqual({
crypto: 'sr25519',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_SR)
});
});
it('allows various inputs', (): void => {
expect(signatureVerify(stringToU8a(MESSAGE), hexToU8a(SIG_ED), decodeAddress(ADDR_ED))).toEqual({
crypto: 'ed25519',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_ED)
});
});
it('fails on an invalid signature', (): void => {
expect(signatureVerify(MESSAGE, SIG_SR, ADDR_ED)).toEqual({
crypto: 'none',
isValid: false
isValid: false,
publicKey: decodeAddress(ADDR_ED)
});
});
});
@@ -100,35 +108,40 @@ describe('signatureVerify', (): void => {
it('verifies an ed25519 signature', (): void => {
expect(signatureVerify(MESSAGE, MUL_ED, ADDR_ED)).toEqual({
crypto: 'ed25519',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_ED)
});
});
it('verifies an ecdsa signature', (): void => {
expect(signatureVerify(MESSAGE, MUL_EC, ADDR_EC)).toEqual({
crypto: 'ecdsa',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_EC)
});
});
it('verifies an ethereum signature', (): void => {
expect(signatureVerify(MESSAGE, MUL_ET, ADDR_ET)).toEqual({
crypto: 'ethereum',
isValid: true
isValid: true,
publicKey: hexToU8a(ADDR_ET)
});
});
it('verifies an sr25519 signature', (): void => {
expect(signatureVerify(MESSAGE, MUL_SR, ADDR_SR)).toEqual({
crypto: 'sr25519',
isValid: true
isValid: true,
publicKey: decodeAddress(ADDR_SR)
});
});
it('fails on an invalid signature', (): void => {
expect(signatureVerify(MESSAGE, MUL_SR, ADDR_ED)).toEqual({
crypto: 'sr25519',
isValid: false
isValid: false,
publicKey: new Uint8Array([61, 12, 55, 211, 0, 211, 97, 199, 4, 37, 17, 213, 81, 175, 166, 23, 251, 199, 144, 210, 19, 83, 186, 1, 196, 231, 14, 156, 171, 46, 141, 146])
});
});
});
+1 -1
View File
@@ -79,9 +79,9 @@ export function signatureVerify (message: Uint8Array | string, signature: Uint8A
assert([64, 65, 66].includes(signatureU8a.length), `Invalid signature length, expected [64..66] bytes, found ${signatureU8a.length}`);
const result: VerifyResult = { crypto: 'none', isValid: false };
const publicKey = decodeAddress(addressOrPublicKey);
const input = { message, publicKey, signature: signatureU8a };
const result: VerifyResult = { crypto: 'none', isValid: false, publicKey };
return [0, 1, 2].includes(signatureU8a[0]) && [65, 66].includes(signatureU8a.length)
? verifyMultisig(result, input)
+1
View File
@@ -16,4 +16,5 @@ export type KeypairType = 'ed25519' | 'sr25519' | 'ecdsa' | 'ethereum';
export interface VerifyResult {
crypto: 'none' | KeypairType;
isValid: boolean;
publicKey: Uint8Array;
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/util",
"version": "5.6.2",
"version": "5.7.1",
"description": "A collection of useful utilities for @polkadot",
"main": "index.js",
"sideEffects": false,
@@ -13,8 +13,8 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-textdecoder": "5.6.2",
"@polkadot/x-textencoder": "5.6.2",
"@polkadot/x-textdecoder": "5.7.1",
"@polkadot/x-textencoder": "5.7.1",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.11.9",
"camelcase": "^5.3.1",
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/util', version: '5.7.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-fetch",
"version": "5.6.2",
"version": "5.7.1",
"description": "A cross-environment fetch replacement",
"browser": "browser.js",
"main": "node.js",
@@ -15,7 +15,7 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-fetch#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-global": "5.6.2",
"@polkadot/x-global": "5.7.1",
"@types/node-fetch": "^2.5.8",
"node-fetch": "^2.6.1"
}
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-fetch', version: '5.7.1' };
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-global",
"version": "5.6.2",
"version": "5.7.1",
"description": "A cross-environment global replacement",
"main": "index.js",
"sideEffects": false,
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-global', version: '5.7.1' };
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-randomvalues",
"version": "5.6.2",
"version": "5.7.1",
"description": "A cross-environment window.crypto.getRandomValues replacement",
"browser": "browser.js",
"main": "node.js",
@@ -15,9 +15,9 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-randomvalues#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-global": "5.6.2"
"@polkadot/x-global": "5.7.1"
},
"devDependencies": {
"@types/react-native": "^0.63.48"
"@types/react-native": "^0.63.49"
}
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-randomvalues', version: '5.7.1' };
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-rxjs",
"version": "5.6.2",
"version": "5.7.1",
"description": "A pass-through interface for RxJs (allowing node + mjs usage)",
"main": "index.js",
"sideEffects": false,
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-rxjs', version: '5.7.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-textdecoder",
"version": "5.6.2",
"version": "5.7.1",
"description": "A TextDecoder replacement",
"browser": "browser.js",
"main": "node.js",
@@ -15,6 +15,6 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textdecoder#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-global": "5.6.2"
"@polkadot/x-global": "5.7.1"
}
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textdecoder', version: '5.7.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-textencoder",
"version": "5.6.2",
"version": "5.7.1",
"description": "A TextDecoder replacement",
"browser": "browser.js",
"main": "node.js",
@@ -15,6 +15,6 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-textencoder#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-global": "5.6.2"
"@polkadot/x-global": "5.7.1"
}
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-textencoder', version: '5.7.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/x-ws",
"version": "5.6.2",
"version": "5.7.1",
"description": "A cross-environment WebSocket replacement",
"browser": "browser.js",
"main": "node.js",
@@ -15,7 +15,7 @@
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-ws#readme",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@polkadot/x-global": "5.6.2",
"@polkadot/x-global": "5.7.1",
"@types/websocket": "^1.0.1",
"websocket": "^1.0.33"
}
+6
View File
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/x-ws', version: '5.7.1' };
+273 -265
View File
File diff suppressed because it is too large Load Diff