@prosopo/account 0.3.1 → 0.3.3
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/cjs/extension/ExtensionWeb3.cjs +29 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/util/dist/index.cjs +1 -0
- package/dist/cjs/util/dist/util.cjs +8 -0
- package/dist/extension/ExtensionWeb2.d.ts +2 -2
- package/dist/extension/ExtensionWeb3.d.ts +6 -0
- package/dist/extension/ExtensionWeb3.d.ts.map +1 -0
- package/dist/extension/ExtensionWeb3.js +26 -0
- package/dist/extension/ExtensionWeb3.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/vite.cjs.config.ts +13 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Extension = require("./Extension.cjs");
|
|
4
|
+
require("../common/dist/index.cjs");
|
|
5
|
+
const extensionDapp = require("@polkadot/extension-dapp");
|
|
6
|
+
const error = require("../common/dist/error.cjs");
|
|
7
|
+
class ExtensionWeb3 extends Extension.Extension {
|
|
8
|
+
async getAccount(config) {
|
|
9
|
+
const { dappName, userAccountAddress: address } = config;
|
|
10
|
+
if (!address) {
|
|
11
|
+
throw new error.ProsopoError("WIDGET.NO_ACCOUNTS_FOUND", { context: { error: "No account address provided" } });
|
|
12
|
+
}
|
|
13
|
+
const extensions = await extensionDapp.web3Enable(dappName);
|
|
14
|
+
if (extensions.length === 0) {
|
|
15
|
+
throw new error.ProsopoError("WIDGET.NO_EXTENSION_FOUND");
|
|
16
|
+
}
|
|
17
|
+
for (const extension of extensions) {
|
|
18
|
+
const accounts = await extension.accounts.get();
|
|
19
|
+
const account = accounts.find((account2) => account2.address === address);
|
|
20
|
+
if (account) {
|
|
21
|
+
return { account, extension };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
throw new error.ProsopoError("WIDGET.ACCOUNT_NOT_FOUND", {
|
|
25
|
+
context: { error: `No account found matching ${address}` }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ExtensionWeb3 = ExtensionWeb3;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const Extension = require("./extension/Extension.cjs");
|
|
4
4
|
const ExtensionWeb2 = require("./extension/ExtensionWeb2.cjs");
|
|
5
|
+
const ExtensionWeb3 = require("./extension/ExtensionWeb3.cjs");
|
|
5
6
|
exports.Extension = Extension.Extension;
|
|
6
7
|
exports.ExtensionWeb2 = ExtensionWeb2.ExtensionWeb2;
|
|
8
|
+
exports.ExtensionWeb3 = ExtensionWeb3.ExtensionWeb3;
|
|
@@ -10,6 +10,7 @@ exports.at = util.at;
|
|
|
10
10
|
exports.flattenObj = util.flattenObj;
|
|
11
11
|
exports.get = util.get;
|
|
12
12
|
exports.getCurrentFileDirectory = util.getCurrentFileDirectory;
|
|
13
|
+
exports.hashToHex = util.hashToHex;
|
|
13
14
|
exports.isArray = util.isArray;
|
|
14
15
|
exports.isObject = util.isObject;
|
|
15
16
|
exports.kebabCase = util.kebabCase;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const util = require("@polkadot/util");
|
|
3
4
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
5
|
function* permutations(bins, options) {
|
|
5
6
|
if (options?.includeEmpty) {
|
|
@@ -141,10 +142,17 @@ const isArray = (value) => {
|
|
|
141
142
|
const isObject = (value) => {
|
|
142
143
|
return value instanceof Object && !isArray(value);
|
|
143
144
|
};
|
|
145
|
+
const hashToHex = (hash) => {
|
|
146
|
+
if (isArray(hash)) {
|
|
147
|
+
return util.u8aToHex(new Uint8Array(hash));
|
|
148
|
+
}
|
|
149
|
+
return hash.toString();
|
|
150
|
+
};
|
|
144
151
|
exports.at = at;
|
|
145
152
|
exports.flattenObj = flattenObj;
|
|
146
153
|
exports.get = get;
|
|
147
154
|
exports.getCurrentFileDirectory = getCurrentFileDirectory;
|
|
155
|
+
exports.hashToHex = hashToHex;
|
|
148
156
|
exports.isArray = isArray;
|
|
149
157
|
exports.isObject = isObject;
|
|
150
158
|
exports.kebabCase = kebabCase;
|
|
@@ -6,11 +6,11 @@ export declare class ExtensionWeb2 extends Extension {
|
|
|
6
6
|
private createAccount;
|
|
7
7
|
private getFingerprint;
|
|
8
8
|
getNetwork: (config: ProcaptchaClientConfigOutput) => {
|
|
9
|
-
endpoint: string;
|
|
10
9
|
contract: {
|
|
11
|
-
address: string;
|
|
12
10
|
name: string;
|
|
11
|
+
address: string;
|
|
13
12
|
};
|
|
13
|
+
endpoint: string;
|
|
14
14
|
pairType: "ed25519" | "sr25519" | "ecdsa" | "ethereum";
|
|
15
15
|
ss58Format: number;
|
|
16
16
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Account, ProcaptchaClientConfigOutput } from '@prosopo/types';
|
|
2
|
+
import { Extension } from './Extension.js';
|
|
3
|
+
export declare class ExtensionWeb3 extends Extension {
|
|
4
|
+
getAccount(config: ProcaptchaClientConfigOutput): Promise<Account>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ExtensionWeb3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionWeb3.d.ts","sourceRoot":"","sources":["../../src/extension/ExtensionWeb3.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAQ1C,qBAAa,aAAc,SAAQ,SAAS;IAC3B,UAAU,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;CA0BlF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Extension } from './Extension.js';
|
|
2
|
+
import { ProsopoError } from '@prosopo/common';
|
|
3
|
+
import { web3Enable } from '@polkadot/extension-dapp';
|
|
4
|
+
export class ExtensionWeb3 extends Extension {
|
|
5
|
+
async getAccount(config) {
|
|
6
|
+
const { dappName, userAccountAddress: address } = config;
|
|
7
|
+
if (!address) {
|
|
8
|
+
throw new ProsopoError('WIDGET.NO_ACCOUNTS_FOUND', { context: { error: 'No account address provided' } });
|
|
9
|
+
}
|
|
10
|
+
const extensions = await web3Enable(dappName);
|
|
11
|
+
if (extensions.length === 0) {
|
|
12
|
+
throw new ProsopoError('WIDGET.NO_EXTENSION_FOUND');
|
|
13
|
+
}
|
|
14
|
+
for (const extension of extensions) {
|
|
15
|
+
const accounts = await extension.accounts.get();
|
|
16
|
+
const account = accounts.find((account) => account.address === address);
|
|
17
|
+
if (account) {
|
|
18
|
+
return { account, extension };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw new ProsopoError('WIDGET.ACCOUNT_NOT_FOUND', {
|
|
22
|
+
context: { error: `No account found matching ${address}` },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ExtensionWeb3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionWeb3.js","sourceRoot":"","sources":["../../src/extension/ExtensionWeb3.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAKrD,MAAM,OAAO,aAAc,SAAQ,SAAS;IACjC,KAAK,CAAC,UAAU,CAAC,MAAoC;QACxD,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;QAExD,IAAI,CAAC,OAAO,EAAE;YACV,MAAM,IAAI,YAAY,CAAC,0BAA0B,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,6BAA6B,EAAE,EAAE,CAAC,CAAA;SAC5G;QAGD,MAAM,UAAU,GAAwB,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAA;QAClE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM,IAAI,YAAY,CAAC,2BAA2B,CAAC,CAAA;SACtD;QAGD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAChC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;YAC/C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;YACvE,IAAI,OAAO,EAAE;gBACT,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;aAChC;SACJ;QAED,MAAM,IAAI,YAAY,CAAC,0BAA0B,EAAE;YAC/C,OAAO,EAAE,EAAE,KAAK,EAAE,6BAA6B,OAAO,EAAE,EAAE;SAC7D,CAAC,CAAA;IACN,CAAC;CACJ"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/account",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Services and Utils for Prosopo account gen and management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"@polkadot/rpc-provider": "10.11.2",
|
|
46
46
|
"@polkadot/util": "12.6.2",
|
|
47
47
|
"@polkadot/util-crypto": "12.6.2",
|
|
48
|
-
"@prosopo/common": "0.3.
|
|
49
|
-
"@prosopo/types": "0.3.
|
|
50
|
-
"@prosopo/util": "0.3.
|
|
48
|
+
"@prosopo/common": "0.3.3",
|
|
49
|
+
"@prosopo/types": "0.3.3",
|
|
50
|
+
"@prosopo/util": "0.3.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@prosopo/config": "0.3.
|
|
53
|
+
"@prosopo/config": "0.3.3",
|
|
54
54
|
"tslib": "2.6.2",
|
|
55
55
|
"typescript": "5.1.6"
|
|
56
56
|
},
|
package/vite.cjs.config.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Copyright 2021-2024 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.
|
|
1
14
|
import { ViteCommonJSConfig } from '@prosopo/config'
|
|
2
15
|
import path from 'path'
|
|
3
16
|
|