@parity/product-sdk-signer 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -2
- package/dist/index.js +14 -691
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +12 -0
- package/src/providers/dev.ts +1 -0
- package/src/providers/host.ts +7 -7
package/src/index.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @parity/product-sdk-signer — Account connection and signing, decoupled from where the keys actually live.
|
|
3
|
+
*
|
|
4
|
+
* `SignerManager` wraps one or more `SignerProvider` implementations behind a
|
|
5
|
+
* `Result`-typed API for connecting, listing accounts, and reacting to status or
|
|
6
|
+
* account changes. The two built-in providers — `HostProvider` (Polkadot
|
|
7
|
+
* Desktop/Mobile) and `DevProvider` (the well-known Alice/Bob accounts) — let
|
|
8
|
+
* the same call sites work in production and in tests.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
// Core manager
|
|
2
14
|
export { SignerManager } from "./signer-manager.js";
|
|
3
15
|
|
package/src/providers/dev.ts
CHANGED
|
@@ -14,6 +14,7 @@ const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely
|
|
|
14
14
|
/** Standard Substrate dev account names. */
|
|
15
15
|
const DEFAULT_DEV_NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Ferdie"] as const;
|
|
16
16
|
|
|
17
|
+
/** A well-known Substrate development account name (Alice, Bob, …) used to derive deterministic dev accounts from the standard Substrate dev mnemonic. */
|
|
17
18
|
export type DevAccountName = (typeof DEFAULT_DEV_NAMES)[number];
|
|
18
19
|
|
|
19
20
|
/** Supported key types for dev account derivation. */
|
package/src/providers/host.ts
CHANGED
|
@@ -97,8 +97,8 @@ interface NeverthrowResultAsync<T, E> {
|
|
|
97
97
|
|
|
98
98
|
/** @internal */
|
|
99
99
|
export interface AccountsProvider {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
getLegacyAccounts: () => NeverthrowResultAsync<RawAccount[], unknown>;
|
|
101
|
+
getLegacyAccountSigner: (account: ProductAccount) => import("polkadot-api").PolkadotSigner;
|
|
102
102
|
getProductAccount: (
|
|
103
103
|
dotNsIdentifier: string,
|
|
104
104
|
derivationIndex?: number,
|
|
@@ -404,7 +404,7 @@ export class HostProvider implements SignerProvider {
|
|
|
404
404
|
// Step 3: Fetch non-product accounts
|
|
405
405
|
let rawAccounts: RawAccount[];
|
|
406
406
|
try {
|
|
407
|
-
rawAccounts = (await provider.
|
|
407
|
+
rawAccounts = (await provider.getLegacyAccounts().match(
|
|
408
408
|
(accounts) => accounts,
|
|
409
409
|
(error) => {
|
|
410
410
|
throw new Error(`Host rejected account request: ${formatError(error)}`);
|
|
@@ -487,7 +487,7 @@ export class HostProvider implements SignerProvider {
|
|
|
487
487
|
if (!this.accountsProvider) {
|
|
488
488
|
throw new Error("Host provider is disconnected");
|
|
489
489
|
}
|
|
490
|
-
return this.accountsProvider.
|
|
490
|
+
return this.accountsProvider.getLegacyAccountSigner({
|
|
491
491
|
dotNsIdentifier: "",
|
|
492
492
|
derivationIndex: 0,
|
|
493
493
|
publicKey: raw.publicKey,
|
|
@@ -527,7 +527,7 @@ if (import.meta.vitest) {
|
|
|
527
527
|
} as unknown as import("polkadot-api").PolkadotSigner;
|
|
528
528
|
|
|
529
529
|
return {
|
|
530
|
-
|
|
530
|
+
getLegacyAccounts: vi.fn().mockReturnValue({
|
|
531
531
|
match: async (
|
|
532
532
|
onOk: (v: RawAccountTest[]) => unknown,
|
|
533
533
|
onErr: (e: unknown) => unknown,
|
|
@@ -538,7 +538,7 @@ if (import.meta.vitest) {
|
|
|
538
538
|
return onOk(accounts);
|
|
539
539
|
},
|
|
540
540
|
}),
|
|
541
|
-
|
|
541
|
+
getLegacyAccountSigner: vi.fn().mockReturnValue(mockSigner),
|
|
542
542
|
getProductAccount: vi.fn().mockReturnValue({
|
|
543
543
|
match: async (
|
|
544
544
|
onOk: (v: RawAccountTest) => unknown,
|
|
@@ -622,7 +622,7 @@ if (import.meta.vitest) {
|
|
|
622
622
|
}
|
|
623
623
|
});
|
|
624
624
|
|
|
625
|
-
test("returns HOST_REJECTED when
|
|
625
|
+
test("returns HOST_REJECTED when getLegacyAccounts fails", async () => {
|
|
626
626
|
const mockProvider = createMockProvider({ shouldReject: true, error: "Rejected" });
|
|
627
627
|
const provider = new HostProvider({
|
|
628
628
|
maxRetries: 1,
|