@me2em/core 0.4.4-alpha.1 → 0.4.4-alpha.2
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 +159 -373
- package/dist/crypto/ed25519.d.ts +12 -0
- package/dist/crypto/ed25519.d.ts.map +1 -0
- package/dist/crypto/ed25519.js +12 -0
- package/dist/crypto/ed25519.js.map +1 -0
- package/dist/crypto/hkdf.d.ts +13 -0
- package/dist/crypto/hkdf.d.ts.map +1 -0
- package/dist/crypto/hkdf.js +16 -0
- package/dist/crypto/hkdf.js.map +1 -0
- package/dist/crypto/index.d.ts +3 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/init.d.ts +9 -0
- package/dist/crypto/init.d.ts.map +1 -0
- package/dist/crypto/init.js +16 -0
- package/dist/crypto/init.js.map +1 -0
- package/dist/handle.d.ts +87 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +113 -0
- package/dist/handle.js.map +1 -0
- package/dist/identity.d.ts +43 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +71 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/seed.d.ts +96 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +127 -0
- package/dist/seed.js.map +1 -0
- package/dist/session.d.ts +41 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +37 -0
- package/dist/session.js.map +1 -0
- package/package.json +36 -12
- package/.github/workflows/ci.yml +0 -0
- package/CODE_OF_CONDUCT.md +0 -73
- package/CONTRIBUTING.md +0 -145
- package/GOVERNANCE.md +0 -132
- package/SECURITY.md +0 -70
- package/packages/core/README.md +0 -656
- package/packages/core/package.json +0 -44
- package/packages/core/test/derivation.spec.ts +0 -117
- package/packages/core/tsconfig.json +0 -9
- package/pnpm-workspace.yaml +0 -2
- package/specs/core.md +0 -44
- package/specs/openapi/server-ref.yaml +0 -10
- package/specs/test-vectors.json +0 -13
- package/tsconfig.base.json +0 -20
- package/typedoc.json +0 -18
- /package/{packages/core/src → src}/crypto/ed25519.ts +0 -0
- /package/{packages/core/src → src}/crypto/hkdf.ts +0 -0
- /package/{packages/core/src → src}/crypto/index.ts +0 -0
- /package/{packages/core/src → src}/crypto/init.ts +0 -0
- /package/{packages/core/src → src}/handle.ts +0 -0
- /package/{packages/core/src → src}/identity.ts +0 -0
- /package/{packages/core/src → src}/index.ts +0 -0
- /package/{packages/core/src → src}/seed.ts +0 -0
- /package/{packages/core/src → src}/session.ts +0 -0
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Identity, Handle, generateSeedPhrase, get32ByteSeedFromMnemonic, validateSeedPhrase } from '../src/index.js';
|
|
3
|
-
|
|
4
|
-
describe('Me2em Core Functionality', () => {
|
|
5
|
-
const testSeed = new Uint8Array(32).fill(42);
|
|
6
|
-
|
|
7
|
-
describe('Identity & Handle Derivation', () => {
|
|
8
|
-
it('should derive same HandleId from same seed + name', async () => {
|
|
9
|
-
const identity1 = await Identity.fromSeed(testSeed);
|
|
10
|
-
const handle1a = await identity1.deriveHandle('work');
|
|
11
|
-
const handle1b = await identity1.deriveHandle('private');
|
|
12
|
-
|
|
13
|
-
const identity2 = await Identity.fromSeed(testSeed);
|
|
14
|
-
const handle2a = await identity2.deriveHandle('work');
|
|
15
|
-
|
|
16
|
-
expect(handle1a.getId()).toBe(handle2a.getId());
|
|
17
|
-
expect(handle1a.getId()).not.toBe(handle1b.getId());
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should attach and retrieve metadata', async () => {
|
|
21
|
-
const identity = await Identity.fromSeed(testSeed);
|
|
22
|
-
const metadata = { displayName: 'Alice', role: 'admin' };
|
|
23
|
-
const handle = await identity.deriveHandle('work', metadata);
|
|
24
|
-
|
|
25
|
-
expect(handle.getName()).toBe('work');
|
|
26
|
-
expect(handle.getMetadata()).toEqual(metadata);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('Handle.derivePassword', () => {
|
|
31
|
-
it('should deterministically derive the same password', async () => {
|
|
32
|
-
const identity = await Identity.fromSeed(testSeed);
|
|
33
|
-
const handle = await identity.deriveHandle('google');
|
|
34
|
-
|
|
35
|
-
const pwd1 = handle.derivePassword('google', 16);
|
|
36
|
-
const pwd2 = handle.derivePassword('google', 16);
|
|
37
|
-
|
|
38
|
-
expect(pwd1).toBe(pwd2);
|
|
39
|
-
expect(pwd1.length).toBeGreaterThan(0);
|
|
40
|
-
expect(pwd1).toMatch(/^[A-Za-z0-9_-]{22}$/);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should derive different passwords for different contexts', async () => {
|
|
44
|
-
const identity = await Identity.fromSeed(testSeed);
|
|
45
|
-
const handle = await identity.deriveHandle('google');
|
|
46
|
-
|
|
47
|
-
const pwdGoogle = handle.derivePassword('google');
|
|
48
|
-
const pwdGithub = handle.derivePassword('github');
|
|
49
|
-
|
|
50
|
-
expect(pwdGoogle).not.toBe(pwdGithub);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('Handle.deriveChannelKey', () => {
|
|
55
|
-
it('should deterministically derive a 32-byte channel key', async () => {
|
|
56
|
-
const identity = await Identity.fromSeed(testSeed);
|
|
57
|
-
const handle = await identity.deriveHandle('drone-001');
|
|
58
|
-
|
|
59
|
-
const key1 = handle.deriveChannelKey('telemetry-v1');
|
|
60
|
-
const key2 = handle.deriveChannelKey('telemetry-v1');
|
|
61
|
-
|
|
62
|
-
expect(key1).toEqual(key2);
|
|
63
|
-
expect(key1.length).toBe(32);
|
|
64
|
-
expect(key1).toBeInstanceOf(Uint8Array);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should derive different keys for different contexts', async () => {
|
|
68
|
-
const identity = await Identity.fromSeed(testSeed);
|
|
69
|
-
const handle = await identity.deriveHandle('drone-001');
|
|
70
|
-
|
|
71
|
-
const keyTelemetry = handle.deriveChannelKey('telemetry');
|
|
72
|
-
const keyCommand = handle.deriveChannelKey('command');
|
|
73
|
-
|
|
74
|
-
expect(keyTelemetry).not.toEqual(keyCommand);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('BIP39 Seed Utilities', () => {
|
|
79
|
-
it('should generate valid 12-word and 24-word phrases', () => {
|
|
80
|
-
const phrase12 = generateSeedPhrase(128);
|
|
81
|
-
expect(phrase12.length).toBe(12);
|
|
82
|
-
expect(validateSeedPhrase(phrase12).isValid).toBe(true);
|
|
83
|
-
|
|
84
|
-
const phrase24 = generateSeedPhrase(256);
|
|
85
|
-
expect(phrase24.length).toBe(24);
|
|
86
|
-
expect(validateSeedPhrase(phrase24).isValid).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should reject invalid seed phrases', () => {
|
|
90
|
-
const invalid = ['apple', 'banana', 'cherry'];
|
|
91
|
-
const result = validateSeedPhrase(invalid);
|
|
92
|
-
expect(result.isValid).toBe(false);
|
|
93
|
-
expect(result.error).toContain('must be 12 or 24 words');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should convert mnemonic to deterministic 32-byte seed', async () => {
|
|
97
|
-
const phrase = generateSeedPhrase(128);
|
|
98
|
-
const seedBytes = await get32ByteSeedFromMnemonic(phrase);
|
|
99
|
-
|
|
100
|
-
expect(seedBytes.length).toBe(32);
|
|
101
|
-
expect(seedBytes).toBeInstanceOf(Uint8Array);
|
|
102
|
-
|
|
103
|
-
const identity = await Identity.fromSeed(seedBytes);
|
|
104
|
-
expect(identity.getPublicKey().length).toBe(32);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should produce identical Identity from string and array mnemonic', async () => {
|
|
108
|
-
const phraseArray = generateSeedPhrase(128);
|
|
109
|
-
const phraseString = phraseArray.join(' ');
|
|
110
|
-
|
|
111
|
-
const seed1 = await get32ByteSeedFromMnemonic(phraseArray);
|
|
112
|
-
const seed2 = await get32ByteSeedFromMnemonic(phraseString);
|
|
113
|
-
|
|
114
|
-
expect(seed1).toEqual(seed2);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
package/pnpm-workspace.yaml
DELETED
package/specs/core.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Me2em Protocol Specification v0.1
|
|
2
|
-
|
|
3
|
-
## 1. Cryptographic Primitives
|
|
4
|
-
- **Root Key**: Ed25519
|
|
5
|
-
- **Derivation**: HKDF-SHA256
|
|
6
|
-
- **Handle Key**: Ed25519 (independent pair per handle)
|
|
7
|
-
- **Signature**: Ed25519 pure
|
|
8
|
-
|
|
9
|
-
## 2. Identity Derivation
|
|
10
|
-
```
|
|
11
|
-
RootPrivateKey = HKDF-SHA256(
|
|
12
|
-
InputKeyMaterial = Seed (32 bytes)
|
|
13
|
-
Info = "me2em/identity/v1/root"
|
|
14
|
-
Length = 32
|
|
15
|
-
)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## 3. Handle Derivation
|
|
19
|
-
```
|
|
20
|
-
HandlePrivateKey = HKDF-SHA256(
|
|
21
|
-
InputKeyMaterial = RootPrivateKey
|
|
22
|
-
Info = "me2em/handle/v1/<lowercase_name>"
|
|
23
|
-
Length = 32
|
|
24
|
-
)
|
|
25
|
-
HandleId = Base64Url(Ed25519.PublicKey(HandlePrivateKey))
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## 4. Authentication Flow
|
|
29
|
-
1. Client sends `handleId` → requests challenge
|
|
30
|
-
2. Server returns `nonce` (256-bit random, TTL 2m)
|
|
31
|
-
3. Client signs `nonce` with `HandlePrivateKey`
|
|
32
|
-
4. Client sends `signature`
|
|
33
|
-
5. Server verifies with `HandlePublicKey` (from registry)
|
|
34
|
-
6. On success: issues `SessionToken(handleId, scopes, expires)`
|
|
35
|
-
|
|
36
|
-
## 5. Session Token Structure
|
|
37
|
-
```json
|
|
38
|
-
{
|
|
39
|
-
"handleId": "base64url_pubkey",
|
|
40
|
-
"scopes": ["read:messages", "write:profile"],
|
|
41
|
-
"expiresAt": 1716912000,
|
|
42
|
-
"sig": "ed25519_signature_of_payload"
|
|
43
|
-
}
|
|
44
|
-
```
|
package/specs/test-vectors.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.1.0",
|
|
3
|
-
"algorithm": "HKDF-SHA256 + Ed25519",
|
|
4
|
-
"vectors": [
|
|
5
|
-
{
|
|
6
|
-
"description": "Basic derivation: seed + 'work'",
|
|
7
|
-
"seed_hex": "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a",
|
|
8
|
-
"handle_name": "work",
|
|
9
|
-
"expected_handle_id": "Ab3...Xy9",
|
|
10
|
-
"expected_public_key_hex": "deadbeef..."
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
}
|
package/tsconfig.base.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022", "DOM"],
|
|
7
|
-
"types": ["node"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"declarationMap": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"isolatedModules": true,
|
|
17
|
-
"allowImportingTsExtensions": false
|
|
18
|
-
},
|
|
19
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
20
|
-
}
|
package/typedoc.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://typedoc.org/schema.json",
|
|
3
|
-
"entryPoints": ["packages/core/src/index.ts"],
|
|
4
|
-
"out": "docs",
|
|
5
|
-
"name": "me2em Protocol API Reference",
|
|
6
|
-
"includeVersion": true,
|
|
7
|
-
"excludePrivate": true,
|
|
8
|
-
"excludeProtected": true,
|
|
9
|
-
"excludeInternal": true,
|
|
10
|
-
"readme": "packages/core/README.md",
|
|
11
|
-
"skipErrorChecking": true,
|
|
12
|
-
"navigation": {
|
|
13
|
-
"includeCategories": true,
|
|
14
|
-
"includeGroups": true
|
|
15
|
-
},
|
|
16
|
-
"categorizeByGroup": true,
|
|
17
|
-
"sort": ["source-order", "alphabetical"]
|
|
18
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|