@totemsdk/edge 0.1.0 → 0.1.1

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/src/ports.ts DELETED
@@ -1,75 +0,0 @@
1
- /**
2
- * Port interfaces for @totemsdk/edge.
3
- *
4
- * All ports are interfaces only. Callers inject implementations at runtime.
5
- * @totemsdk/edge ships no proof creation/verification implementations.
6
- */
7
-
8
- import type { EdgeOperationResult } from './types.js';
9
-
10
- export interface EdgePaymentPort {
11
- pay(params: {
12
- recipient: string;
13
- amount: string;
14
- tokenId?: string;
15
- memo?: string;
16
- }): Promise<EdgeOperationResult<{ txpowId?: string }>>;
17
- }
18
-
19
- export interface EdgeLiquidityPort {
20
- getBalance(address: string): Promise<EdgeOperationResult<{ balance: string; tokenId: string }>>;
21
- getUtxos(address: string): Promise<EdgeOperationResult<{ utxos: unknown[] }>>;
22
- }
23
-
24
- export interface EdgeProofPort {
25
- createProof(params: {
26
- subject: string;
27
- claims: unknown[];
28
- context?: Record<string, unknown>;
29
- }): Promise<EdgeOperationResult<{ proofId: string; proof: unknown }>>;
30
-
31
- verifyProof(params: {
32
- proof: unknown;
33
- subject?: string;
34
- }): Promise<EdgeOperationResult<{ valid: boolean; reason?: string }>>;
35
- }
36
-
37
- export interface EdgeLookupPort {
38
- lookup(params: {
39
- query: string;
40
- kind?: string;
41
- }): Promise<EdgeOperationResult<{ results: unknown[] }>>;
42
-
43
- watch(params: {
44
- address: string;
45
- onUpdate: (data: unknown) => void;
46
- }): Promise<EdgeOperationResult<{ unsubscribe: () => void }>>;
47
- }
48
-
49
- export interface EdgePolicyPort {
50
- check(params: {
51
- action: string;
52
- subject: string;
53
- context?: Record<string, unknown>;
54
- }): Promise<EdgeOperationResult<{ allowed: boolean; reason?: string }>>;
55
- }
56
-
57
- export interface EdgeIdentityPort {
58
- resolve(identityId: string): Promise<EdgeOperationResult<{ identity: unknown }>>;
59
- verify(proof: unknown): Promise<EdgeOperationResult<{ valid: boolean; address?: string }>>;
60
- }
61
-
62
- export interface EdgeManifestPort {
63
- sign(manifest: unknown, seed: Uint8Array, keyIndex: number): Promise<EdgeOperationResult<{ signed: unknown }>>;
64
- verify(signed: unknown): Promise<EdgeOperationResult<{ valid: boolean; reason?: string }>>;
65
- }
66
-
67
- export interface EdgeRuntimePorts {
68
- payment?: EdgePaymentPort;
69
- liquidity?: EdgeLiquidityPort;
70
- proof?: EdgeProofPort;
71
- lookup?: EdgeLookupPort;
72
- policy?: EdgePolicyPort;
73
- identity?: EdgeIdentityPort;
74
- manifest?: EdgeManifestPort;
75
- }
package/src/provider.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * Provider helper functions for @totemsdk/edge.
3
- *
4
- * These functions return data structures only — they do not submit to any registry.
5
- * Registry, trust-index, watchlist, and lease-coordinator logic remain in
6
- * @totemsdk/lookup-node and future @totemsdk/proofgraph.
7
- */
8
-
9
- import { sha3_256 } from '@noble/hashes/sha3.js';
10
- import { toHex } from './canonical.js';
11
- import { signManifest, computeManifestId } from '@totemsdk/manifest';
12
- import type { EdgeServiceManifest, SignedManifest } from '@totemsdk/manifest';
13
- import { bindManifestToIdentity } from '@totemsdk/identity';
14
- import type { IdentityGraph, ManifestIdentityBinding, IdentityProofVerifier } from '@totemsdk/identity';
15
- import type { EdgeProviderProfile, EdgeServiceRegistration } from './types.js';
16
-
17
- export function createEdgeProviderProfile(opts: {
18
- operatorAddress: string;
19
- name: string;
20
- description?: string;
21
- tags?: string[];
22
- }): EdgeProviderProfile {
23
- const { operatorAddress, name, description, tags } = opts;
24
- const ts = Date.now();
25
- const raw = `edge-provider\0${operatorAddress}\0${name}\0${ts}`;
26
- const hash = sha3_256(new TextEncoder().encode(raw));
27
- const profileId = `edge:provider:${toHex(hash)}`;
28
- return {
29
- profileId,
30
- operatorAddress,
31
- name,
32
- ...(description !== undefined ? { description } : {}),
33
- tags: tags ?? [],
34
- createdAt: ts,
35
- };
36
- }
37
-
38
- export function createEdgeServiceRegistration(opts: {
39
- profileId: string;
40
- serviceId: string;
41
- operatorAddress: string;
42
- expiresAt?: number;
43
- metadata?: Record<string, unknown>;
44
- }): EdgeServiceRegistration {
45
- const { profileId, serviceId, operatorAddress, expiresAt, metadata } = opts;
46
- const ts = Date.now();
47
- const raw = `edge-svc-reg\0${profileId}\0${serviceId}\0${operatorAddress}\0${ts}`;
48
- const hash = sha3_256(new TextEncoder().encode(raw));
49
- const registrationId = `edge:registration:${toHex(hash)}`;
50
- return {
51
- registrationId,
52
- profileId,
53
- serviceId,
54
- operatorAddress,
55
- registeredAt: ts,
56
- ...(expiresAt !== undefined ? { expiresAt } : {}),
57
- ...(metadata !== undefined ? { metadata } : {}),
58
- };
59
- }
60
-
61
- export async function createEdgeServiceManifest(
62
- manifest: EdgeServiceManifest,
63
- seed: Uint8Array,
64
- keyIndex: number,
65
- ): Promise<SignedManifest<EdgeServiceManifest>> {
66
- return signManifest(manifest, seed, keyIndex);
67
- }
68
-
69
- export async function bindEdgeServiceIdentity(
70
- signedManifest: SignedManifest<EdgeServiceManifest>,
71
- identityGraph: IdentityGraph,
72
- options?: {
73
- proofVerifiers?: Record<string, IdentityProofVerifier>;
74
- },
75
- ): Promise<ManifestIdentityBinding> {
76
- return bindManifestToIdentity(signedManifest, identityGraph, options);
77
- }
package/src/receipts.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * Edge receipt creation and verification.
3
- *
4
- * EdgeReceipt is an app/runtime-level receipt. It may reference existing
5
- * receipt IDs from other layers via relatedManifestId, relatedIdentityId,
6
- * and payload fields. It does NOT represent chain-level settlement finality.
7
- *
8
- * verifyEdgeReceipt always returns a structured EdgeOperationResult, never a bare boolean.
9
- */
10
-
11
- import { sha3_256 } from '@noble/hashes/sha3.js';
12
- import { canonicalJson, toHex } from './canonical.js';
13
- import type { EdgeReceipt, EdgeOperationResult } from './types.js';
14
-
15
- export function createEdgeReceipt(opts: {
16
- kind: string;
17
- payload: Record<string, unknown>;
18
- relatedManifestId?: string;
19
- relatedIdentityId?: string;
20
- issuedAt?: number;
21
- }): EdgeReceipt {
22
- const { kind, payload, relatedManifestId, relatedIdentityId } = opts;
23
- const issuedAt = opts.issuedAt ?? Date.now();
24
-
25
- const canonical = canonicalJson({ kind, payload, relatedManifestId, relatedIdentityId, issuedAt });
26
- const hash = sha3_256(new TextEncoder().encode(canonical));
27
- const receiptId = `edge:receipt:${toHex(hash)}`;
28
-
29
- return {
30
- receiptId,
31
- kind,
32
- issuedAt,
33
- ...(relatedManifestId !== undefined ? { relatedManifestId } : {}),
34
- ...(relatedIdentityId !== undefined ? { relatedIdentityId } : {}),
35
- payload,
36
- };
37
- }
38
-
39
- export function verifyEdgeReceipt(receipt: unknown): EdgeOperationResult<{ receipt: EdgeReceipt }> {
40
- if (!receipt || typeof receipt !== 'object') {
41
- return { ok: false, error: 'receipt is not an object', errorCode: 'INVALID_RECEIPT' };
42
- }
43
-
44
- const r = receipt as Record<string, unknown>;
45
-
46
- if (typeof r.receiptId !== 'string') {
47
- return { ok: false, error: 'receipt.receiptId must be a string', errorCode: 'INVALID_RECEIPT' };
48
- }
49
- if (typeof r.kind !== 'string') {
50
- return { ok: false, error: 'receipt.kind must be a string', errorCode: 'INVALID_RECEIPT' };
51
- }
52
- if (typeof r.issuedAt !== 'number') {
53
- return { ok: false, error: 'receipt.issuedAt must be a number', errorCode: 'INVALID_RECEIPT' };
54
- }
55
- if (!r.payload || typeof r.payload !== 'object') {
56
- return { ok: false, error: 'receipt.payload must be an object', errorCode: 'INVALID_RECEIPT' };
57
- }
58
-
59
- return { ok: true, data: { receipt: receipt as EdgeReceipt } };
60
- }
package/src/runtime.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Edge runtime factory.
3
- */
4
-
5
- import { EDGE_VERSION } from './constants.js';
6
- import {
7
- EdgeCapabilitySet,
8
- EdgeCapability,
9
- hasCapability,
10
- assertCapability,
11
- } from './capabilities.js';
12
- import type { EdgeRuntimePorts } from './ports.js';
13
- import type { EdgeRuntime } from './types.js';
14
-
15
- export function createEdgeRuntime(opts: {
16
- deviceId: string;
17
- capabilities: EdgeCapabilitySet;
18
- ports: EdgeRuntimePorts;
19
- }): EdgeRuntime {
20
- const { deviceId, capabilities, ports } = opts;
21
- return {
22
- version: EDGE_VERSION,
23
- deviceId,
24
- capabilities,
25
- ports,
26
- hasCapability(cap: EdgeCapability): boolean {
27
- return hasCapability(capabilities, cap);
28
- },
29
- assertCapability(cap: EdgeCapability): void {
30
- assertCapability(capabilities, cap);
31
- },
32
- };
33
- }
package/src/types.ts DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * @totemsdk/edge — Type definitions
3
- *
4
- * Covers devices, apps, agents, sensors, robots, gateways, and services.
5
- * Adapter-neutral — no ROS2, no MQTT, no Python bindings.
6
- */
7
-
8
- import type { ManifestIdentityBinding } from '@totemsdk/identity';
9
- import type { SignedManifest, EdgeServiceManifest } from '@totemsdk/manifest';
10
-
11
- export type EdgeDeviceKind =
12
- | 'device'
13
- | 'app'
14
- | 'agent'
15
- | 'sensor'
16
- | 'robot'
17
- | 'gateway'
18
- | 'service';
19
-
20
- export interface EdgeOperationResult<T = unknown> {
21
- ok: boolean;
22
- data?: T;
23
- error?: string;
24
- errorCode?: string;
25
- }
26
-
27
- export interface EdgeDevice {
28
- deviceId: string;
29
- kind: EdgeDeviceKind;
30
- identityId?: string;
31
- address?: string;
32
- metadata?: Record<string, unknown>;
33
- createdAt: number;
34
- }
35
-
36
- export interface EdgeRuntime {
37
- version: number;
38
- deviceId: string;
39
- capabilities: import('./capabilities.js').EdgeCapabilitySet;
40
- ports: import('./ports.js').EdgeRuntimePorts;
41
- hasCapability(cap: import('./capabilities.js').EdgeCapability): boolean;
42
- assertCapability(cap: import('./capabilities.js').EdgeCapability): void;
43
- }
44
-
45
- export interface EdgeProviderProfile {
46
- profileId: string;
47
- operatorAddress: string;
48
- name: string;
49
- description?: string;
50
- tags: string[];
51
- createdAt: number;
52
- }
53
-
54
- export interface EdgeServiceRegistration {
55
- registrationId: string;
56
- profileId: string;
57
- serviceId: string;
58
- operatorAddress: string;
59
- registeredAt: number;
60
- expiresAt?: number;
61
- metadata?: Record<string, unknown>;
62
- }
63
-
64
- export interface EdgeReceipt {
65
- receiptId: string;
66
- kind: string;
67
- issuedAt: number;
68
- relatedManifestId?: string;
69
- relatedIdentityId?: string;
70
- payload: Record<string, unknown>;
71
- }
72
-
73
- export type { ManifestIdentityBinding, SignedManifest, EdgeServiceManifest };