Files
bare-operating-system/packages/bare-os-booter/test.identity.js
T
2026-04-03 02:49:18 -04:00

34 lines
915 B
JavaScript

/**
* bare-crypto loads only under Bare — run via brittle-bare (see package.json "test").
*/
import test from 'brittle'
import {
encodeAccount,
decodeAccount,
encodeNewAccount,
ACCOUNT_MAGIC,
ACCOUNT_VERSION
} from './lib/identity-account.js'
test('identity account encode/decode roundtrip', async (t) => {
const pass = 'unit-test-passphrase'
const blob = encodeNewAccount(pass)
t.ok(blob.length > 80)
t.is(blob[0], ACCOUNT_MAGIC[0])
t.is(blob[ACCOUNT_MAGIC.length], ACCOUNT_VERSION)
const { publicKey, secretKey } = decodeAccount(pass, blob)
t.is(publicKey.length, 32)
t.is(secretKey.length, 64)
const blob2 = encodeAccount(pass, publicKey, secretKey)
const again = decodeAccount(pass, blob2)
t.alike(publicKey, again.publicKey)
t.alike(secretKey, again.secretKey)
let bad = false
try {
decodeAccount('wrong-pass', blob)
} catch {
bad = true
}
t.ok(bad)
})