@dfns/lib-concordium 0.8.6
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/index.d.ts +22 -0
- package/index.js +50 -0
- package/package.json +15 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DfnsApiClient } from '@dfns/sdk';
|
|
2
|
+
import { ActivateWalletResponse } from '@dfns/sdk/types/wallets';
|
|
3
|
+
import { AccountAddress } from '@concordium/web-sdk';
|
|
4
|
+
import { SerializedCredentialDeploymentDetails } from '@concordium/id-app-sdk';
|
|
5
|
+
export type DfnsWalletOptions = {
|
|
6
|
+
walletId: string;
|
|
7
|
+
dfnsClient: DfnsApiClient;
|
|
8
|
+
};
|
|
9
|
+
export declare class DfnsWallet {
|
|
10
|
+
private readonly dfnsClient;
|
|
11
|
+
private readonly walletId;
|
|
12
|
+
private status;
|
|
13
|
+
private address?;
|
|
14
|
+
private publicKey;
|
|
15
|
+
private constructor();
|
|
16
|
+
static init(options: DfnsWalletOptions): Promise<DfnsWallet>;
|
|
17
|
+
getAccountAddress(): AccountAddress.Type | undefined;
|
|
18
|
+
getPublicKey(): string;
|
|
19
|
+
getStatus(): string;
|
|
20
|
+
activate(cred: SerializedCredentialDeploymentDetails): Promise<ActivateWalletResponse>;
|
|
21
|
+
refresh(): Promise<void>;
|
|
22
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DfnsWallet = void 0;
|
|
4
|
+
const sdk_1 = require("@dfns/sdk");
|
|
5
|
+
const web_sdk_1 = require("@concordium/web-sdk");
|
|
6
|
+
class DfnsWallet {
|
|
7
|
+
constructor(dfnsOptions, walletResponse) {
|
|
8
|
+
this.dfnsClient = dfnsOptions.dfnsClient;
|
|
9
|
+
this.walletId = dfnsOptions.walletId;
|
|
10
|
+
this.status = walletResponse.status;
|
|
11
|
+
this.address = walletResponse.address;
|
|
12
|
+
this.publicKey = walletResponse.signingKey.publicKey;
|
|
13
|
+
}
|
|
14
|
+
static async init(options) {
|
|
15
|
+
const { walletId, dfnsClient } = options;
|
|
16
|
+
const res = await dfnsClient.wallets.getWallet({ walletId });
|
|
17
|
+
if (res.network !== 'Concordium' && res.network !== 'ConcordiumTestnet') {
|
|
18
|
+
throw new sdk_1.DfnsError(-1, 'wallet is not bound to a Concordium network', {
|
|
19
|
+
walletId,
|
|
20
|
+
network: res.network,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return new DfnsWallet(options, res);
|
|
24
|
+
}
|
|
25
|
+
getAccountAddress() {
|
|
26
|
+
if (this.status !== 'Active') {
|
|
27
|
+
throw new sdk_1.DfnsError(-1, 'wallet is not active', { walletId: this.walletId, status: this.status });
|
|
28
|
+
}
|
|
29
|
+
return this.address ? web_sdk_1.AccountAddress.fromBase58(this.address) : undefined;
|
|
30
|
+
}
|
|
31
|
+
getPublicKey() {
|
|
32
|
+
return this.publicKey;
|
|
33
|
+
}
|
|
34
|
+
getStatus() {
|
|
35
|
+
return this.status;
|
|
36
|
+
}
|
|
37
|
+
async activate(cred) {
|
|
38
|
+
return this.dfnsClient.wallets.activateWallet({
|
|
39
|
+
walletId: this.walletId,
|
|
40
|
+
body: cred
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async refresh() {
|
|
44
|
+
const res = await this.dfnsClient.wallets.getWallet({ walletId: this.walletId });
|
|
45
|
+
this.status = res.status;
|
|
46
|
+
this.address = res.address;
|
|
47
|
+
this.publicKey = res.signingKey.publicKey;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.DfnsWallet = DfnsWallet;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dfns/lib-concordium",
|
|
3
|
+
"version": "0.8.6",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@concordium/web-sdk": "12.0.0-alpha.3",
|
|
6
|
+
"@dfns/sdk": "0.8.6"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@concordium/id-app-sdk": "0.1.4",
|
|
10
|
+
"buffer": "^6.0.3",
|
|
11
|
+
"cross-fetch": "^3.1.6"
|
|
12
|
+
},
|
|
13
|
+
"main": "./index.js",
|
|
14
|
+
"type": "commonjs"
|
|
15
|
+
}
|