diff --git a/src/crypto.mjs b/src/crypto.mjs index 5f0bea4c37b85d34f04020f4f0aa25b257179c35..d0479396b657af888e925b075b8e84687c1f09d4 100644 --- a/src/crypto.mjs +++ b/src/crypto.mjs @@ -13,6 +13,8 @@ const sha256 = sha(); const generateKeypair = nacl.sign.keyPair.fromSeed; +export const isPubkey = (value) => /^[A-HJ-NP-Za-km-z1-9]{42,45}$/.test(value) + export async function idSecPass2rawAll(idSec, pass) { const rawSeed = await saltPass2seed(idSec, pass); const keyPair = seed2keyPair(rawSeed); diff --git a/src/crypto.test.mjs b/src/crypto.test.mjs index 65e87ef8bc41d127d0f6415fa09820a3eaff540a..d241c79e22f31a3d23ccf99183f75c1099903c88 100644 --- a/src/crypto.test.mjs +++ b/src/crypto.test.mjs @@ -30,6 +30,7 @@ test('array sign string', async t => t.is((await app.sign(unsignedDocument, secr test('uint8array sign string', async t => t.is((await app.sign(unsignedDocument, secretKey, 'uint8array'))[0], 27)); test('sign throw for bad output format', async t => t.throwsAsync(() => app.sign(unsignedDocument, secretKey, 'whattt ?'))); +test("is a pubkey", (t) => t.is(app.isPubkey(pubKey), true)); test('b58 should decode/encode well', t => t.is(app.b58.encode(app.b58.decode(pubKey)), pubKey)); test('b58 on pubKey with leading 1', t => t.is(app.b58.encode(app.b58.decode('12BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx')), '12BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx')); test('b58 on pubKey without leading 1', t => t.is(app.b58.encode(app.b58.decode('2BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx')), '2BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx'));