@totemsdk/edge-adapters 0.2.0 → 0.3.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/artifact-cache.d.ts +36 -0
- package/dist/artifact-cache.js +79 -0
- package/dist/cjs/artifact-cache.d.ts +36 -0
- package/dist/cjs/artifact-cache.js +82 -0
- package/dist/cjs/identity.d.ts +19 -0
- package/dist/cjs/identity.js +61 -0
- package/dist/cjs/index.d.ts +25 -0
- package/dist/cjs/index.js +41 -0
- package/dist/cjs/liquidity.d.ts +15 -0
- package/dist/cjs/liquidity.js +45 -0
- package/dist/cjs/location.d.ts +48 -0
- package/dist/cjs/location.js +208 -0
- package/dist/cjs/lookup.d.ts +13 -0
- package/dist/cjs/lookup.js +96 -0
- package/dist/cjs/manifest.d.ts +11 -0
- package/dist/cjs/manifest.js +36 -0
- package/dist/cjs/negotiation-transport.d.ts +50 -0
- package/dist/cjs/negotiation-transport.js +122 -0
- package/dist/cjs/omnia.d.ts +7 -0
- package/dist/cjs/omnia.js +46 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/payment-l1.d.ts +38 -0
- package/dist/cjs/payment-l1.js +46 -0
- package/dist/cjs/payment-l2.d.ts +39 -0
- package/dist/cjs/payment-l2.js +54 -0
- package/dist/cjs/policy.d.ts +13 -0
- package/dist/cjs/policy.js +95 -0
- package/dist/cjs/proof.d.ts +48 -0
- package/dist/cjs/proof.js +88 -0
- package/dist/cjs/pubsub.d.ts +11 -0
- package/dist/cjs/pubsub.js +30 -0
- package/dist/cjs/purchase-authority.d.ts +42 -0
- package/dist/cjs/purchase-authority.js +79 -0
- package/dist/cjs/purchase-lookup.d.ts +44 -0
- package/dist/cjs/purchase-lookup.js +60 -0
- package/dist/cjs/purchase-payment.d.ts +78 -0
- package/dist/cjs/purchase-payment.js +108 -0
- package/dist/cjs/sqlite-commerce-store.d.ts +69 -0
- package/dist/cjs/sqlite-commerce-store.js +416 -0
- package/dist/cjs/stream.d.ts +7 -0
- package/dist/cjs/stream.js +26 -0
- package/dist/identity.js +4 -7
- package/dist/index.d.ts +6 -0
- package/dist/index.js +18 -27
- package/dist/liquidity.js +1 -4
- package/dist/location.js +10 -13
- package/dist/lookup.js +3 -6
- package/dist/manifest.js +5 -7
- package/dist/negotiation-transport.d.ts +50 -0
- package/dist/negotiation-transport.js +118 -0
- package/dist/omnia.js +1 -4
- package/dist/payment-l1.js +1 -4
- package/dist/payment-l2.js +5 -8
- package/dist/policy.js +1 -4
- package/dist/proof.js +7 -10
- package/dist/pubsub.js +1 -4
- package/dist/purchase-authority.d.ts +42 -0
- package/dist/purchase-authority.js +76 -0
- package/dist/purchase-lookup.d.ts +44 -0
- package/dist/purchase-lookup.js +57 -0
- package/dist/purchase-payment.d.ts +78 -0
- package/dist/purchase-payment.js +105 -0
- package/dist/sqlite-commerce-store.d.ts +69 -0
- package/dist/sqlite-commerce-store.js +411 -0
- package/dist/stream.js +1 -4
- package/package.json +37 -26
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* edge-adapters/artifact-cache.ts — RFC-007 Amendment A, phase A1.
|
|
3
|
+
*
|
|
4
|
+
* The first consumer of the Edge persistence injection point (`PersistencePorts`).
|
|
5
|
+
* A scoped, content-addressed artifact cache over the injected `storage` (KV
|
|
6
|
+
* retention index) and `artifacts` (byte store) surfaces.
|
|
7
|
+
*
|
|
8
|
+
* Typed structurally against `@totemsdk/storage` — this module must NOT import
|
|
9
|
+
* `@totemsdk/edge`, so it carries no Edge runtime dependency.
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - `assertPersistence()` validates surfaces/capabilities at construction.
|
|
13
|
+
* - Scope is collision-control only (namespaces); authorization stays above.
|
|
14
|
+
* - Retrieval re-verifies digests via `ArtifactStore.get` (`corrupt` vs
|
|
15
|
+
* `not-found` are never conflated).
|
|
16
|
+
* - Retention/expiry entries survive restart when the injected storage is durable.
|
|
17
|
+
*/
|
|
18
|
+
import type { ArtifactBackendCapabilities, ArtifactRead, ArtifactRef, EffectivePersistence, PersistencePorts, PersistenceRequirement, StorageScope } from '@totemsdk/storage';
|
|
19
|
+
/**
|
|
20
|
+
* Per-object cache policy. Deliberately does NOT reuse the `retention:
|
|
21
|
+
* 'fixed'|'managed'|'none'` vocabulary: that is a BACKEND capability, not a
|
|
22
|
+
* per-object request.
|
|
23
|
+
*/
|
|
24
|
+
export interface ArtifactCacheRetentionPolicy {
|
|
25
|
+
readonly ttlMs?: number;
|
|
26
|
+
readonly invalidateOnExpiry?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface EdgeArtifactCache {
|
|
29
|
+
readonly capabilities: ArtifactBackendCapabilities;
|
|
30
|
+
/** Reported after assertPersistence(); callers must never assume durability. */
|
|
31
|
+
readonly effective: EffectivePersistence;
|
|
32
|
+
put(scope: StorageScope, bytes: Uint8Array, policy?: ArtifactCacheRetentionPolicy): Promise<ArtifactRef>;
|
|
33
|
+
get(scope: StorageScope, ref: ArtifactRef, policy?: ArtifactCacheRetentionPolicy): Promise<ArtifactRead>;
|
|
34
|
+
invalidate(scope: StorageScope, ref: ArtifactRef): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createEdgeArtifactCache(ports: PersistencePorts, requirement?: PersistenceRequirement, policy?: ArtifactCacheRetentionPolicy): EdgeArtifactCache;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* edge-adapters/artifact-cache.ts — RFC-007 Amendment A, phase A1.
|
|
3
|
+
*
|
|
4
|
+
* The first consumer of the Edge persistence injection point (`PersistencePorts`).
|
|
5
|
+
* A scoped, content-addressed artifact cache over the injected `storage` (KV
|
|
6
|
+
* retention index) and `artifacts` (byte store) surfaces.
|
|
7
|
+
*
|
|
8
|
+
* Typed structurally against `@totemsdk/storage` — this module must NOT import
|
|
9
|
+
* `@totemsdk/edge`, so it carries no Edge runtime dependency.
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - `assertPersistence()` validates surfaces/capabilities at construction.
|
|
13
|
+
* - Scope is collision-control only (namespaces); authorization stays above.
|
|
14
|
+
* - Retrieval re-verifies digests via `ArtifactStore.get` (`corrupt` vs
|
|
15
|
+
* `not-found` are never conflated).
|
|
16
|
+
* - Retention/expiry entries survive restart when the injected storage is durable.
|
|
17
|
+
*/
|
|
18
|
+
import { StorageError, artifactRefId, assertPersistence, createScopedStorage, } from '@totemsdk/storage';
|
|
19
|
+
/** Scope-derived artifact namespace: separate scopes never alias the same blob. */
|
|
20
|
+
function scopeNamespace(scope) {
|
|
21
|
+
const parts = [scope.principal, scope.adapter, scope.purpose, scope.domain]
|
|
22
|
+
.filter((p) => typeof p === 'string' && p.length > 0)
|
|
23
|
+
.map((p) => encodeURIComponent(p));
|
|
24
|
+
return `edge-cache:${parts.join('/')}`;
|
|
25
|
+
}
|
|
26
|
+
export function createEdgeArtifactCache(ports, requirement = { durable: false }, policy = {}) {
|
|
27
|
+
const label = 'edge-artifact-cache';
|
|
28
|
+
// The cache always needs both surfaces and a deletable artifact backend.
|
|
29
|
+
const effective = assertPersistence(ports, { ...requirement, needsArtifacts: true, needsArtifactDelete: true }, label);
|
|
30
|
+
const storage = ports.storage;
|
|
31
|
+
const artifacts = ports.artifacts;
|
|
32
|
+
if (!storage) {
|
|
33
|
+
throw new StorageError(`${label}: a storage index is required for retention/expiry`, 'unavailable');
|
|
34
|
+
}
|
|
35
|
+
if (!artifacts) {
|
|
36
|
+
throw new StorageError(`${label}: an artifact store is required`, 'unavailable');
|
|
37
|
+
}
|
|
38
|
+
const defaultTtlMs = policy.ttlMs;
|
|
39
|
+
const defaultInvalidateOnExpiry = policy.invalidateOnExpiry ?? false;
|
|
40
|
+
const now = () => Date.now();
|
|
41
|
+
const scoped = (scope) => createScopedStorage(storage, scope);
|
|
42
|
+
return {
|
|
43
|
+
capabilities: artifacts.capabilities,
|
|
44
|
+
effective,
|
|
45
|
+
async put(scope, bytes, putPolicy) {
|
|
46
|
+
const ttlMs = putPolicy?.ttlMs ?? defaultTtlMs;
|
|
47
|
+
const receipt = await artifacts.put(scopeNamespace(scope), bytes, {
|
|
48
|
+
...(ttlMs !== undefined ? { retentionMs: ttlMs } : {}),
|
|
49
|
+
});
|
|
50
|
+
const entry = {
|
|
51
|
+
ref: receipt.ref,
|
|
52
|
+
size: receipt.size,
|
|
53
|
+
createdAt: now(),
|
|
54
|
+
...(ttlMs !== undefined ? { expiresAt: now() + ttlMs } : {}),
|
|
55
|
+
};
|
|
56
|
+
await scoped(scope).set(artifactRefId(receipt.ref), entry);
|
|
57
|
+
return receipt.ref;
|
|
58
|
+
},
|
|
59
|
+
async get(scope, ref, getPolicy) {
|
|
60
|
+
const entry = await scoped(scope).get(artifactRefId(ref));
|
|
61
|
+
if (!entry) {
|
|
62
|
+
// Not known to this scope — never fall through to the raw backend.
|
|
63
|
+
return { status: 'not-found' };
|
|
64
|
+
}
|
|
65
|
+
if (entry.expiresAt !== undefined && now() > entry.expiresAt) {
|
|
66
|
+
const invalidate = getPolicy?.invalidateOnExpiry ?? defaultInvalidateOnExpiry;
|
|
67
|
+
if (invalidate)
|
|
68
|
+
await this.invalidate(scope, ref);
|
|
69
|
+
return { status: 'not-found' };
|
|
70
|
+
}
|
|
71
|
+
// Digest re-verification + corrupt/not-found taxonomy live in ArtifactStore.
|
|
72
|
+
return artifacts.get(ref);
|
|
73
|
+
},
|
|
74
|
+
async invalidate(scope, ref) {
|
|
75
|
+
await artifacts.delete(ref);
|
|
76
|
+
await scoped(scope).remove(artifactRefId(ref));
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* edge-adapters/artifact-cache.ts — RFC-007 Amendment A, phase A1.
|
|
3
|
+
*
|
|
4
|
+
* The first consumer of the Edge persistence injection point (`PersistencePorts`).
|
|
5
|
+
* A scoped, content-addressed artifact cache over the injected `storage` (KV
|
|
6
|
+
* retention index) and `artifacts` (byte store) surfaces.
|
|
7
|
+
*
|
|
8
|
+
* Typed structurally against `@totemsdk/storage` — this module must NOT import
|
|
9
|
+
* `@totemsdk/edge`, so it carries no Edge runtime dependency.
|
|
10
|
+
*
|
|
11
|
+
* Guarantees:
|
|
12
|
+
* - `assertPersistence()` validates surfaces/capabilities at construction.
|
|
13
|
+
* - Scope is collision-control only (namespaces); authorization stays above.
|
|
14
|
+
* - Retrieval re-verifies digests via `ArtifactStore.get` (`corrupt` vs
|
|
15
|
+
* `not-found` are never conflated).
|
|
16
|
+
* - Retention/expiry entries survive restart when the injected storage is durable.
|
|
17
|
+
*/
|
|
18
|
+
import type { ArtifactBackendCapabilities, ArtifactRead, ArtifactRef, EffectivePersistence, PersistencePorts, PersistenceRequirement, StorageScope } from '@totemsdk/storage';
|
|
19
|
+
/**
|
|
20
|
+
* Per-object cache policy. Deliberately does NOT reuse the `retention:
|
|
21
|
+
* 'fixed'|'managed'|'none'` vocabulary: that is a BACKEND capability, not a
|
|
22
|
+
* per-object request.
|
|
23
|
+
*/
|
|
24
|
+
export interface ArtifactCacheRetentionPolicy {
|
|
25
|
+
readonly ttlMs?: number;
|
|
26
|
+
readonly invalidateOnExpiry?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface EdgeArtifactCache {
|
|
29
|
+
readonly capabilities: ArtifactBackendCapabilities;
|
|
30
|
+
/** Reported after assertPersistence(); callers must never assume durability. */
|
|
31
|
+
readonly effective: EffectivePersistence;
|
|
32
|
+
put(scope: StorageScope, bytes: Uint8Array, policy?: ArtifactCacheRetentionPolicy): Promise<ArtifactRef>;
|
|
33
|
+
get(scope: StorageScope, ref: ArtifactRef, policy?: ArtifactCacheRetentionPolicy): Promise<ArtifactRead>;
|
|
34
|
+
invalidate(scope: StorageScope, ref: ArtifactRef): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createEdgeArtifactCache(ports: PersistencePorts, requirement?: PersistenceRequirement, policy?: ArtifactCacheRetentionPolicy): EdgeArtifactCache;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* edge-adapters/artifact-cache.ts — RFC-007 Amendment A, phase A1.
|
|
4
|
+
*
|
|
5
|
+
* The first consumer of the Edge persistence injection point (`PersistencePorts`).
|
|
6
|
+
* A scoped, content-addressed artifact cache over the injected `storage` (KV
|
|
7
|
+
* retention index) and `artifacts` (byte store) surfaces.
|
|
8
|
+
*
|
|
9
|
+
* Typed structurally against `@totemsdk/storage` — this module must NOT import
|
|
10
|
+
* `@totemsdk/edge`, so it carries no Edge runtime dependency.
|
|
11
|
+
*
|
|
12
|
+
* Guarantees:
|
|
13
|
+
* - `assertPersistence()` validates surfaces/capabilities at construction.
|
|
14
|
+
* - Scope is collision-control only (namespaces); authorization stays above.
|
|
15
|
+
* - Retrieval re-verifies digests via `ArtifactStore.get` (`corrupt` vs
|
|
16
|
+
* `not-found` are never conflated).
|
|
17
|
+
* - Retention/expiry entries survive restart when the injected storage is durable.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.createEdgeArtifactCache = createEdgeArtifactCache;
|
|
21
|
+
const storage_1 = require("@totemsdk/storage");
|
|
22
|
+
/** Scope-derived artifact namespace: separate scopes never alias the same blob. */
|
|
23
|
+
function scopeNamespace(scope) {
|
|
24
|
+
const parts = [scope.principal, scope.adapter, scope.purpose, scope.domain]
|
|
25
|
+
.filter((p) => typeof p === 'string' && p.length > 0)
|
|
26
|
+
.map((p) => encodeURIComponent(p));
|
|
27
|
+
return `edge-cache:${parts.join('/')}`;
|
|
28
|
+
}
|
|
29
|
+
function createEdgeArtifactCache(ports, requirement = { durable: false }, policy = {}) {
|
|
30
|
+
const label = 'edge-artifact-cache';
|
|
31
|
+
// The cache always needs both surfaces and a deletable artifact backend.
|
|
32
|
+
const effective = (0, storage_1.assertPersistence)(ports, { ...requirement, needsArtifacts: true, needsArtifactDelete: true }, label);
|
|
33
|
+
const storage = ports.storage;
|
|
34
|
+
const artifacts = ports.artifacts;
|
|
35
|
+
if (!storage) {
|
|
36
|
+
throw new storage_1.StorageError(`${label}: a storage index is required for retention/expiry`, 'unavailable');
|
|
37
|
+
}
|
|
38
|
+
if (!artifacts) {
|
|
39
|
+
throw new storage_1.StorageError(`${label}: an artifact store is required`, 'unavailable');
|
|
40
|
+
}
|
|
41
|
+
const defaultTtlMs = policy.ttlMs;
|
|
42
|
+
const defaultInvalidateOnExpiry = policy.invalidateOnExpiry ?? false;
|
|
43
|
+
const now = () => Date.now();
|
|
44
|
+
const scoped = (scope) => (0, storage_1.createScopedStorage)(storage, scope);
|
|
45
|
+
return {
|
|
46
|
+
capabilities: artifacts.capabilities,
|
|
47
|
+
effective,
|
|
48
|
+
async put(scope, bytes, putPolicy) {
|
|
49
|
+
const ttlMs = putPolicy?.ttlMs ?? defaultTtlMs;
|
|
50
|
+
const receipt = await artifacts.put(scopeNamespace(scope), bytes, {
|
|
51
|
+
...(ttlMs !== undefined ? { retentionMs: ttlMs } : {}),
|
|
52
|
+
});
|
|
53
|
+
const entry = {
|
|
54
|
+
ref: receipt.ref,
|
|
55
|
+
size: receipt.size,
|
|
56
|
+
createdAt: now(),
|
|
57
|
+
...(ttlMs !== undefined ? { expiresAt: now() + ttlMs } : {}),
|
|
58
|
+
};
|
|
59
|
+
await scoped(scope).set((0, storage_1.artifactRefId)(receipt.ref), entry);
|
|
60
|
+
return receipt.ref;
|
|
61
|
+
},
|
|
62
|
+
async get(scope, ref, getPolicy) {
|
|
63
|
+
const entry = await scoped(scope).get((0, storage_1.artifactRefId)(ref));
|
|
64
|
+
if (!entry) {
|
|
65
|
+
// Not known to this scope — never fall through to the raw backend.
|
|
66
|
+
return { status: 'not-found' };
|
|
67
|
+
}
|
|
68
|
+
if (entry.expiresAt !== undefined && now() > entry.expiresAt) {
|
|
69
|
+
const invalidate = getPolicy?.invalidateOnExpiry ?? defaultInvalidateOnExpiry;
|
|
70
|
+
if (invalidate)
|
|
71
|
+
await this.invalidate(scope, ref);
|
|
72
|
+
return { status: 'not-found' };
|
|
73
|
+
}
|
|
74
|
+
// Digest re-verification + corrupt/not-found taxonomy live in ArtifactStore.
|
|
75
|
+
return artifacts.get(ref);
|
|
76
|
+
},
|
|
77
|
+
async invalidate(scope, ref) {
|
|
78
|
+
await artifacts.delete(ref);
|
|
79
|
+
await scoped(scope).remove((0, storage_1.artifactRefId)(ref));
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IdentityGraph } from '@totemsdk/identity';
|
|
2
|
+
import type { EdgeIdentityPort } from '@totemsdk/edge';
|
|
3
|
+
export interface IdentityPortConfig {
|
|
4
|
+
/**
|
|
5
|
+
* The identity graph this adapter can resolve. Callers holding multiple
|
|
6
|
+
* identities should create one adapter per graph.
|
|
7
|
+
*/
|
|
8
|
+
graph: IdentityGraph;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Wraps an IdentityGraph (from @totemsdk/identity) as an EdgeIdentityPort.
|
|
12
|
+
*
|
|
13
|
+
* resolve: returns the resolved identity when identityId matches graph.document.id,
|
|
14
|
+
* otherwise returns ok:false. For multi-identity setups, compose multiple
|
|
15
|
+
* adapters or use a router above this layer.
|
|
16
|
+
* verify: delegates to verifyIdentityClaim() for SignedIdentityClaim values.
|
|
17
|
+
* Returns ok:false for unrecognised proof shapes.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createIdentityPortAdapter(config: IdentityPortConfig): EdgeIdentityPort;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIdentityPortAdapter = createIdentityPortAdapter;
|
|
4
|
+
const identity_1 = require("@totemsdk/identity");
|
|
5
|
+
/**
|
|
6
|
+
* Wraps an IdentityGraph (from @totemsdk/identity) as an EdgeIdentityPort.
|
|
7
|
+
*
|
|
8
|
+
* resolve: returns the resolved identity when identityId matches graph.document.id,
|
|
9
|
+
* otherwise returns ok:false. For multi-identity setups, compose multiple
|
|
10
|
+
* adapters or use a router above this layer.
|
|
11
|
+
* verify: delegates to verifyIdentityClaim() for SignedIdentityClaim values.
|
|
12
|
+
* Returns ok:false for unrecognised proof shapes.
|
|
13
|
+
*/
|
|
14
|
+
function createIdentityPortAdapter(config) {
|
|
15
|
+
const { graph } = config;
|
|
16
|
+
return {
|
|
17
|
+
async resolve(identityId) {
|
|
18
|
+
try {
|
|
19
|
+
if (graph.document.id !== identityId) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error: `Identity "${identityId}" not found in this adapter's graph`,
|
|
23
|
+
errorCode: 'IDENTITY_NOT_FOUND',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const result = (0, identity_1.resolveIdentityGraph)(graph);
|
|
27
|
+
if (!result.resolved) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
error: result.errors?.join('; ') ?? 'Identity could not be resolved',
|
|
31
|
+
errorCode: 'IDENTITY_UNRESOLVABLE',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, data: { identity: result.resolved } };
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async verify(proof) {
|
|
41
|
+
try {
|
|
42
|
+
const claim = proof;
|
|
43
|
+
if (!claim?.proof?.address) {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
error: 'Proof is not a recognisable SignedIdentityClaim',
|
|
47
|
+
errorCode: 'UNSUPPORTED_PROOF_TYPE',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const result = (0, identity_1.verifyIdentityClaim)(claim);
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
data: { valid: result.valid, address: result.valid ? claim.proof.address : undefined },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { createLiquidityPortAdapter } from './liquidity.js';
|
|
2
|
+
export type { LiquidityPortConfig } from './liquidity.js';
|
|
3
|
+
export { createProofPortAdapter } from './proof.js';
|
|
4
|
+
export type { ProofPortConfig } from './proof.js';
|
|
5
|
+
export { createLookupPortAdapter } from './lookup.js';
|
|
6
|
+
export { createPurchaseLookupAdapter, type PurchaseLookupAdapterConfig } from './purchase-lookup.js';
|
|
7
|
+
export { createPurchaseAuthorityAdapter, type PurchaseAuthorityAdapterConfig } from './purchase-authority.js';
|
|
8
|
+
export { createPurchasePaymentAdapter, type PurchasePaymentAdapterConfig, type PurchasePaymentStore, type PurchasePaymentClaimRecord, } from './purchase-payment.js';
|
|
9
|
+
export { createStreamNegotiationTransport, createPubSubNegotiationTransport, type StreamNegotiationTransportConfig, type PubSubNegotiationTransportConfig, } from './negotiation-transport.js';
|
|
10
|
+
export { createLocationPortAdapter } from './location.js';
|
|
11
|
+
export type { LocationPortConfig } from './location.js';
|
|
12
|
+
export { createPolicyPortAdapter } from './policy.js';
|
|
13
|
+
export { createIdentityPortAdapter } from './identity.js';
|
|
14
|
+
export type { IdentityPortConfig } from './identity.js';
|
|
15
|
+
export { createManifestPortAdapter } from './manifest.js';
|
|
16
|
+
export { createMinimaL1PaymentPort } from './payment-l1.js';
|
|
17
|
+
export type { MinimaL1PaymentPortConfig } from './payment-l1.js';
|
|
18
|
+
export { createOmniaL2PaymentPort } from './payment-l2.js';
|
|
19
|
+
export type { OmniaL2PaymentPortConfig } from './payment-l2.js';
|
|
20
|
+
export { createOmniaHostPort } from './omnia.js';
|
|
21
|
+
export type { OmniaHostPortConfig } from './omnia.js';
|
|
22
|
+
export { createStreamPortAdapter } from './stream.js';
|
|
23
|
+
export { createPubSubPortAdapter } from './pubsub.js';
|
|
24
|
+
export { SQLiteCommerceStore, createSQLiteCommerceStore, type CommerceStore, type SQLiteCommerceStoreConfig, } from './sqlite-commerce-store.js';
|
|
25
|
+
export { createEdgeArtifactCache, type EdgeArtifactCache, type ArtifactCacheRetentionPolicy, } from './artifact-cache.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEdgeArtifactCache = exports.createSQLiteCommerceStore = exports.SQLiteCommerceStore = exports.createPubSubPortAdapter = exports.createStreamPortAdapter = exports.createOmniaHostPort = exports.createOmniaL2PaymentPort = exports.createMinimaL1PaymentPort = exports.createManifestPortAdapter = exports.createIdentityPortAdapter = exports.createPolicyPortAdapter = exports.createLocationPortAdapter = exports.createPubSubNegotiationTransport = exports.createStreamNegotiationTransport = exports.createPurchasePaymentAdapter = exports.createPurchaseAuthorityAdapter = exports.createPurchaseLookupAdapter = exports.createLookupPortAdapter = exports.createProofPortAdapter = exports.createLiquidityPortAdapter = void 0;
|
|
4
|
+
var liquidity_js_1 = require("./liquidity.js");
|
|
5
|
+
Object.defineProperty(exports, "createLiquidityPortAdapter", { enumerable: true, get: function () { return liquidity_js_1.createLiquidityPortAdapter; } });
|
|
6
|
+
var proof_js_1 = require("./proof.js");
|
|
7
|
+
Object.defineProperty(exports, "createProofPortAdapter", { enumerable: true, get: function () { return proof_js_1.createProofPortAdapter; } });
|
|
8
|
+
var lookup_js_1 = require("./lookup.js");
|
|
9
|
+
Object.defineProperty(exports, "createLookupPortAdapter", { enumerable: true, get: function () { return lookup_js_1.createLookupPortAdapter; } });
|
|
10
|
+
var purchase_lookup_js_1 = require("./purchase-lookup.js");
|
|
11
|
+
Object.defineProperty(exports, "createPurchaseLookupAdapter", { enumerable: true, get: function () { return purchase_lookup_js_1.createPurchaseLookupAdapter; } });
|
|
12
|
+
var purchase_authority_js_1 = require("./purchase-authority.js");
|
|
13
|
+
Object.defineProperty(exports, "createPurchaseAuthorityAdapter", { enumerable: true, get: function () { return purchase_authority_js_1.createPurchaseAuthorityAdapter; } });
|
|
14
|
+
var purchase_payment_js_1 = require("./purchase-payment.js");
|
|
15
|
+
Object.defineProperty(exports, "createPurchasePaymentAdapter", { enumerable: true, get: function () { return purchase_payment_js_1.createPurchasePaymentAdapter; } });
|
|
16
|
+
var negotiation_transport_js_1 = require("./negotiation-transport.js");
|
|
17
|
+
Object.defineProperty(exports, "createStreamNegotiationTransport", { enumerable: true, get: function () { return negotiation_transport_js_1.createStreamNegotiationTransport; } });
|
|
18
|
+
Object.defineProperty(exports, "createPubSubNegotiationTransport", { enumerable: true, get: function () { return negotiation_transport_js_1.createPubSubNegotiationTransport; } });
|
|
19
|
+
var location_js_1 = require("./location.js");
|
|
20
|
+
Object.defineProperty(exports, "createLocationPortAdapter", { enumerable: true, get: function () { return location_js_1.createLocationPortAdapter; } });
|
|
21
|
+
var policy_js_1 = require("./policy.js");
|
|
22
|
+
Object.defineProperty(exports, "createPolicyPortAdapter", { enumerable: true, get: function () { return policy_js_1.createPolicyPortAdapter; } });
|
|
23
|
+
var identity_js_1 = require("./identity.js");
|
|
24
|
+
Object.defineProperty(exports, "createIdentityPortAdapter", { enumerable: true, get: function () { return identity_js_1.createIdentityPortAdapter; } });
|
|
25
|
+
var manifest_js_1 = require("./manifest.js");
|
|
26
|
+
Object.defineProperty(exports, "createManifestPortAdapter", { enumerable: true, get: function () { return manifest_js_1.createManifestPortAdapter; } });
|
|
27
|
+
var payment_l1_js_1 = require("./payment-l1.js");
|
|
28
|
+
Object.defineProperty(exports, "createMinimaL1PaymentPort", { enumerable: true, get: function () { return payment_l1_js_1.createMinimaL1PaymentPort; } });
|
|
29
|
+
var payment_l2_js_1 = require("./payment-l2.js");
|
|
30
|
+
Object.defineProperty(exports, "createOmniaL2PaymentPort", { enumerable: true, get: function () { return payment_l2_js_1.createOmniaL2PaymentPort; } });
|
|
31
|
+
var omnia_js_1 = require("./omnia.js");
|
|
32
|
+
Object.defineProperty(exports, "createOmniaHostPort", { enumerable: true, get: function () { return omnia_js_1.createOmniaHostPort; } });
|
|
33
|
+
var stream_js_1 = require("./stream.js");
|
|
34
|
+
Object.defineProperty(exports, "createStreamPortAdapter", { enumerable: true, get: function () { return stream_js_1.createStreamPortAdapter; } });
|
|
35
|
+
var pubsub_js_1 = require("./pubsub.js");
|
|
36
|
+
Object.defineProperty(exports, "createPubSubPortAdapter", { enumerable: true, get: function () { return pubsub_js_1.createPubSubPortAdapter; } });
|
|
37
|
+
var sqlite_commerce_store_js_1 = require("./sqlite-commerce-store.js");
|
|
38
|
+
Object.defineProperty(exports, "SQLiteCommerceStore", { enumerable: true, get: function () { return sqlite_commerce_store_js_1.SQLiteCommerceStore; } });
|
|
39
|
+
Object.defineProperty(exports, "createSQLiteCommerceStore", { enumerable: true, get: function () { return sqlite_commerce_store_js_1.createSQLiteCommerceStore; } });
|
|
40
|
+
var artifact_cache_js_1 = require("./artifact-cache.js");
|
|
41
|
+
Object.defineProperty(exports, "createEdgeArtifactCache", { enumerable: true, get: function () { return artifact_cache_js_1.createEdgeArtifactCache; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChainStateProvider } from '@totemsdk/chain-provider';
|
|
2
|
+
import type { EdgeLiquidityPort } from '@totemsdk/edge';
|
|
3
|
+
export interface LiquidityPortConfig {
|
|
4
|
+
provider: ChainStateProvider;
|
|
5
|
+
/** Token to sum when getBalance is called without an explicit tokenId. Defaults to '0x00' (native Minima). */
|
|
6
|
+
defaultTokenId?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a ChainStateProvider (chain-provider, minima-rpc, lookup-client) as
|
|
10
|
+
* an EdgeLiquidityPort.
|
|
11
|
+
*
|
|
12
|
+
* getBalance sums sendable coins for the given address and tokenId.
|
|
13
|
+
* getUtxos returns all coins as raw UTXOs (typed as unknown[] per the port contract).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createLiquidityPortAdapter(config: LiquidityPortConfig): EdgeLiquidityPort;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLiquidityPortAdapter = createLiquidityPortAdapter;
|
|
4
|
+
const _SCALE = 100000000n;
|
|
5
|
+
function _toScaled(s) {
|
|
6
|
+
const [i, f = ''] = s.split('.');
|
|
7
|
+
return BigInt(i || '0') * _SCALE + BigInt(f.padEnd(8, '0').slice(0, 8));
|
|
8
|
+
}
|
|
9
|
+
function _fromScaled(n) {
|
|
10
|
+
if (n === 0n)
|
|
11
|
+
return '0';
|
|
12
|
+
const frac = (n % _SCALE).toString().padStart(8, '0').replace(/0+$/, '');
|
|
13
|
+
return frac ? `${n / _SCALE}.${frac}` : `${n / _SCALE}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a ChainStateProvider (chain-provider, minima-rpc, lookup-client) as
|
|
17
|
+
* an EdgeLiquidityPort.
|
|
18
|
+
*
|
|
19
|
+
* getBalance sums sendable coins for the given address and tokenId.
|
|
20
|
+
* getUtxos returns all coins as raw UTXOs (typed as unknown[] per the port contract).
|
|
21
|
+
*/
|
|
22
|
+
function createLiquidityPortAdapter(config) {
|
|
23
|
+
const { provider, defaultTokenId = '0x00' } = config;
|
|
24
|
+
return {
|
|
25
|
+
async getBalance(address) {
|
|
26
|
+
try {
|
|
27
|
+
const coins = await provider.getCoins({ address, tokenId: defaultTokenId, sendable: true });
|
|
28
|
+
const balance = _fromScaled(coins.reduce((sum, c) => sum + _toScaled(c.amount), 0n));
|
|
29
|
+
return { ok: true, data: { balance, tokenId: defaultTokenId } };
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async getUtxos(address) {
|
|
36
|
+
try {
|
|
37
|
+
const coins = await provider.getCoins({ address });
|
|
38
|
+
return { ok: true, data: { utxos: coins } };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { EdgeLocationPort } from '@totemsdk/edge';
|
|
2
|
+
export interface LocationPortConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Default issuer stamped onto created location proofs. When unset, the
|
|
5
|
+
* claim's subjectId is used.
|
|
6
|
+
*/
|
|
7
|
+
issuer?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 32-byte WOTS seed. Required for signing; without it only unsigned
|
|
10
|
+
* location proofs are returned, which MUST NOT be presented as completed
|
|
11
|
+
* proofs.
|
|
12
|
+
*/
|
|
13
|
+
seed?: Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* TreeKey index for direct signing (used when no leaseProvider is given).
|
|
16
|
+
* Ignored when leaseProvider is set.
|
|
17
|
+
*/
|
|
18
|
+
keyIndex?: number;
|
|
19
|
+
/**
|
|
20
|
+
* WOTS lease provider for coordinated key-index reservation.
|
|
21
|
+
* When set, keyIndex is ignored and the index is reserved via the provider.
|
|
22
|
+
*/
|
|
23
|
+
leaseProvider?: {
|
|
24
|
+
reserveKeyUse(params: {
|
|
25
|
+
treeId: string;
|
|
26
|
+
ttlMs?: number;
|
|
27
|
+
payloadHash?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
reservationId: string;
|
|
30
|
+
indices: {
|
|
31
|
+
addressIndex: number;
|
|
32
|
+
l1: number;
|
|
33
|
+
l2: number;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
36
|
+
commitKeyUse(reservationId: string, txId: string): Promise<void>;
|
|
37
|
+
burnReservation(reservationId: string, reason: string): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
leaseTreeId?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Wraps @totemsdk/location-proof as an EdgeLocationPort.
|
|
43
|
+
*
|
|
44
|
+
* createClaim/createTrail build content-derived Totem-location claims/trails.
|
|
45
|
+
* createProof returns a SignedProof when config.seed is set; otherwise it
|
|
46
|
+
* returns an UnsignedProof that MUST NOT be presented as a completed proof.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createLocationPortAdapter(config?: LocationPortConfig): EdgeLocationPort;
|