@tinyhumansai/tinyplace 0.1.0
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/dist/api/a2a.d.ts +28 -0
- package/dist/api/a2a.js +21 -0
- package/dist/api/admin.d.ts +38 -0
- package/dist/api/admin.js +49 -0
- package/dist/api/broadcasts.d.ts +32 -0
- package/dist/api/broadcasts.js +51 -0
- package/dist/api/channels.d.ts +43 -0
- package/dist/api/channels.js +57 -0
- package/dist/api/directory.d.ts +15 -0
- package/dist/api/directory.js +26 -0
- package/dist/api/escrow.d.ts +47 -0
- package/dist/api/escrow.js +76 -0
- package/dist/api/events.d.ts +45 -0
- package/dist/api/events.js +77 -0
- package/dist/api/explorer.d.ts +19 -0
- package/dist/api/explorer.js +21 -0
- package/dist/api/groups.d.ts +19 -0
- package/dist/api/groups.js +32 -0
- package/dist/api/inbox.d.ts +27 -0
- package/dist/api/inbox.js +48 -0
- package/dist/api/keys.d.ts +9 -0
- package/dist/api/keys.js +14 -0
- package/dist/api/ledger.d.ts +11 -0
- package/dist/api/ledger.js +14 -0
- package/dist/api/marketplace.d.ts +53 -0
- package/dist/api/marketplace.js +81 -0
- package/dist/api/messages.d.ts +11 -0
- package/dist/api/messages.js +17 -0
- package/dist/api/moderation.d.ts +30 -0
- package/dist/api/moderation.js +32 -0
- package/dist/api/payments.d.ts +15 -0
- package/dist/api/payments.js +26 -0
- package/dist/api/pricing.d.ts +69 -0
- package/dist/api/pricing.js +60 -0
- package/dist/api/profiles.d.ts +18 -0
- package/dist/api/profiles.js +23 -0
- package/dist/api/registry.d.ts +26 -0
- package/dist/api/registry.js +87 -0
- package/dist/api/reputation.d.ts +24 -0
- package/dist/api/reputation.js +29 -0
- package/dist/api/search.d.ts +46 -0
- package/dist/api/search.js +41 -0
- package/dist/api/stats.d.ts +11 -0
- package/dist/api/stats.js +20 -0
- package/dist/auth.d.ts +16 -0
- package/dist/auth.js +36 -0
- package/dist/client.d.ts +63 -0
- package/dist/client.js +73 -0
- package/dist/crypto.d.ts +12 -0
- package/dist/crypto.js +49 -0
- package/dist/http.d.ts +30 -0
- package/dist/http.js +101 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +32 -0
- package/dist/local-signer.d.ts +15 -0
- package/dist/local-signer.js +51 -0
- package/dist/signal/crypto.d.ts +29 -0
- package/dist/signal/crypto.js +156 -0
- package/dist/signal/index.d.ts +11 -0
- package/dist/signal/index.js +6 -0
- package/dist/signal/keys.d.ts +14 -0
- package/dist/signal/keys.js +36 -0
- package/dist/signal/memory-store.d.ts +21 -0
- package/dist/signal/memory-store.js +50 -0
- package/dist/signal/ratchet.d.ts +12 -0
- package/dist/signal/ratchet.js +106 -0
- package/dist/signal/session.d.ts +17 -0
- package/dist/signal/session.js +117 -0
- package/dist/signal/store.d.ts +36 -0
- package/dist/signal/store.js +6 -0
- package/dist/signal/x3dh.d.ts +18 -0
- package/dist/signal/x3dh.js +86 -0
- package/dist/signer.d.ts +13 -0
- package/dist/signer.js +9 -0
- package/dist/types/broadcasts.d.ts +74 -0
- package/dist/types/broadcasts.js +1 -0
- package/dist/types/commerce.d.ts +183 -0
- package/dist/types/commerce.js +1 -0
- package/dist/types/directory.d.ts +88 -0
- package/dist/types/directory.js +1 -0
- package/dist/types/escrow.d.ts +129 -0
- package/dist/types/escrow.js +1 -0
- package/dist/types/events.d.ts +137 -0
- package/dist/types/events.js +1 -0
- package/dist/types/explorer.d.ts +133 -0
- package/dist/types/explorer.js +1 -0
- package/dist/types/groups.d.ts +56 -0
- package/dist/types/groups.js +1 -0
- package/dist/types/identity.d.ts +94 -0
- package/dist/types/identity.js +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.js +16 -0
- package/dist/types/ledger.d.ts +57 -0
- package/dist/types/ledger.js +1 -0
- package/dist/types/marketplace.d.ts +141 -0
- package/dist/types/marketplace.js +1 -0
- package/dist/types/messaging.d.ts +67 -0
- package/dist/types/messaging.js +1 -0
- package/dist/types/payments.d.ts +88 -0
- package/dist/types/payments.js +1 -0
- package/dist/types/profile.d.ts +49 -0
- package/dist/types/profile.js +1 -0
- package/dist/types/reputation.d.ts +90 -0
- package/dist/types/reputation.js +1 -0
- package/dist/types/search.d.ts +56 -0
- package/dist/types/search.js +1 -0
- package/dist/types/social.d.ts +158 -0
- package/dist/types/social.js +1 -0
- package/dist/websocket.d.ts +26 -0
- package/dist/websocket.js +83 -0
- package/package.json +30 -0
- package/src/api/a2a.ts +50 -0
- package/src/api/admin.ts +95 -0
- package/src/api/broadcasts.ts +110 -0
- package/src/api/channels.ts +110 -0
- package/src/api/directory.ts +45 -0
- package/src/api/escrow.ts +163 -0
- package/src/api/events.ts +133 -0
- package/src/api/explorer.ts +48 -0
- package/src/api/groups.ts +64 -0
- package/src/api/inbox.ts +71 -0
- package/src/api/keys.ts +18 -0
- package/src/api/ledger.ts +28 -0
- package/src/api/marketplace.ts +165 -0
- package/src/api/messages.ts +23 -0
- package/src/api/moderation.ts +71 -0
- package/src/api/payments.ts +47 -0
- package/src/api/pricing.ts +122 -0
- package/src/api/profiles.ts +43 -0
- package/src/api/registry.ts +143 -0
- package/src/api/reputation.ts +60 -0
- package/src/api/search.ts +59 -0
- package/src/api/stats.ts +32 -0
- package/src/auth.ts +75 -0
- package/src/client.ts +120 -0
- package/src/crypto.ts +74 -0
- package/src/http.ts +147 -0
- package/src/index.ts +72 -0
- package/src/local-signer.ts +78 -0
- package/src/signal/crypto.ts +229 -0
- package/src/signal/index.ts +28 -0
- package/src/signal/keys.ts +54 -0
- package/src/signal/memory-store.ts +66 -0
- package/src/signal/ratchet.ts +162 -0
- package/src/signal/session.ts +189 -0
- package/src/signal/store.ts +49 -0
- package/src/signal/x3dh.ts +130 -0
- package/src/signer.ts +21 -0
- package/src/types/broadcasts.ts +81 -0
- package/src/types/commerce.ts +206 -0
- package/src/types/directory.ts +98 -0
- package/src/types/escrow.ts +163 -0
- package/src/types/events.ts +155 -0
- package/src/types/explorer.ts +152 -0
- package/src/types/groups.ts +62 -0
- package/src/types/identity.ts +113 -0
- package/src/types/index.ts +16 -0
- package/src/types/ledger.ts +78 -0
- package/src/types/marketplace.ts +166 -0
- package/src/types/messaging.ts +77 -0
- package/src/types/payments.ts +103 -0
- package/src/types/profile.ts +55 -0
- package/src/types/reputation.ts +98 -0
- package/src/types/search.ts +61 -0
- package/src/types/social.ts +186 -0
- package/src/websocket.ts +112 -0
- package/tests/signal.test.ts +353 -0
- package/tests/staging.test.ts +650 -0
- package/tsconfig.json +15 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { toBase64, fromBase64 } from "./crypto.js";
|
|
2
|
+
import { x3dhInitiate, x3dhRespond, buildAssociatedData } from "./x3dh.js";
|
|
3
|
+
import { ratchetEncrypt, ratchetDecrypt } from "./ratchet.js";
|
|
4
|
+
export class SignalSession {
|
|
5
|
+
constructor(store, ourIdentityPublicKey) {
|
|
6
|
+
this.store = store;
|
|
7
|
+
this.ourIdentityPublicKey = ourIdentityPublicKey;
|
|
8
|
+
}
|
|
9
|
+
async encrypt(recipientAddress, recipientIdentityKey, plaintext, recipientBundle) {
|
|
10
|
+
let session = await this.store.getSession(recipientAddress);
|
|
11
|
+
let isPreKeyMessage = false;
|
|
12
|
+
let ephemeralPublicKey;
|
|
13
|
+
let signedPreKeyId;
|
|
14
|
+
let oneTimePreKeyId;
|
|
15
|
+
if (!session && recipientBundle) {
|
|
16
|
+
const bundle = parseKeyBundle(recipientBundle, recipientIdentityKey);
|
|
17
|
+
const identityKeyPair = await this.store.getIdentityX25519KeyPair();
|
|
18
|
+
const result = x3dhInitiate(identityKeyPair, bundle);
|
|
19
|
+
session = result.session;
|
|
20
|
+
ephemeralPublicKey = result.ephemeralPublicKey;
|
|
21
|
+
signedPreKeyId = result.signedPreKeyId;
|
|
22
|
+
oneTimePreKeyId = result.oneTimePreKeyId;
|
|
23
|
+
isPreKeyMessage = true;
|
|
24
|
+
}
|
|
25
|
+
if (!session) {
|
|
26
|
+
throw new Error(`No session for ${recipientAddress}. Provide a key bundle for initial message.`);
|
|
27
|
+
}
|
|
28
|
+
const associatedData = buildAssociatedData(this.ourIdentityPublicKey, recipientIdentityKey);
|
|
29
|
+
const message = await ratchetEncrypt(session, plaintext, associatedData);
|
|
30
|
+
await this.store.storeSession(recipientAddress, session);
|
|
31
|
+
const signal = buildSignalMetadata(message.header, ephemeralPublicKey, signedPreKeyId, oneTimePreKeyId);
|
|
32
|
+
return {
|
|
33
|
+
body: toBase64(message.ciphertext),
|
|
34
|
+
type: isPreKeyMessage ? "PREKEY_BUNDLE" : "CIPHERTEXT",
|
|
35
|
+
signal,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async decrypt(senderAddress, senderIdentityKey, envelope) {
|
|
39
|
+
let session = await this.store.getSession(senderAddress);
|
|
40
|
+
const ciphertext = fromBase64(envelope.body);
|
|
41
|
+
if (envelope.type === "PREKEY_BUNDLE" && envelope.signal) {
|
|
42
|
+
session = await this.processPreKeyMessage(senderIdentityKey, envelope.signal);
|
|
43
|
+
}
|
|
44
|
+
if (!session) {
|
|
45
|
+
throw new Error(`No session for ${senderAddress}`);
|
|
46
|
+
}
|
|
47
|
+
const header = parseSignalHeader(envelope.signal);
|
|
48
|
+
const associatedData = buildAssociatedData(senderIdentityKey, this.ourIdentityPublicKey);
|
|
49
|
+
const ratchetMessage = { header, ciphertext };
|
|
50
|
+
const plaintext = await ratchetDecrypt(session, ratchetMessage, associatedData);
|
|
51
|
+
await this.store.storeSession(senderAddress, session);
|
|
52
|
+
return plaintext;
|
|
53
|
+
}
|
|
54
|
+
async processPreKeyMessage(senderIdentityKey, signal) {
|
|
55
|
+
const identityKeyPair = await this.store.getIdentityX25519KeyPair();
|
|
56
|
+
const signedPreKey = await this.store.getSignedPreKey(signal.signedPreKeyId);
|
|
57
|
+
if (!signedPreKey) {
|
|
58
|
+
throw new Error(`Signed pre-key ${signal.signedPreKeyId} not found`);
|
|
59
|
+
}
|
|
60
|
+
let oneTimePreKeyPair;
|
|
61
|
+
if (signal.oneTimePreKeyId) {
|
|
62
|
+
const oneTimePreKey = await this.store.getPreKey(signal.oneTimePreKeyId);
|
|
63
|
+
if (oneTimePreKey) {
|
|
64
|
+
oneTimePreKeyPair = oneTimePreKey.keyPair;
|
|
65
|
+
await this.store.removePreKey(signal.oneTimePreKeyId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const ephemeralKey = fromBase64(signal.ephemeralKey);
|
|
69
|
+
return x3dhRespond(identityKeyPair, signedPreKey.keyPair, senderIdentityKey, ephemeralKey, oneTimePreKeyPair);
|
|
70
|
+
}
|
|
71
|
+
async hasSession(address) {
|
|
72
|
+
const session = await this.store.getSession(address);
|
|
73
|
+
return session !== null;
|
|
74
|
+
}
|
|
75
|
+
async removeSession(address) {
|
|
76
|
+
await this.store.removeSession(address);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function parseKeyBundle(bundle, recipientX25519IdentityKey) {
|
|
80
|
+
const result = {
|
|
81
|
+
identityKey: recipientX25519IdentityKey,
|
|
82
|
+
signedPreKeyId: bundle.signedPreKey.keyId,
|
|
83
|
+
signedPreKey: fromBase64(bundle.signedPreKey.publicKey),
|
|
84
|
+
};
|
|
85
|
+
if (bundle.oneTimePreKey) {
|
|
86
|
+
result.oneTimePreKeyId = bundle.oneTimePreKey.keyId;
|
|
87
|
+
result.oneTimePreKey = fromBase64(bundle.oneTimePreKey.publicKey);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
function buildSignalMetadata(header, ephemeralPublicKey, signedPreKeyId, oneTimePreKeyId) {
|
|
92
|
+
const signal = {
|
|
93
|
+
ratchetKey: toBase64(header.publicKey),
|
|
94
|
+
messageNumber: header.messageNumber,
|
|
95
|
+
previousChainLength: header.previousChainLength,
|
|
96
|
+
};
|
|
97
|
+
if (ephemeralPublicKey) {
|
|
98
|
+
signal.ephemeralKey = toBase64(ephemeralPublicKey);
|
|
99
|
+
}
|
|
100
|
+
if (signedPreKeyId) {
|
|
101
|
+
signal.signedPreKeyId = signedPreKeyId;
|
|
102
|
+
}
|
|
103
|
+
if (oneTimePreKeyId) {
|
|
104
|
+
signal.oneTimePreKeyId = oneTimePreKeyId;
|
|
105
|
+
}
|
|
106
|
+
return signal;
|
|
107
|
+
}
|
|
108
|
+
function parseSignalHeader(signal) {
|
|
109
|
+
if (!signal?.ratchetKey) {
|
|
110
|
+
throw new Error("Missing ratchet key in signal metadata");
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
publicKey: fromBase64(signal.ratchetKey),
|
|
114
|
+
previousChainLength: signal.previousChainLength ?? 0,
|
|
115
|
+
messageNumber: signal.messageNumber ?? 0,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { X25519KeyPair } from "./crypto.js";
|
|
2
|
+
export interface SessionState {
|
|
3
|
+
dhSendKeyPair: X25519KeyPair;
|
|
4
|
+
dhRecvPublicKey: Uint8Array | null;
|
|
5
|
+
rootKey: Uint8Array;
|
|
6
|
+
sendChainKey: Uint8Array | null;
|
|
7
|
+
recvChainKey: Uint8Array | null;
|
|
8
|
+
sendMessageNumber: number;
|
|
9
|
+
recvMessageNumber: number;
|
|
10
|
+
previousChainLength: number;
|
|
11
|
+
skippedKeys: Map<string, Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
export interface PreKeyPair {
|
|
14
|
+
keyId: string;
|
|
15
|
+
keyPair: X25519KeyPair;
|
|
16
|
+
signature: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export interface SignedPreKeyPair {
|
|
19
|
+
keyId: string;
|
|
20
|
+
keyPair: X25519KeyPair;
|
|
21
|
+
signature: Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
export interface SessionStore {
|
|
24
|
+
getIdentityX25519KeyPair(): Promise<X25519KeyPair>;
|
|
25
|
+
getSignedPreKey(keyId: string): Promise<SignedPreKeyPair | null>;
|
|
26
|
+
getActiveSignedPreKey(): Promise<SignedPreKeyPair>;
|
|
27
|
+
storeSignedPreKey(preKey: SignedPreKeyPair): Promise<void>;
|
|
28
|
+
getPreKey(keyId: string): Promise<PreKeyPair | null>;
|
|
29
|
+
removePreKey(keyId: string): Promise<void>;
|
|
30
|
+
storePreKey(preKey: PreKeyPair): Promise<void>;
|
|
31
|
+
getAllPreKeys(): Promise<Array<PreKeyPair>>;
|
|
32
|
+
getSession(address: string): Promise<SessionState | null>;
|
|
33
|
+
storeSession(address: string, session: SessionState): Promise<void>;
|
|
34
|
+
removeSession(address: string): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare function skippedKeyId(ratchetPublicKey: Uint8Array, messageNumber: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { X25519KeyPair } from "./crypto.js";
|
|
2
|
+
import type { SessionState } from "./store.js";
|
|
3
|
+
export interface X3DHBundle {
|
|
4
|
+
identityKey: Uint8Array;
|
|
5
|
+
signedPreKeyId: string;
|
|
6
|
+
signedPreKey: Uint8Array;
|
|
7
|
+
oneTimePreKeyId?: string;
|
|
8
|
+
oneTimePreKey?: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export interface X3DHInitResult {
|
|
11
|
+
session: SessionState;
|
|
12
|
+
ephemeralPublicKey: Uint8Array;
|
|
13
|
+
signedPreKeyId: string;
|
|
14
|
+
oneTimePreKeyId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function x3dhInitiate(ourIdentityKeyPair: X25519KeyPair, theirBundle: X3DHBundle): X3DHInitResult;
|
|
17
|
+
export declare function x3dhRespond(ourIdentityKeyPair: X25519KeyPair, ourSignedPreKeyPair: X25519KeyPair, theirIdentityKey: Uint8Array, theirEphemeralKey: Uint8Array, ourOneTimePreKeyPair?: X25519KeyPair): SessionState;
|
|
18
|
+
export declare function buildAssociatedData(senderIdentityKey: Uint8Array, recipientIdentityKey: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
3
|
+
import { generateX25519KeyPair, x25519SharedSecret, } from "./crypto.js";
|
|
4
|
+
const X3DH_INFO = new TextEncoder().encode("WhisperText");
|
|
5
|
+
const PADDING = new Uint8Array(32).fill(0xff);
|
|
6
|
+
export function x3dhInitiate(ourIdentityKeyPair, theirBundle) {
|
|
7
|
+
const ephemeral = generateX25519KeyPair();
|
|
8
|
+
// DH1: our identity <-> their signed pre-key
|
|
9
|
+
const dh1 = x25519SharedSecret(ourIdentityKeyPair.privateKey, theirBundle.signedPreKey);
|
|
10
|
+
// DH2: our ephemeral <-> their identity
|
|
11
|
+
const dh2 = x25519SharedSecret(ephemeral.privateKey, theirBundle.identityKey);
|
|
12
|
+
// DH3: our ephemeral <-> their signed pre-key
|
|
13
|
+
const dh3 = x25519SharedSecret(ephemeral.privateKey, theirBundle.signedPreKey);
|
|
14
|
+
let dhConcat;
|
|
15
|
+
if (theirBundle.oneTimePreKey) {
|
|
16
|
+
// DH4: our ephemeral <-> their one-time pre-key
|
|
17
|
+
const dh4 = x25519SharedSecret(ephemeral.privateKey, theirBundle.oneTimePreKey);
|
|
18
|
+
dhConcat = concat(PADDING, dh1, dh2, dh3, dh4);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
dhConcat = concat(PADDING, dh1, dh2, dh3);
|
|
22
|
+
}
|
|
23
|
+
const sharedSecret = hkdf(sha256, dhConcat, new Uint8Array(32), X3DH_INFO, 32);
|
|
24
|
+
const sendKeyPair = generateX25519KeyPair();
|
|
25
|
+
const session = {
|
|
26
|
+
dhSendKeyPair: sendKeyPair,
|
|
27
|
+
dhRecvPublicKey: theirBundle.signedPreKey,
|
|
28
|
+
rootKey: sharedSecret,
|
|
29
|
+
sendChainKey: null,
|
|
30
|
+
recvChainKey: null,
|
|
31
|
+
sendMessageNumber: 0,
|
|
32
|
+
recvMessageNumber: 0,
|
|
33
|
+
previousChainLength: 0,
|
|
34
|
+
skippedKeys: new Map(),
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
session,
|
|
38
|
+
ephemeralPublicKey: ephemeral.publicKey,
|
|
39
|
+
signedPreKeyId: theirBundle.signedPreKeyId,
|
|
40
|
+
oneTimePreKeyId: theirBundle.oneTimePreKeyId,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function x3dhRespond(ourIdentityKeyPair, ourSignedPreKeyPair, theirIdentityKey, theirEphemeralKey, ourOneTimePreKeyPair) {
|
|
44
|
+
// DH1: their identity <-> our signed pre-key
|
|
45
|
+
const dh1 = x25519SharedSecret(ourSignedPreKeyPair.privateKey, theirIdentityKey);
|
|
46
|
+
// DH2: their ephemeral <-> our identity
|
|
47
|
+
const dh2 = x25519SharedSecret(ourIdentityKeyPair.privateKey, theirEphemeralKey);
|
|
48
|
+
// DH3: their ephemeral <-> our signed pre-key
|
|
49
|
+
const dh3 = x25519SharedSecret(ourSignedPreKeyPair.privateKey, theirEphemeralKey);
|
|
50
|
+
let dhConcat;
|
|
51
|
+
if (ourOneTimePreKeyPair) {
|
|
52
|
+
const dh4 = x25519SharedSecret(ourOneTimePreKeyPair.privateKey, theirEphemeralKey);
|
|
53
|
+
dhConcat = concat(PADDING, dh1, dh2, dh3, dh4);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
dhConcat = concat(PADDING, dh1, dh2, dh3);
|
|
57
|
+
}
|
|
58
|
+
const sharedSecret = hkdf(sha256, dhConcat, new Uint8Array(32), X3DH_INFO, 32);
|
|
59
|
+
return {
|
|
60
|
+
dhSendKeyPair: ourSignedPreKeyPair,
|
|
61
|
+
dhRecvPublicKey: null,
|
|
62
|
+
rootKey: sharedSecret,
|
|
63
|
+
sendChainKey: null,
|
|
64
|
+
recvChainKey: null,
|
|
65
|
+
sendMessageNumber: 0,
|
|
66
|
+
recvMessageNumber: 0,
|
|
67
|
+
previousChainLength: 0,
|
|
68
|
+
skippedKeys: new Map(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function buildAssociatedData(senderIdentityKey, recipientIdentityKey) {
|
|
72
|
+
return concat(senderIdentityKey, recipientIdentityKey);
|
|
73
|
+
}
|
|
74
|
+
function concat(...arrays) {
|
|
75
|
+
let totalLength = 0;
|
|
76
|
+
for (const array of arrays) {
|
|
77
|
+
totalLength += array.length;
|
|
78
|
+
}
|
|
79
|
+
const result = new Uint8Array(totalLength);
|
|
80
|
+
let offset = 0;
|
|
81
|
+
for (const array of arrays) {
|
|
82
|
+
result.set(array, offset);
|
|
83
|
+
offset += array.length;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
package/dist/signer.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SigningKey } from "./auth.js";
|
|
2
|
+
import type { X25519KeyPair } from "./signal/crypto.js";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base for all signing strategies. Subclass this to plug in
|
|
5
|
+
* remote wallets (e.g. OpenHuman), HSMs, or any API-based signer.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Signer implements SigningKey {
|
|
8
|
+
abstract readonly agentId: string;
|
|
9
|
+
abstract readonly publicKeyBase64: string;
|
|
10
|
+
abstract sign(data: Uint8Array): Promise<Uint8Array> | Uint8Array;
|
|
11
|
+
abstract getX25519KeyPair(): Promise<X25519KeyPair>;
|
|
12
|
+
toSigningKey(): SigningKey;
|
|
13
|
+
}
|
package/dist/signer.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type BroadcastVisibility = "public" | "unlisted";
|
|
2
|
+
export type BroadcastEncryption = "none" | "envelope";
|
|
3
|
+
export type BroadcastPaymentType = "free" | "subscription" | "per-message";
|
|
4
|
+
export interface BroadcastSubscriptionPrice {
|
|
5
|
+
amount: string;
|
|
6
|
+
asset: string;
|
|
7
|
+
network: string;
|
|
8
|
+
interval: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BroadcastPaymentPolicy {
|
|
11
|
+
type: BroadcastPaymentType;
|
|
12
|
+
subscription?: BroadcastSubscriptionPrice;
|
|
13
|
+
}
|
|
14
|
+
export interface BroadcastChannel {
|
|
15
|
+
broadcastId: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
owner: string;
|
|
19
|
+
ownerCryptoId?: string;
|
|
20
|
+
publishers: Array<string>;
|
|
21
|
+
subscriberCount: number;
|
|
22
|
+
tags?: Array<string>;
|
|
23
|
+
visibility: BroadcastVisibility;
|
|
24
|
+
encryption: BroadcastEncryption;
|
|
25
|
+
paymentPolicy?: BroadcastPaymentPolicy;
|
|
26
|
+
keyVersion?: number;
|
|
27
|
+
keyRotatedAt?: string;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
lastActivityAt?: string;
|
|
31
|
+
closedAt?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface BroadcastQueryParams {
|
|
34
|
+
q?: string;
|
|
35
|
+
tag?: string;
|
|
36
|
+
tags?: Array<string>;
|
|
37
|
+
owner?: string;
|
|
38
|
+
visibility?: BroadcastVisibility;
|
|
39
|
+
paymentType?: BroadcastPaymentType;
|
|
40
|
+
sort?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface BroadcastSubscriber {
|
|
44
|
+
broadcastId: string;
|
|
45
|
+
agentId: string;
|
|
46
|
+
subscribedAt: string;
|
|
47
|
+
status: string;
|
|
48
|
+
paymentScheme?: string;
|
|
49
|
+
paymentNetwork?: string;
|
|
50
|
+
paymentAsset?: string;
|
|
51
|
+
paymentAmount?: string;
|
|
52
|
+
paymentInterval?: string;
|
|
53
|
+
paymentExpiresAt?: string;
|
|
54
|
+
nextPaymentAt?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface BroadcastMessage {
|
|
57
|
+
messageId: string;
|
|
58
|
+
broadcastId: string;
|
|
59
|
+
publisher: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
contentType: string;
|
|
62
|
+
body: string;
|
|
63
|
+
sequence: number;
|
|
64
|
+
deletedAt?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface BroadcastCreateRequest {
|
|
67
|
+
name: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
tags?: Array<string>;
|
|
70
|
+
visibility?: BroadcastVisibility;
|
|
71
|
+
encryption?: BroadcastEncryption;
|
|
72
|
+
paymentPolicy?: BroadcastPaymentPolicy;
|
|
73
|
+
signature?: string;
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { LedgerType } from "./ledger.js";
|
|
2
|
+
export interface MoneyAmount {
|
|
3
|
+
asset: string;
|
|
4
|
+
amount: string;
|
|
5
|
+
network?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FeeAmount {
|
|
8
|
+
amount: string;
|
|
9
|
+
asset: string;
|
|
10
|
+
percent?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface PriceQuote {
|
|
13
|
+
base: string;
|
|
14
|
+
quote: string;
|
|
15
|
+
network?: string;
|
|
16
|
+
bid: string;
|
|
17
|
+
ask: string;
|
|
18
|
+
mid: string;
|
|
19
|
+
volume24h: string;
|
|
20
|
+
change24h: string;
|
|
21
|
+
source: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export interface PriceCandle {
|
|
25
|
+
open: string;
|
|
26
|
+
high: string;
|
|
27
|
+
low: string;
|
|
28
|
+
close: string;
|
|
29
|
+
volume: string;
|
|
30
|
+
timestamp: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PriceHistory {
|
|
33
|
+
base: string;
|
|
34
|
+
quote: string;
|
|
35
|
+
interval: string;
|
|
36
|
+
candles: Array<PriceCandle>;
|
|
37
|
+
}
|
|
38
|
+
export interface GasEstimate {
|
|
39
|
+
network: string;
|
|
40
|
+
unit: string;
|
|
41
|
+
slow: string;
|
|
42
|
+
standard: string;
|
|
43
|
+
fast: string;
|
|
44
|
+
estimatedFee?: string;
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
}
|
|
47
|
+
export interface TradePair {
|
|
48
|
+
base: string;
|
|
49
|
+
quote: string;
|
|
50
|
+
networks: Array<string>;
|
|
51
|
+
}
|
|
52
|
+
export interface SwapQuote {
|
|
53
|
+
quoteId: string;
|
|
54
|
+
from: MoneyAmount;
|
|
55
|
+
to: MoneyAmount;
|
|
56
|
+
rate: string;
|
|
57
|
+
priceImpact: string;
|
|
58
|
+
fee: FeeAmount;
|
|
59
|
+
route: Array<string>;
|
|
60
|
+
expiresAt: string;
|
|
61
|
+
slippageTolerance: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SwapExecuteRequest {
|
|
64
|
+
quoteId: string;
|
|
65
|
+
paymentAuthorization: string;
|
|
66
|
+
slippageTolerance?: string;
|
|
67
|
+
deadline?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface SwapExecution {
|
|
70
|
+
swapId: string;
|
|
71
|
+
quoteId: string;
|
|
72
|
+
agentId?: string;
|
|
73
|
+
status: string;
|
|
74
|
+
from: MoneyAmount;
|
|
75
|
+
to: MoneyAmount;
|
|
76
|
+
txHash?: string;
|
|
77
|
+
ledgerEntry?: string;
|
|
78
|
+
completedAt?: string;
|
|
79
|
+
createdAt: string;
|
|
80
|
+
}
|
|
81
|
+
export interface BridgeRoute {
|
|
82
|
+
provider: string;
|
|
83
|
+
from: MoneyAmount;
|
|
84
|
+
to: MoneyAmount;
|
|
85
|
+
estimatedTime: string;
|
|
86
|
+
fee: FeeAmount;
|
|
87
|
+
minAmount: string;
|
|
88
|
+
maxAmount: string;
|
|
89
|
+
}
|
|
90
|
+
export interface BridgeQuote {
|
|
91
|
+
quoteId: string;
|
|
92
|
+
from: MoneyAmount;
|
|
93
|
+
to: MoneyAmount;
|
|
94
|
+
provider: string;
|
|
95
|
+
fee: FeeAmount;
|
|
96
|
+
estimatedTime: string;
|
|
97
|
+
expiresAt: string;
|
|
98
|
+
}
|
|
99
|
+
export interface BridgeExecuteRequest {
|
|
100
|
+
quoteId: string;
|
|
101
|
+
destinationAddress: string;
|
|
102
|
+
paymentAuthorization: string;
|
|
103
|
+
}
|
|
104
|
+
export interface BridgeExecution {
|
|
105
|
+
bridgeId: string;
|
|
106
|
+
quoteId: string;
|
|
107
|
+
agentId?: string;
|
|
108
|
+
status: string;
|
|
109
|
+
from: MoneyAmount;
|
|
110
|
+
to: MoneyAmount;
|
|
111
|
+
provider: string;
|
|
112
|
+
destinationAddress: string;
|
|
113
|
+
txHash?: string;
|
|
114
|
+
sourceTxHash?: string;
|
|
115
|
+
destinationTxHash?: string;
|
|
116
|
+
ledgerEntry?: string;
|
|
117
|
+
completedAt?: string;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
}
|
|
120
|
+
export interface FeeConfig {
|
|
121
|
+
feeId: string;
|
|
122
|
+
scope: string;
|
|
123
|
+
transactionType: LedgerType;
|
|
124
|
+
agents: Array<string>;
|
|
125
|
+
rate: string;
|
|
126
|
+
effectiveFrom: string;
|
|
127
|
+
effectiveUntil?: string;
|
|
128
|
+
createdBy: string;
|
|
129
|
+
reason: string;
|
|
130
|
+
revoked: boolean;
|
|
131
|
+
updatedAt: string;
|
|
132
|
+
}
|
|
133
|
+
export interface AgentPaymentStatus {
|
|
134
|
+
handle: string;
|
|
135
|
+
status: string;
|
|
136
|
+
reason?: string;
|
|
137
|
+
updatedBy: string;
|
|
138
|
+
updatedAt: string;
|
|
139
|
+
}
|
|
140
|
+
export interface AdminAuditEntry {
|
|
141
|
+
auditId: string;
|
|
142
|
+
action: string;
|
|
143
|
+
actor: string;
|
|
144
|
+
timestamp: string;
|
|
145
|
+
params: Record<string, string>;
|
|
146
|
+
reason: string;
|
|
147
|
+
}
|
|
148
|
+
export interface SystemConfig {
|
|
149
|
+
key: string;
|
|
150
|
+
value: string;
|
|
151
|
+
updatedBy: string;
|
|
152
|
+
updatedAt: string;
|
|
153
|
+
}
|
|
154
|
+
export interface StatsSnapshot {
|
|
155
|
+
timestamp: string;
|
|
156
|
+
agents: AgentStats;
|
|
157
|
+
transactions: TransactionStats;
|
|
158
|
+
volume: VolumeStats;
|
|
159
|
+
fees: FeeStats;
|
|
160
|
+
}
|
|
161
|
+
export interface AgentStats {
|
|
162
|
+
registered: number;
|
|
163
|
+
active_30d: number;
|
|
164
|
+
directory_cards: number;
|
|
165
|
+
groups: number;
|
|
166
|
+
}
|
|
167
|
+
export interface TransactionStats {
|
|
168
|
+
total: number;
|
|
169
|
+
settled: number;
|
|
170
|
+
by_type: Record<string, number>;
|
|
171
|
+
}
|
|
172
|
+
export interface VolumeStats {
|
|
173
|
+
total_usd: string;
|
|
174
|
+
by_asset: Record<string, string>;
|
|
175
|
+
by_network: Record<string, string>;
|
|
176
|
+
last_24h_usd: string;
|
|
177
|
+
last_30d_usd: string;
|
|
178
|
+
}
|
|
179
|
+
export interface FeeStats {
|
|
180
|
+
total_usd: string;
|
|
181
|
+
last_24h_usd: string;
|
|
182
|
+
last_30d_usd: string;
|
|
183
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Identity, PaymentMethod } from "./identity.js";
|
|
2
|
+
export interface AgentInterface {
|
|
3
|
+
url: string;
|
|
4
|
+
binding: string;
|
|
5
|
+
version: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AgentPayment {
|
|
8
|
+
network: string;
|
|
9
|
+
asset: string;
|
|
10
|
+
rateType: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AgentDocs {
|
|
14
|
+
swaggerJson?: string;
|
|
15
|
+
swaggerMd?: string;
|
|
16
|
+
skillMd?: string;
|
|
17
|
+
swaggerJsonUrl?: string;
|
|
18
|
+
swaggerMdUrl?: string;
|
|
19
|
+
skillMdUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentWebhook {
|
|
22
|
+
event: string;
|
|
23
|
+
url: string;
|
|
24
|
+
secretRef?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
metadata?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentCard {
|
|
29
|
+
agentId: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
username?: string;
|
|
33
|
+
cryptoId: string;
|
|
34
|
+
publicKey?: string;
|
|
35
|
+
url?: string;
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
supportedInterfaces?: Array<AgentInterface>;
|
|
38
|
+
skills?: Array<string>;
|
|
39
|
+
capabilities?: Array<string>;
|
|
40
|
+
tags?: Array<string>;
|
|
41
|
+
paymentMethods?: Array<PaymentMethod>;
|
|
42
|
+
paymentRequirements?: AgentPayment;
|
|
43
|
+
groups?: Array<string>;
|
|
44
|
+
docs?: AgentDocs;
|
|
45
|
+
webhooks?: Array<AgentWebhook>;
|
|
46
|
+
metadata?: Record<string, string>;
|
|
47
|
+
signature?: string;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
}
|
|
51
|
+
export interface AgentInternalAPI {
|
|
52
|
+
docsUrl?: string;
|
|
53
|
+
endpoints?: Array<AgentInterface>;
|
|
54
|
+
details?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export interface ExtendedAgentCard {
|
|
57
|
+
agentId: string;
|
|
58
|
+
agent: AgentCard;
|
|
59
|
+
privateSkills?: Array<string>;
|
|
60
|
+
rateLimits?: Record<string, string>;
|
|
61
|
+
internalApi?: AgentInternalAPI;
|
|
62
|
+
metadata?: Record<string, string>;
|
|
63
|
+
updatedAt: string;
|
|
64
|
+
}
|
|
65
|
+
export interface AgentQueryParams {
|
|
66
|
+
q?: string;
|
|
67
|
+
skill?: string;
|
|
68
|
+
capability?: string;
|
|
69
|
+
tag?: string;
|
|
70
|
+
tags?: Array<string>;
|
|
71
|
+
username?: string;
|
|
72
|
+
cryptoId?: string;
|
|
73
|
+
network?: string;
|
|
74
|
+
asset?: string;
|
|
75
|
+
maxAmount?: string;
|
|
76
|
+
group?: string;
|
|
77
|
+
limit?: number;
|
|
78
|
+
offset?: number;
|
|
79
|
+
}
|
|
80
|
+
export interface ResolveResponse {
|
|
81
|
+
identity: Identity | null;
|
|
82
|
+
agent?: AgentCard;
|
|
83
|
+
}
|
|
84
|
+
export interface ReverseResponse {
|
|
85
|
+
cryptoId: string;
|
|
86
|
+
identities: Array<Identity>;
|
|
87
|
+
agents?: Array<AgentCard>;
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|