Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9dd6f1efc | ||
|
|
563dbbf7e4 | ||
|
|
5a5bc7da0b | ||
|
|
fb2c51a49b | ||
|
|
568e3b7840 | ||
|
|
87d69d7098 | ||
|
|
255cd93bf4 | ||
|
|
ef5780996e | ||
|
|
5155ae8d2b | ||
|
|
f1447ffcbc | ||
|
|
64e9ec5044 | ||
|
|
05986f6d64 | ||
|
|
caca69525a | ||
|
|
845398846c | ||
|
|
412ca6ccd7 | ||
|
|
9232fd5a91 | ||
|
|
49174d181e | ||
|
|
c5bc09fde7 | ||
|
|
1a436906f5 | ||
|
|
d7bb55c003 | ||
|
|
50f015a713 | ||
|
|
1c94508d61 | ||
|
|
ddb007de7b | ||
|
|
8bee7d5d6b | ||
|
|
253eea9249 | ||
|
|
502fdc1e32 | ||
|
|
f3aaaede25 | ||
|
|
309d691938 | ||
|
|
4d6438c3e7 | ||
|
|
19817b213b | ||
|
|
20d4457483 | ||
|
|
a2d0f2b1a3 | ||
|
|
a512766bfb | ||
|
|
b11b42e2b6 | ||
|
|
c13c2022ca |
@@ -1,21 +0,0 @@
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
working_directory: ~/polkadot-js
|
||||
docker:
|
||||
- image: circleci/node:10
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key: dependency-cache-{{ checksum "yarn.lock" }}
|
||||
- run:
|
||||
name: install-deps
|
||||
command: yarn install --frozen-lockfile
|
||||
- save_cache:
|
||||
key: dependency-cache-{{ checksum "yarn.lock" }}
|
||||
paths:
|
||||
- ./node_modules
|
||||
- ~/.cache/yarn
|
||||
- run:
|
||||
name: build
|
||||
command: yarn polkadot-dev-circleci-build
|
||||
+1
-1
@@ -5,7 +5,7 @@ module.exports = {
|
||||
parserOptions: {
|
||||
...base.parserOptions,
|
||||
project: [
|
||||
'./tsconfig.eslint.json'
|
||||
'./tsconfig.json'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
name: PR
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Linting
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: lint
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn lint
|
||||
|
||||
test:
|
||||
name: Testing
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: test
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn test
|
||||
|
||||
build_code:
|
||||
name: Build Code
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: build
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn build
|
||||
|
||||
build_docs:
|
||||
name: Build Docs
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: build
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn docs
|
||||
@@ -0,0 +1,53 @@
|
||||
name: Master
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build_code:
|
||||
name: Build Code
|
||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: build
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn polkadot-dev-ghact-build
|
||||
|
||||
build_docs:
|
||||
name: Build Docs
|
||||
if: "! contains(github.event.head_commit.message, '[CI Skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: build
|
||||
env:
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GH_PAGES_SRC: build-docs
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn polkadot-dev-ghact-docs
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
env:
|
||||
global:
|
||||
- CC_TEST_REPORTER_ID=27a299582eb7fd9580e27897a6ecda1c82a1cd24bcfe2f2ebda1ca70238509b4
|
||||
- GH_PAGES_SRC="build-docs"
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- node_modules
|
||||
before_install:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
||||
- chmod +x ./cc-test-reporter
|
||||
- export PATH=$HOME/.yarn/bin:$(yarn global bin):$PATH
|
||||
before_script:
|
||||
- ./cc-test-reporter before-build
|
||||
script:
|
||||
- yarn polkadot-dev-travis-build
|
||||
after_script:
|
||||
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
provider: script
|
||||
script: yarn polkadot-dev-travis-deploy
|
||||
on:
|
||||
branch: master
|
||||
@@ -1,3 +1,13 @@
|
||||
# 1.6.1
|
||||
|
||||
- `pair.sign(message)` now takes an optional second `options?: SignOptions` parameter, where `SignOptions` is currently defined as `{ withType: boolean }`. Here `withType` instructs the signing to prepend the type of signature (ed2551, sr25519 or ecdsa). This is used for the new Polkadot/Substrate MultiSignature format.
|
||||
|
||||
# 1.5.1
|
||||
|
||||
- Fix typings on the Keyring-exposed encode & decodeAddress
|
||||
- Allow ss58Format = 0 as a valid value
|
||||
- Loosen type definitions for allowed ss58format values (still checked against allowed array)
|
||||
|
||||
# 1.4.1
|
||||
|
||||
- **Breaking change** To set the `ss58Format`, you should now use `setSS58Format` as opposed to the old `setAddressPrefix`
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "1.4.1"
|
||||
"version": "1.6.1"
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"yarn": "^1.10.1"
|
||||
@@ -9,11 +9,11 @@
|
||||
],
|
||||
"resolutions": {
|
||||
"babel-core": "^7.0.0-bridge.0",
|
||||
"typescript": "^3.6.3"
|
||||
"typescript": "^3.6.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-ts && polkadot-dev-build-docs",
|
||||
"check": "yarn lint",
|
||||
"build": "polkadot-dev-build-ts",
|
||||
"docs": "polkadot-dev-build-docs",
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx . && tsc --noEmit --pretty",
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
@@ -21,9 +21,9 @@
|
||||
"test:one": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.6.0",
|
||||
"@polkadot/dev": "^0.31.0-beta.8",
|
||||
"@polkadot/ts": "^0.1.72",
|
||||
"@babel/core": "^7.6.4",
|
||||
"@polkadot/dev": "^0.32.0-beta.11",
|
||||
"@polkadot/ts": "^0.1.82",
|
||||
"gh-pages": "^2.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/chainspec",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "Contains chain specifications for known chains",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/chainspec#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/db",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "Implementation of a basic sync in-memory and on-disk databases with overlays",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,9 +25,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/db#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/trie-hash": "^1.4.1",
|
||||
"@polkadot/util": "^1.4.1",
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/trie-hash": "^1.6.1",
|
||||
"@polkadot/util": "^1.6.1",
|
||||
"lru_map": "^0.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/keyring",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "Keyring management",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
@@ -27,8 +27,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1",
|
||||
"@polkadot/util-crypto": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1",
|
||||
"@polkadot/util-crypto": "^1.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ export default class Keyring implements KeyringInstance {
|
||||
|
||||
public constructor (options: KeyringOptions = {}) {
|
||||
options.type = options.type || 'ed25519';
|
||||
options.ss58Format = options.ss58Format || options.addressPrefix;
|
||||
options.ss58Format = isNumber(options.ss58Format)
|
||||
? options.addressPrefix
|
||||
: options.ss58Format;
|
||||
|
||||
assert(options && ['ed25519', 'sr25519'].includes(options.type || 'undefined'), `Expected a keyring type of either 'ed25519' or 'sr25519', found '${options.type}`);
|
||||
|
||||
|
||||
@@ -3,15 +3,21 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Keypair, KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta, SignOptions } from '../types';
|
||||
import { PairInfo } from './types';
|
||||
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
import { encodeAddress, naclKeypairFromSeed as naclFromSeed, naclSign, naclVerify, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVerify } from '@polkadot/util-crypto';
|
||||
|
||||
import decode from './decode';
|
||||
import encode from './encode';
|
||||
import toJson from './toJson';
|
||||
|
||||
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]);
|
||||
|
||||
function isEmpty (u8a: Uint8Array): boolean {
|
||||
return u8a.reduce((count, u8): number => count + u8, 0) === 0;
|
||||
}
|
||||
@@ -24,10 +30,24 @@ const fromSeed = (type: KeypairType, seed: Uint8Array): Keypair =>
|
||||
? schnorrkelFromSeed(seed)
|
||||
: naclFromSeed(seed);
|
||||
|
||||
const sign = (type: KeypairType, message: Uint8Array, pair: Partial<Keypair>): Uint8Array =>
|
||||
isSr25519(type)
|
||||
? schnorrkelSign(message, pair)
|
||||
: naclSign(message, pair);
|
||||
const sign = (type: KeypairType, message: Uint8Array, pair: Partial<Keypair>, { withType = false }: SignOptions = {}): Uint8Array => {
|
||||
const typeSr25519 = isSr25519(type);
|
||||
|
||||
return u8aConcat(
|
||||
// for multi-signatures, i.e. with indicator, append the signature type as per
|
||||
// the MultiSignature enum
|
||||
withType
|
||||
? (
|
||||
typeSr25519
|
||||
? SIG_TYPE_SR25519
|
||||
: SIG_TYPE_ED25519
|
||||
)
|
||||
: SIG_TYPE_NONE,
|
||||
typeSr25519
|
||||
? schnorrkelSign(message, pair)
|
||||
: naclSign(message, pair)
|
||||
);
|
||||
};
|
||||
|
||||
const verify = (type: KeypairType, message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean =>
|
||||
isSr25519(type)
|
||||
@@ -101,8 +121,8 @@ export default function createPair (type: KeypairType, { publicKey, secretKey }:
|
||||
setMeta: (additional: KeyringPair$Meta): void => {
|
||||
meta = { ...meta, ...additional };
|
||||
},
|
||||
sign: (message: Uint8Array): Uint8Array =>
|
||||
sign(type, message, { publicKey, secretKey }),
|
||||
sign: (message: Uint8Array, options?: SignOptions): Uint8Array =>
|
||||
sign(type, message, { publicKey, secretKey }, options),
|
||||
toJson: (passphrase?: string): KeyringPair$Json =>
|
||||
toJson(type, { meta, publicKey }, encode({ publicKey, secretKey }, passphrase), !!passphrase),
|
||||
verify: (message: Uint8Array, signature: Uint8Array): boolean =>
|
||||
|
||||
@@ -33,6 +33,10 @@ export interface KeyringPair$Json {
|
||||
meta: KeyringPair$Meta;
|
||||
}
|
||||
|
||||
export interface SignOptions {
|
||||
withType?: boolean;
|
||||
}
|
||||
|
||||
export interface KeyringPair {
|
||||
readonly type: KeypairType;
|
||||
|
||||
@@ -44,7 +48,7 @@ export interface KeyringPair {
|
||||
lock: () => void;
|
||||
publicKey: Uint8Array;
|
||||
setMeta: (meta: KeyringPair$Meta) => void;
|
||||
sign (message: Uint8Array): Uint8Array;
|
||||
sign (message: Uint8Array, options?: SignOptions): Uint8Array;
|
||||
toJson (passphrase?: string): KeyringPair$Json;
|
||||
verify (message: Uint8Array, signature: Uint8Array): boolean;
|
||||
}
|
||||
@@ -61,9 +65,9 @@ export interface KeyringInstance {
|
||||
readonly publicKeys: Uint8Array[];
|
||||
readonly type: KeypairType;
|
||||
|
||||
decodeAddress (encoded: string | Uint8Array, ignoreChecksum?: boolean): Uint8Array;
|
||||
encodeAddress (key: Uint8Array | string): string;
|
||||
setSS58Format (prefix: Prefix): void;
|
||||
decodeAddress (encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
|
||||
encodeAddress (key: Uint8Array | string, ss58Format?: Prefix): string;
|
||||
setSS58Format (ss58Format: Prefix): void;
|
||||
|
||||
addPair (pair: KeyringPair): KeyringPair;
|
||||
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/trie-codec",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "This is an implementation of the codec for Substrate Trie",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-codec#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/trie-db",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "This is an implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper, adapted for Polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,16 +25,16 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-db#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/db": "^1.4.1",
|
||||
"@polkadot/trie-codec": "^1.4.1",
|
||||
"@polkadot/trie-hash": "^1.4.1",
|
||||
"@polkadot/util": "^1.4.1",
|
||||
"@polkadot/util-crypto": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/db": "^1.6.1",
|
||||
"@polkadot/trie-codec": "^1.6.1",
|
||||
"@polkadot/trie-hash": "^1.6.1",
|
||||
"@polkadot/util": "^1.6.1",
|
||||
"@polkadot/util-crypto": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/chainspec": "^1.4.1",
|
||||
"@polkadot/util-rlp": "^1.4.1",
|
||||
"@polkadot/chainspec": "^1.6.1",
|
||||
"@polkadot/util-rlp": "^1.6.1",
|
||||
"ethereumjs-testing": "1.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/trie-hash",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "Generates trie roots from key-value pairs",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,10 +25,10 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/chainspec": "^1.4.1"
|
||||
"@polkadot/chainspec": "^1.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-crypto",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "A collection of useful crypto utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,8 +25,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1",
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1",
|
||||
"@polkadot/wasm-crypto": "^0.14.1",
|
||||
"@types/bip39": "^2.4.2",
|
||||
"@types/bs58": "^4.0.0",
|
||||
|
||||
@@ -12,7 +12,7 @@ import sshash from './sshash';
|
||||
export default function check (address: string, prefix: Prefix): [boolean, string | null] {
|
||||
const decoded = bs58.decode(address);
|
||||
|
||||
if (decoded[0] as Prefix !== prefix) {
|
||||
if (decoded[0] !== prefix) {
|
||||
return [false, `Prefix mismatch, expected ${prefix}, found ${decoded[0]}`];
|
||||
} else if (!defaults.allowedEncodedLengths.includes(decoded.length)) {
|
||||
return [false, 'Invalid decoded address length'];
|
||||
|
||||
@@ -13,7 +13,7 @@ import defaults from './defaults';
|
||||
import sshash from './sshash';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export default function decode (encoded: string | Uint8Array, ignoreChecksum?: boolean, prefix: Prefix = defaults.prefix): Uint8Array {
|
||||
export default function decode (encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format: Prefix = 99): Uint8Array {
|
||||
if (isU8a(encoded) || isHex(encoded)) {
|
||||
return u8aToU8a(encoded);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Prefix } from './types';
|
||||
import { allowedSS58 } from './ss58';
|
||||
|
||||
const defaults = {
|
||||
allowedDecodedLengths: [1, 2, 4, 8, 32],
|
||||
// publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
|
||||
allowedEncodedLengths: [3, 4, 6, 10, 35],
|
||||
allowedPrefix: [0, 1, 3, 42, 43, 68, 69] as Prefix[],
|
||||
prefix: 42 as Prefix
|
||||
allowedPrefix: allowedSS58,
|
||||
prefix: 42
|
||||
};
|
||||
|
||||
export default defaults;
|
||||
|
||||
@@ -13,7 +13,7 @@ import decode from './decode';
|
||||
import defaults from './defaults';
|
||||
import sshash from './sshash';
|
||||
|
||||
export default function encode (_key: Uint8Array | string, prefix: Prefix = defaults.prefix): string {
|
||||
export default function encode (_key: Uint8Array | string, ss58Format: Prefix = defaults.prefix): string {
|
||||
// decode it, this means we can re-encode an address
|
||||
const key = decode(_key);
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function encode (_key: Uint8Array | string, prefix: Prefix = defa
|
||||
|
||||
const isPublicKey = key.length === 32;
|
||||
|
||||
const input = u8aConcat(new Uint8Array([prefix]), key);
|
||||
const input = u8aConcat(new Uint8Array([ss58Format]), key);
|
||||
const hash = sshash(input);
|
||||
|
||||
return bs58.encode(
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export const allowedSS58 = [
|
||||
// Polkadot
|
||||
0, 1,
|
||||
// Kusama
|
||||
2, 3,
|
||||
// Dothereum
|
||||
20,
|
||||
// Substrate default
|
||||
42, 43,
|
||||
// Substrate BBQ (deprecated)
|
||||
68, 69
|
||||
];
|
||||
@@ -2,9 +2,6 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
type PrefixPolkadot = 0;
|
||||
type PrefixKusama = 2;
|
||||
type PrefixSubstrate = 42;
|
||||
type DeprecatedPrefixBBQ = 68;
|
||||
|
||||
export type Prefix = PrefixPolkadot | PrefixKusama | PrefixSubstrate | DeprecatedPrefixBBQ;
|
||||
// FIXME we really want this to map with what is in the allowedSS58 array... i.e. the
|
||||
// values there. As of now, we just map to number.
|
||||
export type Prefix = number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-rlp",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "RLP encoding and decoding",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,8 +27,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-rlp#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@polkadot/util": "^1.4.1"
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@polkadot/util": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ethereumjs-testing": "1.0.4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.1",
|
||||
"description": "A collection of useful utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.0",
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@types/bn.js": "^4.11.5",
|
||||
"bn.js": "^4.11.8",
|
||||
"camelcase": "^5.3.1",
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": [
|
||||
"build",
|
||||
"packages/*/build"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"extends": "./node_modules/@polkadot/dev/config/tsconfig",
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"**/build/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
@@ -22,6 +26,7 @@
|
||||
"@polkadot/util": [ "packages/util/src" ],
|
||||
"@polkadot/util/*": [ "packages/util/src/*" ]
|
||||
},
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@polkadot/ts",
|
||||
"./node_modules/@types"
|
||||
|
||||
Reference in New Issue
Block a user