Use @polkadot/hw-ledger from common (#429)

This commit is contained in:
Jaco Greeff
2021-01-14 22:54:38 +01:00
committed by GitHub
parent 089b24f505
commit 19c68dada7
25 changed files with 96 additions and 813 deletions
-3
View File
@@ -5,9 +5,6 @@ const config = require('@polkadot/dev/config/jest.cjs');
module.exports = Object.assign({}, config, {
moduleNameMapper: {
'@polkadot/ledger-transports(.*)$': '<rootDir>/packages/ledger-transports/src/node',
// eslint-disable-next-line sort-keys
'@polkadot/ledger(.*)$': '<rootDir>/packages/ledger/src/$1',
'@polkadot/react-(identicon|qr)(.*)$': '<rootDir>/packages/react-$1/src/$2',
'@polkadot/reactnative-(identicon)(.*)$': '<rootDir>/packages/reactnative-$1/src/$2',
'@polkadot/ui-(assets|keyring|settings|shared)(.*)$': '<rootDir>/packages/ui-$1/src/$2',
+3 -3
View File
@@ -12,12 +12,12 @@
"test": "jest"
},
"dependencies": {
"@polkadot/keyring": "^5.2.4-4",
"@polkadot/keyring": "^5.2.4-6",
"@polkadot/reactnative-identicon": "0.65.2-4",
"@polkadot/ui-keyring": "0.65.2-4",
"@polkadot/ui-settings": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"@react-native-community/async-storage": "^1.12.1",
"fast-text-encoding": "^1.0.3",
"get-yarn-workspaces": "^1.0.2",
-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-2
View File
@@ -1,2 +0,0 @@
# @polkadot/ledger-transports
-24
View File
@@ -1,24 +0,0 @@
{
"name": "@polkadot/ledger-transports",
"version": "0.65.2-4",
"repository": "github:polkadot-js/ui",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"main": "node.js",
"browser": "browser.js",
"react-native": "react-native.js",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.12.5",
"@ledgerhq/hw-transport-webusb": "^5.38.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.38.0"
}
}
-24
View File
@@ -1,24 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type Transport from '@ledgerhq/hw-transport';
import type { TransportDef } from './types';
import LedgerWebUSB from '@ledgerhq/hw-transport-webusb';
const transports: TransportDef[] = [
// deprecated
// import LedgerU2F from '@ledgerhq/hw-transport-u2f';
// {
// create: (): Promise<Transport> =>
// LedgerU2F.create(),
// type: 'u2f'
// },
{
create: (): Promise<Transport> =>
LedgerWebUSB.create(),
type: 'webusb'
}
];
export { transports };
-15
View File
@@ -1,15 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
declare module '@ledgerhq/hw-transport-node-hid-noevents' {
import Transport from '@ledgerhq/hw-transport';
export default class TransportNodeHidNoEvents extends Transport<string> {}
export function getDevices(): Array<unknown>
}
declare module '@ledgerhq/hw-transport-node-hid-singleton' {
import TransportNodeHidNoEvents, { getDevices } from '@ledgerhq/hw-transport-node-hid-noevents';
export default class TransportNodeHid extends TransportNodeHidNoEvents { }
}
-17
View File
@@ -1,17 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type Transport from '@ledgerhq/hw-transport';
import type { TransportDef } from './types';
import LedgerHid from '@ledgerhq/hw-transport-node-hid-singleton';
const transports: TransportDef[] = [
{
create: (): Promise<Transport> =>
LedgerHid.create(),
type: 'hid'
}
];
export { transports };
@@ -1,8 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { TransportDef } from './types';
const transports: TransportDef[] = [];
export { transports };
-11
View File
@@ -1,11 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Transport from '@ledgerhq/hw-transport';
export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
export interface TransportDef {
create (): Promise<Transport>;
type: LedgerTypes;
}
-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-2
View File
@@ -1,2 +0,0 @@
# @polkadot/ledger
-21
View File
@@ -1,21 +0,0 @@
{
"name": "@polkadot/ledger",
"version": "0.65.2-4",
"repository": "github:polkadot-js/ui",
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [],
"contributors": [],
"license": "Apache-2.0",
"main": "index.js",
"module": "index.mjs",
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/ledger-transports": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@zondax/ledger-polkadot": "^0.13.0"
},
"peerDependencies": {
"@polkadot/util": "*"
}
}
-118
View File
@@ -1,118 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type Transport from '@ledgerhq/hw-transport';
import type { AccountOptions, LedgerAddress, LedgerSignature, LedgerTypes, LedgerVersion } from './types';
import { newDockApp, newKusamaApp, newPolkadotApp, newPolymeshApp, ResponseBase, SubstrateApp } from '@zondax/ledger-polkadot';
import { transports } from '@polkadot/ledger-transports';
import { assert, bufferToU8a, u8aToBuffer, u8aToHex } from '@polkadot/util';
export const LEDGER_DEFAULT_ACCOUNT = 0x80000000;
export const LEDGER_DEFAULT_CHANGE = 0x80000000;
export const LEDGER_DEFAULT_INDEX = 0x80000000;
const SUCCESS_CODE = 0x9000;
// These match up with the network keys in the @polkadot/networks package
// (which is turn aligns with the substrate/ss58-registry.json as the single
// source of truth)
const APPS: Record<string, (transport: Transport) => SubstrateApp> = {
dock: newDockApp,
kusama: newKusamaApp,
polkadot: newPolkadotApp,
polymath: newPolymeshApp
};
type Chain = keyof typeof APPS;
// A very basic wrapper for a ledger app -
// - it connects automatically, creating an app as required
// - Promises return errors (instead of wrapper errors)
export class Ledger {
#app: SubstrateApp | null = null;
#chain: Chain;
#transport: LedgerTypes;
constructor (transport: LedgerTypes, chain: Chain) {
// u2f is deprecated
assert(['hid', 'webusb'].includes(transport), `Unsupported transport ${transport}`);
assert(Object.keys(APPS).includes(chain), `Unsupported chain ${chain}`);
this.#chain = chain;
this.#transport = transport;
}
public async getAddress (confirm = false, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE }: Partial<AccountOptions> = {}): Promise<LedgerAddress> {
return this.#withApp(async (app: SubstrateApp): Promise<LedgerAddress> => {
const { address, pubKey } = await this.#wrapError(app.getAddress(account + accountOffset, change, addressIndex + addressOffset, confirm));
return {
address,
publicKey: `0x${pubKey}`
};
});
}
public async getVersion (): Promise<LedgerVersion> {
return this.#withApp(async (app: SubstrateApp): Promise<LedgerVersion> => {
const { device_locked: isLocked, major, minor, patch, test_mode: isTestMode } = await this.#wrapError(app.getVersion());
return {
isLocked,
isTestMode,
version: [major, minor, patch]
};
});
}
public async sign (message: Uint8Array, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE }: Partial<AccountOptions> = {}): Promise<LedgerSignature> {
return this.#withApp(async (app: SubstrateApp): Promise<LedgerSignature> => {
const buffer = u8aToBuffer(message);
const { signature } = await this.#wrapError(app.sign(account + accountOffset, change, addressIndex + addressOffset, buffer));
return {
signature: u8aToHex(bufferToU8a(signature))
};
});
}
#getApp = async (): Promise<SubstrateApp> => {
if (!this.#app) {
const def = transports.find(({ type }) => type === this.#transport);
assert(def, `Unable to find a transport for ${this.#transport}`);
const transport = await def.create();
this.#app = APPS[this.#chain](transport);
}
return this.#app;
};
#withApp = async <T> (fn: (app: SubstrateApp) => Promise<T>): Promise<T> => {
try {
const app = await this.#getApp();
return await fn(app);
} catch (error) {
this.#app = null;
throw error;
}
};
#wrapError = async <T extends ResponseBase> (promise: Promise<T>): Promise<T> => {
const result = await promise;
assert(result.return_code === SUCCESS_CODE, result.error_message);
return result;
};
}
-25
View File
@@ -1,25 +0,0 @@
// Copyright 2017-2021 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
export type LedgerTypes = 'hid' | 'u2f' | 'webusb';
export interface AccountOptions {
account: number;
addressIndex: number;
change: number;
}
export interface LedgerAddress {
address: string;
publicKey: string;
}
export interface LedgerSignature {
signature: string;
}
export interface LedgerVersion {
isLocked: boolean;
isTestMode: boolean;
version: [number, number, number];
}
+3 -3
View File
@@ -10,11 +10,11 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/keyring": "^5.2.4-4",
"@polkadot/keyring": "^5.2.4-6",
"@polkadot/ui-settings": "0.65.2-4",
"@polkadot/ui-shared": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"color": "^3.1.3",
"ethereum-blockies-base64": "^1.0.2",
"jdenticon": "3.1.0",
+2 -2
View File
@@ -10,8 +10,8 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"qrcode-generator": "^1.4.4",
"react-qr-reader": "^2.2.1",
"styled-components": "^5.2.1"
+2 -2
View File
@@ -11,8 +11,8 @@
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/ui-shared": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"react-native-svg": "^12.1.0"
},
"peerDependencies": {
+3 -3
View File
@@ -14,10 +14,10 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/keyring": "^5.2.4-4",
"@polkadot/ledger": "^0.65.2-4",
"@polkadot/hw-ledger": "^5.2.4-6",
"@polkadot/keyring": "^5.2.4-6",
"@polkadot/ui-settings": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/x-rxjs": "^3.4.2-8",
"mkdirp": "^1.0.4",
"store": "^2.0.12"
+1 -1
View File
@@ -5,7 +5,7 @@ import './detectPackage';
import { Keyring } from './Keyring';
export { Ledger } from '@polkadot/ledger';
export { Ledger } from '@polkadot/hw-ledger';
const keyring = new Keyring();
+2 -2
View File
@@ -10,8 +10,8 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/networks": "^5.2.4-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/networks": "^5.2.4-6",
"@polkadot/util": "^5.2.4-6",
"eventemitter3": "^4.0.7",
"store": "^2.0.12"
},
+2 -2
View File
@@ -17,8 +17,8 @@
"@polkadot/util-crypto": "*"
},
"devDependencies": {
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"@types/color": "^3.0.1",
"@types/xmlserializer": "^0.6.2"
}
+2 -2
View File
@@ -11,8 +11,8 @@
"dependencies": {
"@babel/runtime": "^7.12.5",
"@polkadot/ui-shared": "0.65.2-4",
"@polkadot/util": "^5.2.4-4",
"@polkadot/util-crypto": "^5.2.4-4",
"@polkadot/util": "^5.2.4-6",
"@polkadot/util-crypto": "^5.2.4-6",
"jdenticon": "3.1.0"
},
"peerDependencies": {
-4
View File
@@ -7,10 +7,6 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@polkadot/ledger": [ "packages/ledger/src" ],
"@polkadot/ledger/*": [ "packages/ledger/src/*" ],
"@polkadot/ledger-transports": [ "packages/ledger-transports/src/browser" ],
"@polkadot/ledger-transports/*": [ "packages/ledger-transports/src/browser" ],
"@polkadot/react-identicon": [ "packages/react-identicon/src" ],
"@polkadot/react-identicon/*": [ "packages/react-identicon/src/*" ],
"@polkadot/react-qr": [ "packages/react-qr/src" ],
+76 -117
View File
@@ -2040,47 +2040,45 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/keyring@npm:^5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/keyring@npm:5.2.4-4"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/util": 5.2.4-4
"@polkadot/util-crypto": 5.2.4-4
peerDependencies:
"@polkadot/util": 5.2.4-4
"@polkadot/util-crypto": 5.2.4-4
checksum: cf4d51528c64a5eae24a2de8572a16317f356e7642569719386f853e643ea36d9f487a2225ac3cae4fa3f3d6ed089fea4659c13a9e78a588edae9ee00c3a7127
languageName: node
linkType: hard
"@polkadot/ledger-transports@0.65.2-4, @polkadot/ledger-transports@workspace:packages/ledger-transports":
version: 0.0.0-use.local
resolution: "@polkadot/ledger-transports@workspace:packages/ledger-transports"
"@polkadot/hw-ledger-transports@npm:5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/hw-ledger-transports@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
"@ledgerhq/hw-transport-node-hid-singleton": ^5.38.0
"@ledgerhq/hw-transport-webusb": ^5.38.0
"@types/ledgerhq__hw-transport-node-hid": ^4.22.2
"@types/ledgerhq__hw-transport-webusb": ^4.70.1
dependenciesMeta:
"@ledgerhq/hw-transport-node-hid-singleton":
optional: true
languageName: unknown
linkType: soft
checksum: 6e5c0cd9fa00d4b52da820dc7e152e24594728d54a25170eeb24bad893491e3dadaf5dd5c7a0d26a009c31c56a05d0b7a28eb5040c9a65ad150e01dd096bdc33
languageName: node
linkType: hard
"@polkadot/ledger@^0.65.2-4, @polkadot/ledger@workspace:packages/ledger":
version: 0.0.0-use.local
resolution: "@polkadot/ledger@workspace:packages/ledger"
"@polkadot/hw-ledger@npm:^5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/hw-ledger@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/ledger-transports": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/hw-ledger-transports": 5.2.4-6
"@polkadot/util": ^5.2.4-6
"@zondax/ledger-polkadot": ^0.13.0
checksum: 0fac5b941ba56f6ad86bf210083b4e3436eef81b96b6f247aec27d2c588915ca6f9d394493080688cf5dacb570117beb39a0cdcda071af8f3d9cb2c95c6910db
languageName: node
linkType: hard
"@polkadot/keyring@npm:^5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/keyring@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/util": 5.2.4-6
"@polkadot/util-crypto": 5.2.4-6
peerDependencies:
"@polkadot/util": "*"
languageName: unknown
linkType: soft
"@polkadot/util": 5.2.4-6
"@polkadot/util-crypto": 5.2.4-6
checksum: 12aee20425e4d8a2f8e3c56849d427ca6311e94d543c37e5ea37b9ae3d082c3f69e0a3fd3af3d59ef5e7903016901e504304dba78a69cfc6a537cd81d99ab0ca
languageName: node
linkType: hard
"@polkadot/metadata@npm:3.4.2-8":
version: 3.4.2-8
@@ -2105,12 +2103,12 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/networks@npm:5.2.4-4, @polkadot/networks@npm:^5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/networks@npm:5.2.4-4"
"@polkadot/networks@npm:5.2.4-6, @polkadot/networks@npm:^5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/networks@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
checksum: 3aeddcc77f011c2ac7da71167b0dab5576b5d450b5fe89dcfb12693ad5796b978bef2acd3d1d481734462e9560bcb230e45ac6ece2003afa8cf4528480b80811
checksum: 3acd5815c463e65c465b818bb61de8e5a13192127c2a9c62834dbf10e6af0d85abfec0b3084314de33e9b4780f8b7ae6e491f5efaa7580500b1c6428b8af9a39
languageName: node
linkType: hard
@@ -2119,11 +2117,11 @@ __metadata:
resolution: "@polkadot/react-identicon@workspace:packages/react-identicon"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/keyring": ^5.2.4-4
"@polkadot/keyring": ^5.2.4-6
"@polkadot/ui-settings": 0.65.2-4
"@polkadot/ui-shared": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
"@types/react-copy-to-clipboard": ^5.0.0
"@types/react-dom": ^17.0.0
"@types/styled-components": ^5.1.7
@@ -2149,8 +2147,8 @@ __metadata:
resolution: "@polkadot/react-qr@workspace:packages/react-qr"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
"@types/react-qr-reader": ^2.1.3
"@types/styled-components": ^5.1.7
qrcode-generator: ^1.4.4
@@ -2171,8 +2169,8 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/ui-shared": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
"@types/react-native": ^0.63.45
react-native-svg: ^12.1.0
peerDependencies:
@@ -2232,11 +2230,11 @@ __metadata:
resolution: "@polkadot/ui-keyring@workspace:packages/ui-keyring"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/keyring": ^5.2.4-4
"@polkadot/ledger": ^0.65.2-4
"@polkadot/hw-ledger": ^5.2.4-6
"@polkadot/keyring": ^5.2.4-6
"@polkadot/types": ^3.4.2-8
"@polkadot/ui-settings": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/x-rxjs": ^3.4.2-8
"@types/mkdirp": ^1.0.1
"@types/store": ^2.0.2
@@ -2254,8 +2252,8 @@ __metadata:
resolution: "@polkadot/ui-settings@workspace:packages/ui-settings"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/networks": ^5.2.4-4
"@polkadot/util": ^5.2.4-4
"@polkadot/networks": ^5.2.4-6
"@polkadot/util": ^5.2.4-6
"@types/store": ^2.0.2
eventemitter3: ^4.0.7
store: ^2.0.12
@@ -2270,8 +2268,8 @@ __metadata:
resolution: "@polkadot/ui-shared@workspace:packages/ui-shared"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
"@types/color": ^3.0.1
"@types/xmlserializer": ^0.6.2
color: ^3.1.3
@@ -2281,15 +2279,15 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/util-crypto@npm:5.2.4-4, @polkadot/util-crypto@npm:^5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/util-crypto@npm:5.2.4-4"
"@polkadot/util-crypto@npm:5.2.4-6, @polkadot/util-crypto@npm:^5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/util-crypto@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/networks": 5.2.4-4
"@polkadot/util": 5.2.4-4
"@polkadot/networks": 5.2.4-6
"@polkadot/util": 5.2.4-6
"@polkadot/wasm-crypto": ^3.1.1
"@polkadot/x-randomvalues": 5.2.4-4
"@polkadot/x-randomvalues": 5.2.4-6
base-x: ^3.0.8
blakejs: ^1.1.0
bn.js: ^4.11.9
@@ -2301,8 +2299,8 @@ __metadata:
tweetnacl: ^1.0.3
xxhashjs: ^0.2.2
peerDependencies:
"@polkadot/util": 5.2.4-4
checksum: 86d2624e74edc058fac26695c9ec36172c1c87f67a3f78c5c3b988fd796041d551bdfa518d4c975025cbb4d428a42196b5371d720d6f93f990e5aea4d1af4803
"@polkadot/util": 5.2.4-6
checksum: a435d8c121e79ada4bac928bc936249238dc2268b36c04cf68bda4654e54d9945c0f45af1c5e124240207a76838d0f1bce50e710ab291d4ec6a8ddb734842937
languageName: node
linkType: hard
@@ -2346,18 +2344,18 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/util@npm:5.2.4-4, @polkadot/util@npm:^5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/util@npm:5.2.4-4"
"@polkadot/util@npm:5.2.4-6, @polkadot/util@npm:^5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/util@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/x-textdecoder": 5.2.4-4
"@polkadot/x-textencoder": 5.2.4-4
"@polkadot/x-textdecoder": 5.2.4-6
"@polkadot/x-textencoder": 5.2.4-6
"@types/bn.js": ^4.11.6
bn.js: ^4.11.9
camelcase: ^5.3.1
ip-regex: ^4.2.0
checksum: 0ed645425ed240e1086d271a4302f0bee307a34efdcba3be9f2d880e952dc480ffeece5225582475e88bf32edfdc77b6d04e8204b3c269a16a56bb5896000915
checksum: b079d1dbb29eefb5c416ef36e6b5c4d369ff211721e077e9592f6cd2de77acc0a88b51257f266a4c396add2123bc1f7dbf05a39ba83d1ae50702dd3e23596d60
languageName: node
linkType: hard
@@ -2367,8 +2365,8 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/ui-shared": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
jdenticon: 3.1.0
vue: ^2.6.12
peerDependencies:
@@ -2419,12 +2417,12 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-randomvalues@npm:5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/x-randomvalues@npm:5.2.4-4"
"@polkadot/x-randomvalues@npm:5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/x-randomvalues@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
checksum: b7df713f63f053bec50c0db44c4bfbbcac72bb3c1449f235acecc3773dd5b1f5ceb4ce5e735cf8fc10e86355f0aa32679173cb8456899636491a424171741360
checksum: 04d266331dc1dbc049e0c54c93143e0bf9a77e256227f076620ddef08d835149c14e8a21bb388ed9edbf0c6bd3e847815bb15bbd5993edaef761be35ef2f5615
languageName: node
linkType: hard
@@ -2447,12 +2445,12 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-textdecoder@npm:5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/x-textdecoder@npm:5.2.4-4"
"@polkadot/x-textdecoder@npm:5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/x-textdecoder@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
checksum: 500000e99065d2500ef52c2925a54e62e6b186806730bceeb31452239ad22eb64955da6178872de6f0a11ceaf78011a3f01e15176dc6725e1417db8fa3c9826e
checksum: 968e3ee0005c8d1c5183ff068cbfc68b674894363516cd08f0a121f6bd93434e6043bbae941974d7d06852730538b5c89c1c20498009f865b601624311f628fb
languageName: node
linkType: hard
@@ -2465,12 +2463,12 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-textencoder@npm:5.2.4-4":
version: 5.2.4-4
resolution: "@polkadot/x-textencoder@npm:5.2.4-4"
"@polkadot/x-textencoder@npm:5.2.4-6":
version: 5.2.4-6
resolution: "@polkadot/x-textencoder@npm:5.2.4-6"
dependencies:
"@babel/runtime": ^7.12.5
checksum: 6b1e6bd53ff1a6e90b0c6f3bcf79a57e561f9dcf08f3cb7469b090251df1628d964773c26a34d1f059728d7145f6a2692b95734b9ceb4d3b307a1eab29195550
checksum: ce60ca66f10a2ad2aad6e8e96e1a0e424e9032e8a1d0c32d432704618e0e27b3a72c1ff78e1832f0f12e7699ae03637841ccf23f46ecdee9b51e3d70f185afd6
languageName: node
linkType: hard
@@ -2872,36 +2870,6 @@ __metadata:
languageName: node
linkType: hard
"@types/ledgerhq__hw-transport-node-hid@npm:^4.22.2":
version: 4.22.2
resolution: "@types/ledgerhq__hw-transport-node-hid@npm:4.22.2"
dependencies:
"@types/ledgerhq__hw-transport": "*"
"@types/node": "*"
"@types/node-hid": "*"
checksum: 2e967635bb7de860f3b525d0629fae4cc2f7d460024a86b564c4239142f27b10fafdea6e2deeed05356dbb7dca45d8663ad2e522e94e51930549b4e5507aa014
languageName: node
linkType: hard
"@types/ledgerhq__hw-transport-webusb@npm:^4.70.1":
version: 4.70.1
resolution: "@types/ledgerhq__hw-transport-webusb@npm:4.70.1"
dependencies:
"@types/ledgerhq__hw-transport": "*"
"@types/node": "*"
checksum: 4e233ba9e18bb4605f397e4e286904b5e51836007bdb8aeb35f1af5bfcf7df809d005ec9c6f5f58af79e0ad9aa1a1ede65d61401fbd2cbb6e1e3496b3bf7a2a6
languageName: node
linkType: hard
"@types/ledgerhq__hw-transport@npm:*":
version: 4.21.3
resolution: "@types/ledgerhq__hw-transport@npm:4.21.3"
dependencies:
"@types/node": "*"
checksum: ca61594c52ab559a2a15fd4e3b60e5e46d9d1075a734544e5238f01618b5fcbafaec85dafae310e882658b012454ed818a124cbaba6a6b29ba96bc0ca09de326
languageName: node
linkType: hard
"@types/minimatch@npm:*":
version: 3.0.3
resolution: "@types/minimatch@npm:3.0.3"
@@ -2918,15 +2886,6 @@ __metadata:
languageName: node
linkType: hard
"@types/node-hid@npm:*":
version: 1.3.0
resolution: "@types/node-hid@npm:1.3.0"
dependencies:
"@types/node": "*"
checksum: 7ad8f010c0f1aa23b09e820d69d5068077c20277622b9e33ccaab06b0bf29b37928ce4d0c64046615f93c382d5f2cd211a20b9c955c56679271dacfa52ef026d
languageName: node
linkType: hard
"@types/node@npm:*":
version: 14.14.19
resolution: "@types/node@npm:14.14.19"
@@ -6958,12 +6917,12 @@ __metadata:
dependencies:
"@babel/core": ^7.12.10
"@babel/runtime": ^7.12.5
"@polkadot/keyring": ^5.2.4-4
"@polkadot/keyring": ^5.2.4-6
"@polkadot/reactnative-identicon": 0.65.2-4
"@polkadot/ui-keyring": 0.65.2-4
"@polkadot/ui-settings": 0.65.2-4
"@polkadot/util": ^5.2.4-4
"@polkadot/util-crypto": ^5.2.4-4
"@polkadot/util": ^5.2.4-6
"@polkadot/util-crypto": ^5.2.4-6
"@react-native-community/async-storage": ^1.12.1
"@react-native-community/cli-platform-ios": ^4.13.0
"@types/react-test-renderer": 17.0.0