@dfns/lib-solana 0.8.4-rc1 → 0.8.5
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.js +25 -66
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -6,6 +6,21 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
6
6
|
const hexToBuffer = (hex) => {
|
|
7
7
|
return Buffer.from(hex.replace(/^0x/, ''), 'hex');
|
|
8
8
|
};
|
|
9
|
+
const assertSigned = (res) => {
|
|
10
|
+
if (res.status === 'Failed') {
|
|
11
|
+
throw new sdk_1.DfnsError(-1, 'signing failed', res);
|
|
12
|
+
}
|
|
13
|
+
else if (res.status !== 'Signed') {
|
|
14
|
+
throw new sdk_1.DfnsError(-1, 'cannot complete signing synchronously because this wallet action requires policy approval', res);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const combineSignature = (res) => {
|
|
18
|
+
if (!res.signature) {
|
|
19
|
+
throw new sdk_1.DfnsError(-1, 'signature missing', res);
|
|
20
|
+
}
|
|
21
|
+
const { r, s } = res.signature;
|
|
22
|
+
return Buffer.concat([hexToBuffer(r), hexToBuffer(s)]);
|
|
23
|
+
};
|
|
9
24
|
class DfnsWallet {
|
|
10
25
|
constructor(metadata, options) {
|
|
11
26
|
this.metadata = metadata;
|
|
@@ -43,23 +58,11 @@ class DfnsWallet {
|
|
|
43
58
|
transaction: `0x${transaction.serialize({ verifySignatures: false }).toString('hex')}`,
|
|
44
59
|
},
|
|
45
60
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
while (!signedData && responseStatus != 'Failed') {
|
|
49
|
-
// Wait 10s before polling again
|
|
50
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
51
|
-
// Poll for signature if not immediately available
|
|
52
|
-
const getSig = await this.dfnsClient.wallets.getSignature({
|
|
53
|
-
walletId: this.metadata.id,
|
|
54
|
-
signatureId: res.id
|
|
55
|
-
});
|
|
56
|
-
responseStatus = getSig.status;
|
|
57
|
-
signedData = getSig.signedData;
|
|
58
|
-
}
|
|
59
|
-
if (!signedData) {
|
|
61
|
+
assertSigned(res);
|
|
62
|
+
if (!res.signedData) {
|
|
60
63
|
throw new sdk_1.DfnsError(-1, 'signedData missing', res);
|
|
61
64
|
}
|
|
62
|
-
return web3_js_1.Transaction.from(hexToBuffer(signedData));
|
|
65
|
+
return web3_js_1.Transaction.from(hexToBuffer(res.signedData));
|
|
63
66
|
}
|
|
64
67
|
else {
|
|
65
68
|
const res = await this.dfnsClient.wallets.generateSignature({
|
|
@@ -69,24 +72,8 @@ class DfnsWallet {
|
|
|
69
72
|
message: `0x${transaction.serializeMessage().toString('hex')}`,
|
|
70
73
|
},
|
|
71
74
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
while (!signature && responseStatus != 'Failed') {
|
|
75
|
-
// Wait 10s before polling again
|
|
76
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
77
|
-
// Poll for signature if not immediately available
|
|
78
|
-
const getSig = await this.dfnsClient.wallets.getSignature({
|
|
79
|
-
walletId: this.metadata.id,
|
|
80
|
-
signatureId: res.id
|
|
81
|
-
});
|
|
82
|
-
responseStatus = getSig.status;
|
|
83
|
-
signature = getSig.signature;
|
|
84
|
-
}
|
|
85
|
-
if (!signature) {
|
|
86
|
-
throw new sdk_1.DfnsError(-1, 'signature missing', res);
|
|
87
|
-
}
|
|
88
|
-
const { r, s } = signature;
|
|
89
|
-
transaction.addSignature(this.publicKey, Buffer.concat([hexToBuffer(r), hexToBuffer(s)]));
|
|
75
|
+
assertSigned(res);
|
|
76
|
+
transaction.addSignature(this.publicKey, combineSignature(res));
|
|
90
77
|
return transaction;
|
|
91
78
|
}
|
|
92
79
|
}
|
|
@@ -99,23 +86,11 @@ class DfnsWallet {
|
|
|
99
86
|
transaction: `0x${Buffer.from(transaction.serialize()).toString('hex')}`,
|
|
100
87
|
},
|
|
101
88
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
while (!signedData && responseStatus != 'Failed') {
|
|
105
|
-
// Wait 10s before polling again
|
|
106
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
107
|
-
// Poll for signature if not immediately available
|
|
108
|
-
const getSig = await this.dfnsClient.wallets.getSignature({
|
|
109
|
-
walletId: this.metadata.id,
|
|
110
|
-
signatureId: res.id
|
|
111
|
-
});
|
|
112
|
-
responseStatus = getSig.status;
|
|
113
|
-
signedData = getSig.signedData;
|
|
114
|
-
}
|
|
115
|
-
if (!signedData) {
|
|
89
|
+
assertSigned(res);
|
|
90
|
+
if (!res.signedData) {
|
|
116
91
|
throw new sdk_1.DfnsError(-1, 'signedData missing', res);
|
|
117
92
|
}
|
|
118
|
-
return web3_js_1.VersionedTransaction.deserialize(hexToBuffer(signedData));
|
|
93
|
+
return web3_js_1.VersionedTransaction.deserialize(hexToBuffer(res.signedData));
|
|
119
94
|
}
|
|
120
95
|
else {
|
|
121
96
|
const res = await this.dfnsClient.wallets.generateSignature({
|
|
@@ -125,24 +100,8 @@ class DfnsWallet {
|
|
|
125
100
|
message: `0x${Buffer.from(transaction.message.serialize()).toString('hex')}`,
|
|
126
101
|
},
|
|
127
102
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
while (!signature && responseStatus != 'Failed') {
|
|
131
|
-
// Wait 10s before polling again
|
|
132
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
133
|
-
// Poll for signature if not immediately available
|
|
134
|
-
const getSig = await this.dfnsClient.wallets.getSignature({
|
|
135
|
-
walletId: this.metadata.id,
|
|
136
|
-
signatureId: res.id
|
|
137
|
-
});
|
|
138
|
-
responseStatus = getSig.status;
|
|
139
|
-
signature = getSig.signature;
|
|
140
|
-
}
|
|
141
|
-
if (!signature) {
|
|
142
|
-
throw new sdk_1.DfnsError(-1, 'signature missing', res);
|
|
143
|
-
}
|
|
144
|
-
const { r, s } = signature;
|
|
145
|
-
transaction.addSignature(this.publicKey, Buffer.concat([hexToBuffer(r), hexToBuffer(s)]));
|
|
103
|
+
assertSigned(res);
|
|
104
|
+
transaction.addSignature(this.publicKey, combineSignature(res));
|
|
146
105
|
return transaction;
|
|
147
106
|
}
|
|
148
107
|
}
|
package/package.json
CHANGED