@owlmeans/basic-keys 0.1.18-rc.5 → 0.1.18-rc.51
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/README.md +12 -12
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/basic-keys/SKILL.md +43 -13
- package/build/auth/types.d.ts +10 -0
- package/build/auth/types.d.ts.map +1 -0
- package/build/auth/types.js +2 -0
- package/build/auth/types.js.map +1 -0
- package/build/auth.d.ts +3 -4
- package/build/auth.d.ts.map +1 -1
- package/build/auth.js +43 -39
- package/build/auth.js.map +1 -1
- package/build/bin.d.ts +1 -0
- package/build/bin.js +1 -0
- package/build/bin.js.map +1 -1
- package/build/helper/types.d.ts +11 -0
- package/build/helper/types.d.ts.map +1 -0
- package/build/helper/types.js +2 -0
- package/build/helper/types.js.map +1 -0
- package/build/helper.d.ts +4 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +21 -15
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/keypair.js +2 -2
- package/build/keypair.js.map +1 -1
- package/build/model.d.ts +2 -2
- package/build/model.d.ts.map +1 -1
- package/build/model.js +16 -16
- package/build/model.js.map +1 -1
- package/build/plugins/ed25519.js +3 -3
- package/build/plugins/ed25519.js.map +1 -1
- package/build/plugins/xchacha.js +2 -2
- package/build/plugins/xchacha.js.map +1 -1
- package/build/utils/types.d.ts +16 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils.d.ts +3 -4
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +26 -22
- package/build/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/auth/types.ts +17 -0
- package/src/auth.ts +51 -44
- package/src/bin.ts +1 -0
- package/src/helper/types.ts +11 -0
- package/src/helper.ts +26 -16
- package/src/index.ts +2 -0
- package/src/keypair.ts +2 -2
- package/src/model.ts +17 -17
- package/src/plugins/ed25519.ts +3 -3
- package/src/plugins/xchacha.ts +2 -2
- package/src/utils/types.ts +15 -0
- package/src/utils.ts +28 -21
- package/tests/auth.spec.ts +5 -5
- package/tests/keys.spec.ts +3 -3
- package/tests/known-answers.spec.ts +68 -0
- package/build/.gitkeep +0 -0
package/tests/auth.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import {
|
|
2
|
+
import { authCredentialsHelper } from '@owlmeans/basic-keys'
|
|
3
3
|
import { AuthRole, AuthenticationType } from '@owlmeans/auth'
|
|
4
4
|
import type { AuthCredentials } from '@owlmeans/auth'
|
|
5
5
|
import { fixtureKey } from './context.js'
|
|
@@ -15,8 +15,8 @@ const baseCreds = (): Omit<AuthCredentials, 'credential'> => ({
|
|
|
15
15
|
describe('@owlmeans/basic-keys — packAuthCredentials round-trip', () => {
|
|
16
16
|
test('signs and verifies credentials with extras attached', async () => {
|
|
17
17
|
const key = fixtureKey()
|
|
18
|
-
const signed = await packAuthCredentials(baseCreds(), { nonce: 'n-1' }, key)
|
|
19
|
-
const result = await unpackAuthCredentials<{ nonce: string }>(signed, key)
|
|
18
|
+
const signed = await authCredentialsHelper.packAuthCredentials(baseCreds(), { nonce: 'n-1' }, key)
|
|
19
|
+
const result = await authCredentialsHelper.unpackAuthCredentials<{ nonce: string }>(signed, key)
|
|
20
20
|
expect(result.isValid).toBe(true)
|
|
21
21
|
expect(result.extras?.nonce).toBe('n-1')
|
|
22
22
|
})
|
|
@@ -24,8 +24,8 @@ describe('@owlmeans/basic-keys — packAuthCredentials round-trip', () => {
|
|
|
24
24
|
test('verification fails for a different keypair', async () => {
|
|
25
25
|
const signing = fixtureKey('alice')
|
|
26
26
|
const other = fixtureKey('bob')
|
|
27
|
-
const signed = await packAuthCredentials(baseCreds(), { nonce: 'n-1' }, signing)
|
|
28
|
-
const result = await unpackAuthCredentials(signed, other)
|
|
27
|
+
const signed = await authCredentialsHelper.packAuthCredentials(baseCreds(), { nonce: 'n-1' }, signing)
|
|
28
|
+
const result = await authCredentialsHelper.unpackAuthCredentials(signed, other)
|
|
29
29
|
expect(result.isValid).toBe(false)
|
|
30
30
|
})
|
|
31
31
|
})
|
package/tests/keys.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import {
|
|
2
|
+
import { keyHelper, makeKeyPairModel } from '@owlmeans/basic-keys'
|
|
3
3
|
import { fixtureKey } from './context.js'
|
|
4
4
|
|
|
5
5
|
describe('@owlmeans/basic-keys — KeyPairModel sign/verify', () => {
|
|
@@ -26,13 +26,13 @@ describe('@owlmeans/basic-keys — public-key-only verification (fromPubKey)', (
|
|
|
26
26
|
const signing = fixtureKey('peer-keys-spec')
|
|
27
27
|
const sig = await signing.sign({ event: 'check' })
|
|
28
28
|
|
|
29
|
-
const verifying = fromPubKey(signing.exportPublic())
|
|
29
|
+
const verifying = keyHelper.fromPubKey(signing.exportPublic())
|
|
30
30
|
expect(await verifying.verify({ event: 'check' }, sig)).toBe(true)
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
test('matchAddress agrees with exportAddress() on the same keypair', () => {
|
|
34
34
|
const key = fixtureKey('addr-spec')
|
|
35
|
-
expect(matchAddress(key.exportAddress(), key.exportPublic())).toBe(true)
|
|
35
|
+
expect(keyHelper.matchAddress(key.exportAddress(), key.exportPublic())).toBe(true)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
test('export() round-trips into a new model that produces the same public key', async () => {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { xchacha20poly1305 } from '@noble/ciphers/chacha.js'
|
|
3
|
+
import { ed25519 } from '@noble/curves/ed25519.js'
|
|
4
|
+
import { hmac } from '@noble/hashes/hmac.js'
|
|
5
|
+
import { sha256, sha512 } from '@noble/hashes/sha2.js'
|
|
6
|
+
import { keccak_256 } from '@noble/hashes/sha3.js'
|
|
7
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'
|
|
8
|
+
import { base58, base64 } from '@scure/base'
|
|
9
|
+
import canonicalize from 'canonicalize'
|
|
10
|
+
import { ed25519Plugin } from '../src/plugins/ed25519.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Answers computed with @noble/hashes 1.8, @noble/curves 1.9, @noble/ciphers 1.3, @scure/base 1.2 and
|
|
14
|
+
* canonicalize 2.1 — the versions this package ran before the v2 line. A round trip passes whatever the
|
|
15
|
+
* library does to its bytes; these do not, so a derivation, an address or a signature that moved fails here.
|
|
16
|
+
*/
|
|
17
|
+
const enc = new TextEncoder()
|
|
18
|
+
const SEED = hexToBytes('0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20')
|
|
19
|
+
const PUB = '79b5562e8fe654f94078b112e8a98ba7901f853ae695bed7e0e3910bad049664'
|
|
20
|
+
|
|
21
|
+
describe('@owlmeans/basic-keys — known answers of the crypto primitives', () => {
|
|
22
|
+
test('hashes', () => {
|
|
23
|
+
expect(bytesToHex(sha256(enc.encode('owlmeans')))).toBe('03321b0b5c45f6146418c0aedbf69e6c171002fbd11f13c3c7edff8b1499dbf7')
|
|
24
|
+
expect(bytesToHex(sha512(enc.encode('owlmeans')))).toBe('25c101a119c1f9333f6d2d96c908dc71cc407ba30184c885179c53e7ad4b265c3dcccc1db293f2574d91b615626a91e00526b72c3d5206b8b42dd5153c3ea652')
|
|
25
|
+
expect(bytesToHex(keccak_256(enc.encode('owlmeans')))).toBe('859b6703a20c79d0a3a2ab79f69cd1ed8c5268b1537ee1c433431102ee488563')
|
|
26
|
+
expect(bytesToHex(hmac(sha512, enc.encode('key'), enc.encode('owlmeans')))).toBe('3e0c8942c110583b9c25f03be8e666d55c81393e61d335f486ff3cb5a9c1daf0154e68f79414a49f9c92801c05d01e21f95410fa70af37fe7d17e8108ea5b137')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('an ed25519 key derives the same public key, address and signature', () => {
|
|
30
|
+
const pub = ed25519Plugin.toPublic(SEED)
|
|
31
|
+
expect(bytesToHex(pub)).toBe(PUB)
|
|
32
|
+
expect(base58.encode(pub)).toBe('9C6hybhQ6Aycep9jaUnP6uL9ZYvDjUp1aSkFWPUFJtpj')
|
|
33
|
+
expect(base64.encode(pub)).toBe('ebVWLo/mVPlAeLES6KmLp5AfhTrmlb7X4OORC60ElmQ=')
|
|
34
|
+
expect(ed25519Plugin.toAdress(pub)).toBe('25ypesVVjyxzsRPzbQs8ejHnokbP')
|
|
35
|
+
|
|
36
|
+
const message = enc.encode('hello owlmeans')
|
|
37
|
+
const signature = ed25519Plugin.sign(message, SEED)
|
|
38
|
+
expect(bytesToHex(signature)).toBe('154297b3ce7ecc748bfad553b10e564b0034e857b127a8012d6585fdd4cd2f62348c7ec2a3a9cb20e7c9f3a6681348c2af7ec7c18482ae4def296c6a4423ed0a')
|
|
39
|
+
expect(ed25519Plugin.verify(message, signature, pub)).toBe(true)
|
|
40
|
+
expect(ed25519.verify(signature, enc.encode('hello owlmeans!'), pub)).toBe(false)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('a random ed25519 secret key is 32 bytes and signs verifiably', () => {
|
|
44
|
+
const secret = ed25519Plugin.random()
|
|
45
|
+
expect(secret.length).toBe(32)
|
|
46
|
+
const message = enc.encode('fresh')
|
|
47
|
+
expect(ed25519Plugin.verify(message, ed25519Plugin.sign(message, secret), ed25519Plugin.toPublic(secret))).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('xchacha20-poly1305 opens a ciphertext sealed before the upgrade, and seals the same bytes', () => {
|
|
51
|
+
const key = hexToBytes('fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0')
|
|
52
|
+
const nonce = hexToBytes('000306090c0f1215181b1e2124272a2d303336393c3f4245')
|
|
53
|
+
const sealed = 'e003dd72872ec24f237d31da2ec1f62c870582997ad3c5002b0775362bb8'
|
|
54
|
+
expect(new TextDecoder().decode(xchacha20poly1305(key, nonce).decrypt(hexToBytes(sealed)))).toBe('secret payload')
|
|
55
|
+
expect(bytesToHex(xchacha20poly1305(key, nonce).encrypt(enc.encode('secret payload')))).toBe(sealed)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('canonical JSON keeps its key order, escapes and unicode', () => {
|
|
59
|
+
expect(canonicalize({ b: [3, { z: 1, a: 'é' }], a: 1, n: null, u: 'ü
' })).toBe('{"a":1,"b":[3,{"a":"é","z":1}],"n":null,"u":"ü
"}')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('canonical JSON drops undefined properties, nulls undefined array items and serializes dates and numbers as before', () => {
|
|
63
|
+
expect(canonicalize({ a: 1, b: undefined, c: [1, undefined, 3] })).toBe('{"a":1,"c":[1,null,3]}')
|
|
64
|
+
expect(canonicalize({ z: { y: undefined, x: 1 } })).toBe('{"z":{"x":1}}')
|
|
65
|
+
expect(canonicalize({ d: new Date(0) })).toBe('{"d":"1970-01-01T00:00:00.000Z"}')
|
|
66
|
+
expect(canonicalize({ n: [1e21, 1e-7, -0, 0.1] })).toBe('{"n":[1e+21,1e-7,0,0.1]}')
|
|
67
|
+
})
|
|
68
|
+
})
|
package/build/.gitkeep
DELETED
|
File without changes
|