@dfns/lib-solana 0.8.3 → 0.8.4-rc1
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 +66 -25
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -6,21 +6,6 @@ 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
|
-
};
|
|
24
9
|
class DfnsWallet {
|
|
25
10
|
constructor(metadata, options) {
|
|
26
11
|
this.metadata = metadata;
|
|
@@ -58,11 +43,23 @@ class DfnsWallet {
|
|
|
58
43
|
transaction: `0x${transaction.serialize({ verifySignatures: false }).toString('hex')}`,
|
|
59
44
|
},
|
|
60
45
|
});
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
let responseStatus = res.status;
|
|
47
|
+
let signedData = res.signedData;
|
|
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) {
|
|
63
60
|
throw new sdk_1.DfnsError(-1, 'signedData missing', res);
|
|
64
61
|
}
|
|
65
|
-
return web3_js_1.Transaction.from(hexToBuffer(
|
|
62
|
+
return web3_js_1.Transaction.from(hexToBuffer(signedData));
|
|
66
63
|
}
|
|
67
64
|
else {
|
|
68
65
|
const res = await this.dfnsClient.wallets.generateSignature({
|
|
@@ -72,8 +69,24 @@ class DfnsWallet {
|
|
|
72
69
|
message: `0x${transaction.serializeMessage().toString('hex')}`,
|
|
73
70
|
},
|
|
74
71
|
});
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
let responseStatus = res.status;
|
|
73
|
+
let signature = res.signature;
|
|
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)]));
|
|
77
90
|
return transaction;
|
|
78
91
|
}
|
|
79
92
|
}
|
|
@@ -86,11 +99,23 @@ class DfnsWallet {
|
|
|
86
99
|
transaction: `0x${Buffer.from(transaction.serialize()).toString('hex')}`,
|
|
87
100
|
},
|
|
88
101
|
});
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
let responseStatus = res.status;
|
|
103
|
+
let signedData = res.signedData;
|
|
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) {
|
|
91
116
|
throw new sdk_1.DfnsError(-1, 'signedData missing', res);
|
|
92
117
|
}
|
|
93
|
-
return web3_js_1.VersionedTransaction.deserialize(hexToBuffer(
|
|
118
|
+
return web3_js_1.VersionedTransaction.deserialize(hexToBuffer(signedData));
|
|
94
119
|
}
|
|
95
120
|
else {
|
|
96
121
|
const res = await this.dfnsClient.wallets.generateSignature({
|
|
@@ -100,8 +125,24 @@ class DfnsWallet {
|
|
|
100
125
|
message: `0x${Buffer.from(transaction.message.serialize()).toString('hex')}`,
|
|
101
126
|
},
|
|
102
127
|
});
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
let responseStatus = res.status;
|
|
129
|
+
let signature = res.signature;
|
|
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)]));
|
|
105
146
|
return transaction;
|
|
106
147
|
}
|
|
107
148
|
}
|
package/package.json
CHANGED