|
1 | | -import assert from "node:assert"; |
| 1 | +import assert, { fail } from "node:assert"; |
2 | 2 | import test from "node:test"; |
3 | 3 |
|
4 | 4 | import { EllipticPoint } from "@tkey/common-types"; |
@@ -166,8 +166,40 @@ variable.forEach((testVariable) => { |
166 | 166 | const signature2 = sigToRSV(await coreKitInstance.sign(msgBuffer)); |
167 | 167 | const pubkey2 = secp256k1.recoverPubKey(msgHash, signature2, signature2.v) as EllipticPoint; |
168 | 168 | assert(pubkey2.eq(publicKeyPoint)); |
| 169 | + |
| 170 | + // should fail to sign due to preSignValidation |
| 171 | + { |
| 172 | + coreKitInstance.setPreSigningValidator(async ({ data }) => { |
| 173 | + return { |
| 174 | + success: false, |
| 175 | + data: Buffer.from(data).toString("hex") |
| 176 | + } |
| 177 | + }); |
| 178 | + |
| 179 | + try { |
| 180 | + await coreKitInstance.sign(msgHash, true); |
| 181 | + fail("Should fail signing") |
| 182 | + } catch (err) { |
| 183 | + assert(err); |
| 184 | + } |
| 185 | + }; |
| 186 | + |
| 187 | + // should succeed to sign |
| 188 | + { |
| 189 | + coreKitInstance.setPreSigningValidator(async ({ data }) => { |
| 190 | + return { |
| 191 | + success: true, |
| 192 | + data: Buffer.from(data).toString("hex") |
| 193 | + } |
| 194 | + }); |
| 195 | + const signature = sigToRSV(await coreKitInstance.sign(msgHash, true)); |
| 196 | + const pubkey = secp256k1.recoverPubKey(msgHash, signature, signature.v) as EllipticPoint; |
| 197 | + const publicKeyPoint = bufferToElliptic(coreKitInstance.getPubKey()); |
| 198 | + assert(pubkey.eq(publicKeyPoint)); |
| 199 | + }; |
169 | 200 | }); |
170 | 201 |
|
| 202 | + |
171 | 203 | await t.test("#Login and sign with different account/wallet index", async function () { |
172 | 204 | const vid = stringGen(10); |
173 | 205 | const coreKitInstance = newCoreKitInstance(); |
|
0 commit comments