@prosopo/keyring 2.10.0 → 2.10.1
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/.turbo/turbo-build$colon$cjs.log +2 -5
- package/.turbo/turbo-build$colon$tsc.log +11 -14
- package/.turbo/turbo-build.log +3 -9
- package/CHANGELOG.md +15 -0
- package/LICENSE +201 -0
- package/package.json +59 -60
- package/src/accounts/getPair.test.ts +0 -142
- package/src/accounts/getPair.ts +0 -63
- package/src/accounts/index.ts +0 -16
- package/src/accounts/mnemonic.test.ts +0 -103
- package/src/accounts/mnemonic.ts +0 -45
- package/src/accounts/testAccounts.test.ts +0 -102
- package/src/accounts/testAccounts.ts +0 -66
- package/src/index.ts +0 -16
- package/src/keyring/index.ts +0 -15
- package/src/keyring/keyring.test.ts +0 -373
- package/src/keyring/keyring.ts +0 -411
- package/src/keyring/pairs.test.ts +0 -133
- package/src/keyring/pairs.ts +0 -44
- package/src/keyring/testing.test.ts +0 -146
- package/src/keyring/testing.ts +0 -119
- package/src/keyring/testingPairs.ts +0 -61
- package/src/keyring.test-d.ts +0 -134
- package/src/pair/decode.spec.ts +0 -25
- package/src/pair/decode.ts +0 -64
- package/src/pair/defaults.ts +0 -22
- package/src/pair/encode.spec.ts +0 -30
- package/src/pair/encode.ts +0 -32
- package/src/pair/index.ts +0 -304
- package/src/pair/nobody.test.ts +0 -127
- package/src/pair/nobody.ts +0 -79
- package/src/pair/toJson.spec.ts +0 -46
- package/src/pair/toJson.ts +0 -28
- package/tsconfig.cjs.json +0 -30
- package/tsconfig.json +0 -33
- package/tsconfig.tsbuildinfo +0 -1
- package/tsconfig.types.json +0 -9
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import { u8aToHex } from "@polkadot/util";
|
|
16
|
-
import {
|
|
17
|
-
mnemonicToMiniSecret,
|
|
18
|
-
mnemonicValidate,
|
|
19
|
-
sr25519FromSeed,
|
|
20
|
-
} from "@prosopo/util-crypto";
|
|
21
|
-
import { describe, expect, it } from "vitest";
|
|
22
|
-
import { Keyring } from "../keyring/index.js";
|
|
23
|
-
import { generateMiniSecret, generateMnemonic } from "./mnemonic.js";
|
|
24
|
-
|
|
25
|
-
// Key derivation runs scrypt/pbkdf2 with production parameters and takes
|
|
26
|
-
// seconds per call, so these suites need more than the 10s default.
|
|
27
|
-
const SLOW = { timeout: 60000 };
|
|
28
|
-
|
|
29
|
-
describe("generateMnemonic", SLOW, () => {
|
|
30
|
-
it("returns a valid twelve word mnemonic and its address", async () => {
|
|
31
|
-
const [mnemonic, address] = await generateMnemonic();
|
|
32
|
-
expect(mnemonic.split(" ")).toHaveLength(12);
|
|
33
|
-
expect(mnemonicValidate(mnemonic)).toBe(true);
|
|
34
|
-
expect(address).toBe(new Keyring().addFromMnemonic(mnemonic).address);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("generates a fresh mnemonic each call", async () => {
|
|
38
|
-
// A repeated mnemonic would mean every generated account shares a key.
|
|
39
|
-
const [first] = await generateMnemonic();
|
|
40
|
-
const [second] = await generateMnemonic();
|
|
41
|
-
expect(second).not.toBe(first);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("adds the account to a keyring it is given", async () => {
|
|
45
|
-
const keyring = new Keyring();
|
|
46
|
-
const [, address] = await generateMnemonic(keyring);
|
|
47
|
-
expect(keyring.getPairs()).toHaveLength(1);
|
|
48
|
-
expect(keyring.getPair(address).address).toBe(address);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("uses a fresh keyring when none is passed, leaving no shared state", async () => {
|
|
52
|
-
const keyring = new Keyring();
|
|
53
|
-
await generateMnemonic();
|
|
54
|
-
expect(keyring.getPairs()).toEqual([]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("honours the requested pair type when it creates the keyring", async () => {
|
|
58
|
-
const [, address] = await generateMnemonic(undefined, "sr25519");
|
|
59
|
-
expect(typeof address).toBe("string");
|
|
60
|
-
await expect(generateMnemonic(undefined, "ed25519")).rejects.toThrow(
|
|
61
|
-
"Expected a keyring type of either 'sr25519'",
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("ignores the pair type when a keyring is supplied", async () => {
|
|
66
|
-
// The keyring already fixes the curve; the argument is only used to
|
|
67
|
-
// construct one, so an incompatible value must not throw here.
|
|
68
|
-
const keyring = new Keyring({ type: "sr25519" });
|
|
69
|
-
await expect(generateMnemonic(keyring, "ed25519")).resolves.toBeDefined();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("generateMiniSecret", SLOW, () => {
|
|
74
|
-
it("returns the 32 byte mini secret for the generated mnemonic", async () => {
|
|
75
|
-
const keyring = new Keyring();
|
|
76
|
-
const [secret, address] = await generateMiniSecret(keyring);
|
|
77
|
-
|
|
78
|
-
expect(secret).toHaveLength(32);
|
|
79
|
-
expect(u8aToHex(sr25519FromSeed(secret).publicKey)).toBe(
|
|
80
|
-
u8aToHex(keyring.getPair(address).publicKey),
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("derives the secret from the same mnemonic it registered", async () => {
|
|
85
|
-
const keyring = new Keyring();
|
|
86
|
-
const [secret] = await generateMiniSecret(keyring);
|
|
87
|
-
const registered = keyring.getPairs()[0];
|
|
88
|
-
expect(registered).toBeDefined();
|
|
89
|
-
expect(u8aToHex(secret)).not.toBe(u8aToHex(new Uint8Array(32)));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("agrees with mnemonicToMiniSecret for a known phrase", async () => {
|
|
93
|
-
const phrase =
|
|
94
|
-
"bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
|
95
|
-
expect(u8aToHex(mnemonicToMiniSecret(phrase))).toHaveLength(66);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("generates a fresh secret each call", async () => {
|
|
99
|
-
const [first] = await generateMiniSecret();
|
|
100
|
-
const [second] = await generateMiniSecret();
|
|
101
|
-
expect(u8aToHex(second)).not.toBe(u8aToHex(first));
|
|
102
|
-
});
|
|
103
|
-
});
|
package/src/accounts/mnemonic.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import { mnemonicGenerate, mnemonicToMiniSecret } from "@prosopo/util-crypto";
|
|
16
|
-
import type { KeypairType } from "@prosopo/util-crypto";
|
|
17
|
-
import { Keyring } from "../keyring/keyring.js";
|
|
18
|
-
|
|
19
|
-
/** Generate a mnemonic, returning the mnemonic and associated address
|
|
20
|
-
* @param keyring
|
|
21
|
-
* @param pairType
|
|
22
|
-
*/
|
|
23
|
-
export async function generateMnemonic(
|
|
24
|
-
keyring?: Keyring,
|
|
25
|
-
pairType?: KeypairType,
|
|
26
|
-
): Promise<[string, string]> {
|
|
27
|
-
if (!keyring) {
|
|
28
|
-
keyring = new Keyring({ type: pairType || "sr25519" });
|
|
29
|
-
}
|
|
30
|
-
const mnemonic = mnemonicGenerate();
|
|
31
|
-
const account = keyring.addFromMnemonic(mnemonic);
|
|
32
|
-
return [mnemonic, account.address];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Generate a secret, returning the secret and associated address
|
|
36
|
-
* @param keyring
|
|
37
|
-
* @param pairType
|
|
38
|
-
*/
|
|
39
|
-
export async function generateMiniSecret(
|
|
40
|
-
keyring?: Keyring,
|
|
41
|
-
pairType?: KeypairType,
|
|
42
|
-
): Promise<[Uint8Array, string]> {
|
|
43
|
-
const [mnemonic, address] = await generateMnemonic(keyring, pairType);
|
|
44
|
-
return [mnemonicToMiniSecret(mnemonic), address];
|
|
45
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
import { CaptchaType } from "@prosopo/types";
|
|
16
|
-
import { describe, expect, it } from "vitest";
|
|
17
|
-
import { DEV_PHRASE } from "../keyring/index.js";
|
|
18
|
-
import { getPair } from "./getPair.js";
|
|
19
|
-
import { getDefaultProviders, getDefaultSiteKeys } from "./testAccounts.js";
|
|
20
|
-
|
|
21
|
-
// Key derivation runs scrypt/pbkdf2 with production parameters and takes
|
|
22
|
-
// seconds per call, so these suites need more than the 10s default.
|
|
23
|
-
const SLOW = { timeout: 60000 };
|
|
24
|
-
|
|
25
|
-
describe("getDefaultSiteKeys", SLOW, () => {
|
|
26
|
-
it("provides one site per captcha type, in a stable order", () => {
|
|
27
|
-
expect(
|
|
28
|
-
getDefaultSiteKeys().map((site) => site.settings.captchaType),
|
|
29
|
-
).toEqual([
|
|
30
|
-
CaptchaType.image,
|
|
31
|
-
CaptchaType.pow,
|
|
32
|
-
CaptchaType.frictionless,
|
|
33
|
-
CaptchaType.puzzle,
|
|
34
|
-
]);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("derives each site key from the dev phrase and its captcha type", () => {
|
|
38
|
-
// The seeded dev site keys are checked into fixtures and referenced by
|
|
39
|
-
// the demos, so the derivation must not drift.
|
|
40
|
-
for (const site of getDefaultSiteKeys()) {
|
|
41
|
-
expect(site.secret).toBe(`${DEV_PHRASE}//${site.settings.captchaType}`);
|
|
42
|
-
expect(site.address).toBe(getPair(site.secret).address);
|
|
43
|
-
expect(site.pair?.address).toBe(site.address);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("gives every site a distinct address", () => {
|
|
48
|
-
const addresses = getDefaultSiteKeys().map((site) => site.address);
|
|
49
|
-
expect(new Set(addresses).size).toBe(addresses.length);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("writes the settings explicitly rather than leaning on schema defaults", () => {
|
|
53
|
-
for (const site of getDefaultSiteKeys()) {
|
|
54
|
-
expect(site.settings.domains).toEqual(["localhost"]);
|
|
55
|
-
expect(site.settings.imageMaxRounds).toBe(2);
|
|
56
|
-
expect(
|
|
57
|
-
site.settings.frictionlessThreshold.frictionlessPuzzleThreshold,
|
|
58
|
-
).toBe(0.8);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("returns a fresh array each call, so callers cannot corrupt the seed", () => {
|
|
63
|
-
const first = getDefaultSiteKeys();
|
|
64
|
-
const second = getDefaultSiteKeys();
|
|
65
|
-
expect(first).not.toBe(second);
|
|
66
|
-
first.pop();
|
|
67
|
-
expect(second).toHaveLength(4);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("getDefaultProviders", SLOW, () => {
|
|
72
|
-
it("provides a single local provider with a matching pair and address", () => {
|
|
73
|
-
const providers = getDefaultProviders();
|
|
74
|
-
expect(providers).toHaveLength(1);
|
|
75
|
-
const provider = providers[0];
|
|
76
|
-
expect(provider).toBeDefined();
|
|
77
|
-
if (!provider) return;
|
|
78
|
-
expect(provider.url).toBe("https://localhost:9229");
|
|
79
|
-
expect(provider.address).toBe(provider.pair?.address);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("points at the checked-in dev dataset", () => {
|
|
83
|
-
const provider = getDefaultProviders()[0];
|
|
84
|
-
expect(provider?.datasetFile).toBe("./dev/data/captchas.json");
|
|
85
|
-
expect(provider?.captchaDatasetId).toMatch(/^0x[0-9a-f]{64}$/);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("is deterministic across calls", () => {
|
|
89
|
-
expect(getDefaultProviders()[0]?.address).toBe(
|
|
90
|
-
getDefaultProviders()[0]?.address,
|
|
91
|
-
);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("does not reuse a site key as the provider key", () => {
|
|
95
|
-
const siteAddresses = new Set(
|
|
96
|
-
getDefaultSiteKeys().map((site) => site.address),
|
|
97
|
-
);
|
|
98
|
-
expect(siteAddresses.has(getDefaultProviders()[0]?.address ?? "")).toBe(
|
|
99
|
-
false,
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
//sr25519 dev site keys
|
|
15
|
-
import {
|
|
16
|
-
CaptchaType,
|
|
17
|
-
ClientSettingsSchema,
|
|
18
|
-
type IProviderAccount,
|
|
19
|
-
type ISite,
|
|
20
|
-
} from "@prosopo/types";
|
|
21
|
-
import { DEV_PHRASE } from "../keyring/index.js";
|
|
22
|
-
import { getPair } from "./getPair.js";
|
|
23
|
-
|
|
24
|
-
export function getDefaultSiteKeys(): ISite[] {
|
|
25
|
-
const captchaTypes = [
|
|
26
|
-
CaptchaType.image,
|
|
27
|
-
CaptchaType.pow,
|
|
28
|
-
CaptchaType.frictionless,
|
|
29
|
-
CaptchaType.puzzle,
|
|
30
|
-
];
|
|
31
|
-
const sites: ISite[] = [];
|
|
32
|
-
for (const captchaType of captchaTypes) {
|
|
33
|
-
const secret = `${DEV_PHRASE}//${captchaType}`;
|
|
34
|
-
const pair = getPair(secret);
|
|
35
|
-
// Settings are written explicitly rather than relying on schema defaults
|
|
36
|
-
// so dev seeds are self-describing and stay stable when defaults change.
|
|
37
|
-
sites.push({
|
|
38
|
-
pair: pair,
|
|
39
|
-
address: pair.address,
|
|
40
|
-
secret: secret,
|
|
41
|
-
settings: ClientSettingsSchema.parse({
|
|
42
|
-
captchaType: captchaType,
|
|
43
|
-
domains: ["localhost"],
|
|
44
|
-
imageMaxRounds: 2,
|
|
45
|
-
frictionlessThreshold: 0.8,
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return sites;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getDefaultProviders(): IProviderAccount[] {
|
|
53
|
-
const pair = getPair(
|
|
54
|
-
"puppy cream effort carbon despair leg pyramid cotton endorse immense drill peasant",
|
|
55
|
-
);
|
|
56
|
-
return [
|
|
57
|
-
{
|
|
58
|
-
url: "https://localhost:9229",
|
|
59
|
-
pair: pair,
|
|
60
|
-
address: pair.address,
|
|
61
|
-
datasetFile: "./dev/data/captchas.json",
|
|
62
|
-
captchaDatasetId:
|
|
63
|
-
"0x3e067b8f6aeae82fdbe2b2557b9c2d90aaabff241df651bf0f36667d2ab0018d",
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
export * from "./accounts/index.js";
|
|
15
|
-
export * from "./keyring/index.js";
|
|
16
|
-
export * from "./pair/index.js";
|
package/src/keyring/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
export * from "./keyring.js";
|
|
15
|
-
export * from "./pairs.js";
|