beam-protocol-sdk 0.5.0 → 0.5.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 ADDED
@@ -0,0 +1,97 @@
1
+ # beam-protocol-sdk
2
+
3
+ TypeScript SDK for Beam Protocol: identity generation, registration, discovery, DID tooling, and signed agent-to-agent messaging.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install beam-protocol-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { BeamClient, BeamIdentity } from 'beam-protocol-sdk'
15
+
16
+ const identity = BeamIdentity.generate({ agentName: 'assistant', orgName: 'acme' })
17
+ const client = new BeamClient({ identity: identity.export(), directoryUrl: 'https://api.beam.directory' })
18
+
19
+ await client.register('Acme Assistant', ['conversation.message'])
20
+ const reply = await client.talk('echo@beam.directory', 'Hello from Beam')
21
+ console.log(reply.message)
22
+ ```
23
+
24
+ ## Common Usage
25
+
26
+ ### Handle incoming intents
27
+
28
+ ```ts
29
+ client.on('task.execute', async (frame, respond) => {
30
+ respond({
31
+ success: true,
32
+ payload: {
33
+ receivedFrom: frame.from,
34
+ intent: frame.intent,
35
+ },
36
+ })
37
+ })
38
+
39
+ await client.connect()
40
+ ```
41
+
42
+ ### Search and lookup
43
+
44
+ ```ts
45
+ const directory = client.directory
46
+ const record = await directory.lookup('echo@beam.directory')
47
+ const matches = await directory.search({ capabilities: ['conversation.message'], limit: 10 })
48
+ ```
49
+
50
+ ### Work with DID documents and credentials
51
+
52
+ ```ts
53
+ const didDocument = await client.did.resolve('did:beam:echo')
54
+ const domainCredential = await client.credentials.issueDomainVC(client.beamId, 'acme.com')
55
+ const isValid = client.credentials.verify(domainCredential)
56
+ ```
57
+
58
+ ## API Reference
59
+
60
+ ### Core classes
61
+
62
+ - `BeamIdentity` - generate, import, export, sign, verify, and parse Beam IDs
63
+ - `BeamClient` - register agents, connect over WebSocket, send intents, use talk/thread helpers
64
+ - `BeamDirectory` - lookup, search, browse, stats, profile updates, verification, delegation, reporting
65
+ - `BeamDID` - DID resolution and DID document helpers
66
+ - `BeamCredentialsClient` - issue and verify Beam-issued credentials
67
+
68
+ ### Frame helpers
69
+
70
+ - `createIntentFrame()`
71
+ - `createResultFrame()`
72
+ - `signFrame()`
73
+ - `validateIntentFrame()`
74
+ - `validateResultFrame()`
75
+
76
+ ### Key management helpers
77
+
78
+ - `exportIdentity()`
79
+ - `importIdentity()`
80
+ - `generateRecoveryPhrase()`
81
+ - `recoverFromPhrase()`
82
+ - `toQRData()`
83
+ - `fromQRData()`
84
+
85
+ Full API docs: [docs.beam.directory/api/typescript](https://docs.beam.directory/api/typescript)
86
+
87
+ ## Development
88
+
89
+ ```bash
90
+ npm install
91
+ npm run build
92
+ npm test
93
+ ```
94
+
95
+ ## License
96
+
97
+ Apache-2.0
@@ -0,0 +1,2 @@
1
+ export declare function beamIdFromApiKey(apiKey: string): string | null;
2
+ //# sourceMappingURL=api-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../src/api-key.ts"],"names":[],"mappings":"AAqBA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgB9D"}
@@ -0,0 +1,34 @@
1
+ const AGENT_API_KEY_PREFIX = 'bk_';
2
+ function normalizeBase64Url(value) {
3
+ const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
4
+ const padding = (4 - (normalized.length % 4)) % 4;
5
+ return normalized.padEnd(normalized.length + padding, '=');
6
+ }
7
+ function base64ToUtf8(base64) {
8
+ if (typeof Buffer !== 'undefined') {
9
+ return Buffer.from(base64, 'base64').toString('utf8');
10
+ }
11
+ const binary = atob(base64);
12
+ const bytes = new Uint8Array(binary.length);
13
+ for (let index = 0; index < binary.length; index += 1) {
14
+ bytes[index] = binary.charCodeAt(index);
15
+ }
16
+ return new TextDecoder().decode(bytes);
17
+ }
18
+ export function beamIdFromApiKey(apiKey) {
19
+ if (!apiKey.startsWith(AGENT_API_KEY_PREFIX)) {
20
+ return null;
21
+ }
22
+ const encodedBeamId = apiKey.slice(AGENT_API_KEY_PREFIX.length).split('.', 1)[0] ?? '';
23
+ if (!encodedBeamId) {
24
+ return null;
25
+ }
26
+ try {
27
+ const beamId = base64ToUtf8(normalizeBase64Url(encodedBeamId));
28
+ return beamId || null;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ //# sourceMappingURL=api-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key.js","sourceRoot":"","sources":["../src/api-key.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAElC,SAAS,kBAAkB,CAAC,KAAa;IACvC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC9D,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACjD,OAAO,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,OAAO,EAAE,GAAG,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC3C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACtF,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,YAAY,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAA;QAC9D,OAAO,MAAM,IAAI,IAAI,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const BIP39_ENGLISH: string[];
2
+ //# sourceMappingURL=bip39-wordlist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bip39-wordlist.d.ts","sourceRoot":"","sources":["../src/bip39-wordlist.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,EAAE,MAAM,EAigEjC,CAAC"}