@prosopo/keyring 2.3.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.
@@ -0,0 +1,6 @@
1
+ import type { KeyringPair, KeyringPair$Json } from "@polkadot/keyring/types";
2
+ import type { KeypairType } from "@polkadot/util-crypto/types";
3
+ import type { PolkadotSecretJSON } from "@prosopo/types";
4
+ export declare function getPairAsync(secret?: string | KeyringPair$Json | PolkadotSecretJSON, account?: string | Uint8Array, pairType?: KeypairType, ss58Format?: number): Promise<KeyringPair>;
5
+ export declare function getPair(secret?: string | KeyringPair$Json | PolkadotSecretJSON, account?: string | Uint8Array, pairType?: KeypairType, ss58Format?: number): KeyringPair;
6
+ //# sourceMappingURL=getPair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPair.d.ts","sourceRoot":"","sources":["../../src/accounts/getPair.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,wBAAsB,YAAY,CACjC,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,kBAAkB,EACvD,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,EAC7B,QAAQ,CAAC,EAAE,WAAW,EACtB,UAAU,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,CAAC,CAGtB;AAED,wBAAgB,OAAO,CACtB,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,kBAAkB,EACvD,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,EAC7B,QAAQ,CAAC,EAAE,WAAW,EACtB,UAAU,CAAC,EAAE,MAAM,GACjB,WAAW,CAkCb"}
@@ -0,0 +1,47 @@
1
+ import { Keyring } from "@polkadot/keyring";
2
+ import { cryptoWaitReady } from "@polkadot/util-crypto";
3
+ import { mnemonicValidate } from "@polkadot/util-crypto/mnemonic";
4
+ import { hexToU8a } from "@polkadot/util/hex";
5
+ import { isHex } from "@polkadot/util/is";
6
+ import { ProsopoEnvError } from "@prosopo/common";
7
+ export async function getPairAsync(secret, account, pairType, ss58Format) {
8
+ await cryptoWaitReady();
9
+ return getPair(secret, account, pairType, ss58Format);
10
+ }
11
+ export function getPair(secret, account, pairType, ss58Format) {
12
+ pairType = pairType || "sr25519";
13
+ ss58Format = ss58Format || 42;
14
+ const keyring = new Keyring({ type: pairType, ss58Format });
15
+ if (!secret && account) {
16
+ return keyring.addFromAddress(account);
17
+ }
18
+ if (secret && typeof secret === "string") {
19
+ if (mnemonicValidate(secret)) {
20
+ return keyring.addFromMnemonic(secret);
21
+ }
22
+ if (isHex(secret)) {
23
+ return keyring.addFromSeed(hexToU8a(secret));
24
+ }
25
+ if (secret.startsWith("//")) {
26
+ return keyring.addFromUri(secret);
27
+ }
28
+ try {
29
+ const json = JSON.parse(secret);
30
+ const { encoding: { content }, } = json;
31
+ const keyring = new Keyring({ type: content[1], ss58Format });
32
+ return keyring.addFromJson(json);
33
+ }
34
+ catch (e) {
35
+ throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED", {
36
+ context: { error: e },
37
+ });
38
+ }
39
+ }
40
+ else if (typeof secret === "object") {
41
+ return keyring.addFromJson(secret);
42
+ }
43
+ else {
44
+ throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
45
+ }
46
+ }
47
+ //# sourceMappingURL=getPair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPair.js","sourceRoot":"","sources":["../../src/accounts/getPair.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,C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,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAChC,MAAM,EACL,QAAQ,EAAE,EAAE,OAAO,EAAE,GACrB,GAAG,IAAI,CAAC;YACT,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9D,OAAO,OAAO,CAAC,WAAW,CAAC,IAAwB,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,MAAM,IAAI,eAAe,CAAC,6BAA6B,EAAE;gBACxD,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;aACrB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,WAAW,CAAC,MAA0B,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,eAAe,CAAC,6BAA6B,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./mnemonic.js";
2
+ export * from "./getPair.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./mnemonic.js";
2
+ export * from "./getPair.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Keyring } from "@polkadot/keyring";
2
+ import type { KeypairType } from "@polkadot/util-crypto/types";
3
+ export declare function generateMnemonic(keyring?: Keyring, pairType?: KeypairType): Promise<[string, string]>;
4
+ export declare function generateMiniSecret(keyring?: Keyring, pairType?: KeypairType): Promise<[Uint8Array, string]>;
5
+ //# sourceMappingURL=mnemonic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mnemonic.d.ts","sourceRoot":"","sources":["../../src/accounts/mnemonic.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAM5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAM/D,wBAAsB,gBAAgB,CACrC,OAAO,CAAC,EAAE,OAAO,EACjB,QAAQ,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQ3B;AAMD,wBAAsB,kBAAkB,CACvC,OAAO,CAAC,EAAE,OAAO,EACjB,QAAQ,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAG/B"}
@@ -0,0 +1,17 @@
1
+ import { Keyring } from "@polkadot/keyring";
2
+ import { cryptoWaitReady } from "@polkadot/util-crypto";
3
+ import { mnemonicGenerate, mnemonicToMiniSecret, } from "@polkadot/util-crypto/mnemonic";
4
+ export async function generateMnemonic(keyring, pairType) {
5
+ if (!keyring) {
6
+ keyring = new Keyring({ type: pairType || "sr25519" });
7
+ }
8
+ await cryptoWaitReady();
9
+ const mnemonic = mnemonicGenerate();
10
+ const account = keyring.addFromMnemonic(mnemonic);
11
+ return [mnemonic, account.address];
12
+ }
13
+ export async function generateMiniSecret(keyring, pairType) {
14
+ const [mnemonic, address] = await generateMnemonic(keyring, pairType);
15
+ return [mnemonicToMiniSecret(mnemonic), address];
16
+ }
17
+ //# sourceMappingURL=mnemonic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mnemonic.js","sourceRoot":"","sources":["../../src/accounts/mnemonic.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAOxC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,OAAiB,EACjB,QAAsB;IAEtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,IAAI,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,eAAe,EAAE,CAAC;IACxB,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAMD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,OAAiB,EACjB,QAAsB;IAEtB,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtE,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./accounts/index.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./accounts/index.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@prosopo/keyring",
3
+ "version": "2.3.1",
4
+ "description": "Keypair generator for Prosopo",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": "20",
9
+ "npm": ">=9"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/cjs/index.cjs"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "test": "echo \"No test specified\"",
19
+ "clean": "tsc --build --clean",
20
+ "build": "tsc --build --verbose",
21
+ "build:cjs": "npx vite --config vite.cjs.config.ts build"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+ssh://git@github.com/prosopo/types.git"
26
+ },
27
+ "author": "Prosopo Limited",
28
+ "license": "Apache-2.0",
29
+ "bugs": {
30
+ "url": "https://github.com/prosopo/captcha/issues"
31
+ },
32
+ "homepage": "https://github.com/prosopo/captcha#readme",
33
+ "dependencies": {
34
+ "@polkadot/keyring": "12.6.2",
35
+ "@polkadot/util": "12.6.2",
36
+ "@polkadot/util-crypto": "12.6.2",
37
+ "@prosopo/common": "2.3.1",
38
+ "@prosopo/types": "2.3.1"
39
+ },
40
+ "devDependencies": {
41
+ "@prosopo/config": "2.3.1",
42
+ "@vitest/coverage-v8": "2.1.1",
43
+ "concurrently": "9.0.1",
44
+ "del-cli": "6.0.0",
45
+ "npm-run-all": "2.1.0",
46
+ "tslib": "2.7.0",
47
+ "tsx": "4.19.1",
48
+ "typescript": "5.6.2",
49
+ "vite": "5.4.6",
50
+ "vitest": "2.1.1"
51
+ },
52
+ "sideEffects": false
53
+ }
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ import { ViteCommonJSConfig } from "@prosopo/config";
16
+
17
+ export default function () {
18
+ return ViteCommonJSConfig("util", path.resolve("./tsconfig.cjs.json"));
19
+ }