@dfns/lib-concordium 0.8.12 → 0.8.14-beta-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/index.d.ts +2 -1
- package/index.js +35 -0
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DfnsApiClient } from '@dfns/sdk';
|
|
2
2
|
import { ActivateWalletResponse } from '@dfns/sdk/types/wallets';
|
|
3
|
-
import { AccountAddress } from '@concordium/web-sdk';
|
|
3
|
+
import { AccountAddress, Transaction } from '@concordium/web-sdk';
|
|
4
4
|
import { SerializedCredentialDeploymentDetails } from '@concordium/id-app-sdk';
|
|
5
5
|
export type DfnsWalletOptions = {
|
|
6
6
|
walletId: string;
|
|
@@ -17,6 +17,7 @@ export declare class DfnsWallet {
|
|
|
17
17
|
getAccountAddress(): AccountAddress.Type | undefined;
|
|
18
18
|
getPublicKey(): string;
|
|
19
19
|
getStatus(): string;
|
|
20
|
+
signTransaction(transaction: Transaction.Type): Promise<string>;
|
|
20
21
|
activate(cred: SerializedCredentialDeploymentDetails): Promise<ActivateWalletResponse>;
|
|
21
22
|
refresh(): Promise<void>;
|
|
22
23
|
}
|
package/index.js
CHANGED
|
@@ -3,6 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DfnsWallet = void 0;
|
|
4
4
|
const sdk_1 = require("@dfns/sdk");
|
|
5
5
|
const web_sdk_1 = require("@concordium/web-sdk");
|
|
6
|
+
const assertSigned = (res) => {
|
|
7
|
+
if (res.status === 'Failed') {
|
|
8
|
+
throw new sdk_1.DfnsError(-1, 'signing failed', res);
|
|
9
|
+
}
|
|
10
|
+
else if (res.status !== 'Signed') {
|
|
11
|
+
throw new sdk_1.DfnsError(-1, 'cannot complete signing synchronously because this wallet action requires policy approval', res);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
6
14
|
class DfnsWallet {
|
|
7
15
|
constructor(dfnsOptions, walletResponse) {
|
|
8
16
|
this.dfnsClient = dfnsOptions.dfnsClient;
|
|
@@ -34,6 +42,33 @@ class DfnsWallet {
|
|
|
34
42
|
getStatus() {
|
|
35
43
|
return this.status;
|
|
36
44
|
}
|
|
45
|
+
// We return the signature instead of a SignedTransaction to be flexible when it comes
|
|
46
|
+
// to MultiSig. We can't really know the CredentialId and the KeyId of a given sig,
|
|
47
|
+
// We let the client handle it.
|
|
48
|
+
async signTransaction(transaction) {
|
|
49
|
+
if (this.status !== 'Active') {
|
|
50
|
+
throw new sdk_1.DfnsError(-1, 'wallet is not active', {
|
|
51
|
+
walletId: this.walletId,
|
|
52
|
+
status: this.status,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (!web_sdk_1.Transaction.isSignable(transaction)) {
|
|
56
|
+
throw new sdk_1.DfnsError(-1, 'transaction is not signable', { transaction });
|
|
57
|
+
}
|
|
58
|
+
const res = await this.dfnsClient.wallets.generateSignature({
|
|
59
|
+
walletId: this.walletId,
|
|
60
|
+
body: {
|
|
61
|
+
kind: 'Transaction',
|
|
62
|
+
// take care of bigints
|
|
63
|
+
transaction: JSON.parse(web_sdk_1.Transaction.toJSONString(transaction)),
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
assertSigned(res);
|
|
67
|
+
if (!res.signature?.encoded) {
|
|
68
|
+
throw new sdk_1.DfnsError(-1, 'signature missing from response', res);
|
|
69
|
+
}
|
|
70
|
+
return res.signature.encoded;
|
|
71
|
+
}
|
|
37
72
|
async activate(cred) {
|
|
38
73
|
return this.dfnsClient.wallets.activateWallet({
|
|
39
74
|
walletId: this.walletId,
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfns/lib-concordium",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14-beta-1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@concordium/web-sdk": "12.0.0-alpha.3",
|
|
6
|
-
"@dfns/sdk": "0.8.
|
|
6
|
+
"@dfns/sdk": "0.8.14-beta-1"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@concordium/id-app-sdk": "0.1.4",
|