|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { base58btc } from "multiformats/bases/base58"; |
| 3 | +import { _testHelpers } from "./index"; |
| 4 | + |
| 5 | +describe("signature validator decoding", () => { |
| 6 | + it("decodes z-prefixed base58btc signatures", async () => { |
| 7 | + const bytes = new Uint8Array([1, 2, 3, 4, 5, 250, 251, 252, 253, 254, 255]); |
| 8 | + const multibaseSignature = base58btc.encode(bytes); // includes leading 'z' |
| 9 | + |
| 10 | + const decoded = await _testHelpers.decodeSignature(multibaseSignature); |
| 11 | + |
| 12 | + expect(decoded).toEqual(bytes); |
| 13 | + }); |
| 14 | + |
| 15 | + it("decodes z-prefixed base58btc public keys", async () => { |
| 16 | + const bytes = new Uint8Array([9, 8, 7, 6, 5, 4, 3, 2, 1]); |
| 17 | + const multibaseKey = base58btc.encode(bytes); // includes leading 'z' |
| 18 | + |
| 19 | + const decoded = await _testHelpers.decodeMultibasePublicKey(multibaseKey); |
| 20 | + |
| 21 | + expect(decoded).toEqual(bytes); |
| 22 | + }); |
| 23 | + |
| 24 | + it("decodes z-prefixed hex public keys", async () => { |
| 25 | + const hex = "0a0b0c0d0e0f"; |
| 26 | + const multibaseKey = `z${hex}`; |
| 27 | + |
| 28 | + const decoded = await _testHelpers.decodeMultibasePublicKey(multibaseKey); |
| 29 | + |
| 30 | + expect(decoded).toEqual(new Uint8Array([0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f])); |
| 31 | + }); |
| 32 | + |
| 33 | + it("decodes 0x-prefixed hex public keys", async () => { |
| 34 | + const hex = "3059301306072a8648ce3d020106082a8648ce3d03010703420004180f32e2d5b8dd2d87ce3a9a7ff84806f3526b84e4496a6ee5a5f458d323133377229791a5ef8dd2059c2ff2ceca1fa70e8069433ea126185268de4df42c4861"; |
| 35 | + const decoded = await _testHelpers.decodeMultibasePublicKey(`0x${hex}`); |
| 36 | + |
| 37 | + expect(decoded.byteLength).toBe(hex.length / 2); |
| 38 | + // spot-check first/last bytes |
| 39 | + expect(decoded[0]).toBe(0x30); |
| 40 | + expect(decoded[decoded.length - 1]).toBe(0x61); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
0 commit comments