@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,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* EdgeStreamPort adapter — wraps @totemsdk/stream-transport's IStreamTransport
|
|
4
|
+
* as a first-class EdgeStreamPort for EdgeRuntimePorts.stream.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createStreamPortAdapter = createStreamPortAdapter;
|
|
8
|
+
function createStreamPortAdapter(transport) {
|
|
9
|
+
return {
|
|
10
|
+
async send(data) {
|
|
11
|
+
await transport.send(data);
|
|
12
|
+
},
|
|
13
|
+
onData(handler) {
|
|
14
|
+
return transport.onData(handler);
|
|
15
|
+
},
|
|
16
|
+
onClose(handler) {
|
|
17
|
+
return transport.onClose(handler);
|
|
18
|
+
},
|
|
19
|
+
onError(handler) {
|
|
20
|
+
return transport.onError(handler);
|
|
21
|
+
},
|
|
22
|
+
close() {
|
|
23
|
+
void transport.close();
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/identity.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createIdentityPortAdapter = createIdentityPortAdapter;
|
|
4
|
-
const identity_1 = require("@totemsdk/identity");
|
|
1
|
+
import { resolveIdentityGraph, verifyIdentityClaim } from '@totemsdk/identity';
|
|
5
2
|
/**
|
|
6
3
|
* Wraps an IdentityGraph (from @totemsdk/identity) as an EdgeIdentityPort.
|
|
7
4
|
*
|
|
@@ -11,7 +8,7 @@ const identity_1 = require("@totemsdk/identity");
|
|
|
11
8
|
* verify: delegates to verifyIdentityClaim() for SignedIdentityClaim values.
|
|
12
9
|
* Returns ok:false for unrecognised proof shapes.
|
|
13
10
|
*/
|
|
14
|
-
function createIdentityPortAdapter(config) {
|
|
11
|
+
export function createIdentityPortAdapter(config) {
|
|
15
12
|
const { graph } = config;
|
|
16
13
|
return {
|
|
17
14
|
async resolve(identityId) {
|
|
@@ -23,7 +20,7 @@ function createIdentityPortAdapter(config) {
|
|
|
23
20
|
errorCode: 'IDENTITY_NOT_FOUND',
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
|
-
const result =
|
|
23
|
+
const result = resolveIdentityGraph(graph);
|
|
27
24
|
if (!result.resolved) {
|
|
28
25
|
return {
|
|
29
26
|
ok: false,
|
|
@@ -47,7 +44,7 @@ function createIdentityPortAdapter(config) {
|
|
|
47
44
|
errorCode: 'UNSUPPORTED_PROOF_TYPE',
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
|
-
const result =
|
|
47
|
+
const result = verifyIdentityClaim(claim);
|
|
51
48
|
return {
|
|
52
49
|
ok: true,
|
|
53
50
|
data: { valid: result.valid, address: result.valid ? claim.proof.address : undefined },
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export type { LiquidityPortConfig } from './liquidity.js';
|
|
|
3
3
|
export { createProofPortAdapter } from './proof.js';
|
|
4
4
|
export type { ProofPortConfig } from './proof.js';
|
|
5
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';
|
|
6
10
|
export { createLocationPortAdapter } from './location.js';
|
|
7
11
|
export type { LocationPortConfig } from './location.js';
|
|
8
12
|
export { createPolicyPortAdapter } from './policy.js';
|
|
@@ -17,3 +21,5 @@ export { createOmniaHostPort } from './omnia.js';
|
|
|
17
21
|
export type { OmniaHostPortConfig } from './omnia.js';
|
|
18
22
|
export { createStreamPortAdapter } from './stream.js';
|
|
19
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';
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "createMinimaL1PaymentPort", { enumerable: true, get: function () { return payment_l1_js_1.createMinimaL1PaymentPort; } });
|
|
20
|
-
var payment_l2_js_1 = require("./payment-l2.js");
|
|
21
|
-
Object.defineProperty(exports, "createOmniaL2PaymentPort", { enumerable: true, get: function () { return payment_l2_js_1.createOmniaL2PaymentPort; } });
|
|
22
|
-
var omnia_js_1 = require("./omnia.js");
|
|
23
|
-
Object.defineProperty(exports, "createOmniaHostPort", { enumerable: true, get: function () { return omnia_js_1.createOmniaHostPort; } });
|
|
24
|
-
var stream_js_1 = require("./stream.js");
|
|
25
|
-
Object.defineProperty(exports, "createStreamPortAdapter", { enumerable: true, get: function () { return stream_js_1.createStreamPortAdapter; } });
|
|
26
|
-
var pubsub_js_1 = require("./pubsub.js");
|
|
27
|
-
Object.defineProperty(exports, "createPubSubPortAdapter", { enumerable: true, get: function () { return pubsub_js_1.createPubSubPortAdapter; } });
|
|
1
|
+
export { createLiquidityPortAdapter } from './liquidity.js';
|
|
2
|
+
export { createProofPortAdapter } from './proof.js';
|
|
3
|
+
export { createLookupPortAdapter } from './lookup.js';
|
|
4
|
+
export { createPurchaseLookupAdapter } from './purchase-lookup.js';
|
|
5
|
+
export { createPurchaseAuthorityAdapter } from './purchase-authority.js';
|
|
6
|
+
export { createPurchasePaymentAdapter, } from './purchase-payment.js';
|
|
7
|
+
export { createStreamNegotiationTransport, createPubSubNegotiationTransport, } from './negotiation-transport.js';
|
|
8
|
+
export { createLocationPortAdapter } from './location.js';
|
|
9
|
+
export { createPolicyPortAdapter } from './policy.js';
|
|
10
|
+
export { createIdentityPortAdapter } from './identity.js';
|
|
11
|
+
export { createManifestPortAdapter } from './manifest.js';
|
|
12
|
+
export { createMinimaL1PaymentPort } from './payment-l1.js';
|
|
13
|
+
export { createOmniaL2PaymentPort } from './payment-l2.js';
|
|
14
|
+
export { createOmniaHostPort } from './omnia.js';
|
|
15
|
+
export { createStreamPortAdapter } from './stream.js';
|
|
16
|
+
export { createPubSubPortAdapter } from './pubsub.js';
|
|
17
|
+
export { SQLiteCommerceStore, createSQLiteCommerceStore, } from './sqlite-commerce-store.js';
|
|
18
|
+
export { createEdgeArtifactCache, } from './artifact-cache.js';
|
package/dist/liquidity.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLiquidityPortAdapter = createLiquidityPortAdapter;
|
|
4
1
|
const _SCALE = 100000000n;
|
|
5
2
|
function _toScaled(s) {
|
|
6
3
|
const [i, f = ''] = s.split('.');
|
|
@@ -19,7 +16,7 @@ function _fromScaled(n) {
|
|
|
19
16
|
* getBalance sums sendable coins for the given address and tokenId.
|
|
20
17
|
* getUtxos returns all coins as raw UTXOs (typed as unknown[] per the port contract).
|
|
21
18
|
*/
|
|
22
|
-
function createLiquidityPortAdapter(config) {
|
|
19
|
+
export function createLiquidityPortAdapter(config) {
|
|
23
20
|
const { provider, defaultTokenId = '0x00' } = config;
|
|
24
21
|
return {
|
|
25
22
|
async getBalance(address) {
|
package/dist/location.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLocationPortAdapter = createLocationPortAdapter;
|
|
4
|
-
const location_proof_1 = require("@totemsdk/location-proof");
|
|
1
|
+
import { createLocationClaim, createMovementTrail, createUnsignedLocationProof, scoreLocationClaim, signLocationProof, signLocationProofWithLease, validateLocationClaim, verifyLocationProof, } from '@totemsdk/location-proof';
|
|
5
2
|
const DEVICE_CLASSES = [
|
|
6
3
|
'drone',
|
|
7
4
|
'vehicle',
|
|
@@ -52,7 +49,7 @@ function toSourceType(type) {
|
|
|
52
49
|
* createProof returns a SignedProof when config.seed is set; otherwise it
|
|
53
50
|
* returns an UnsignedProof that MUST NOT be presented as a completed proof.
|
|
54
51
|
*/
|
|
55
|
-
function createLocationPortAdapter(config = {}) {
|
|
52
|
+
export function createLocationPortAdapter(config = {}) {
|
|
56
53
|
return {
|
|
57
54
|
async createClaim(params) {
|
|
58
55
|
try {
|
|
@@ -60,7 +57,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
60
57
|
? params.deviceClass
|
|
61
58
|
: undefined;
|
|
62
59
|
const sourceType = toSourceType(params.source.type);
|
|
63
|
-
const claim =
|
|
60
|
+
const claim = createLocationClaim({
|
|
64
61
|
subjectId: params.subjectId,
|
|
65
62
|
deviceId: params.deviceId,
|
|
66
63
|
...(deviceClass !== undefined ? { deviceClass } : {}),
|
|
@@ -89,7 +86,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
89
86
|
...(params.corroboration !== undefined ? { corroboration: params.corroboration } : {}),
|
|
90
87
|
...(params.metadata !== undefined ? { metadata: params.metadata } : {}),
|
|
91
88
|
});
|
|
92
|
-
const validation =
|
|
89
|
+
const validation = validateLocationClaim(claim);
|
|
93
90
|
if (!validation.valid) {
|
|
94
91
|
return {
|
|
95
92
|
ok: false,
|
|
@@ -105,7 +102,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
105
102
|
async scoreClaim(params) {
|
|
106
103
|
try {
|
|
107
104
|
assertLocationClaim(params.claim);
|
|
108
|
-
const result =
|
|
105
|
+
const result = scoreLocationClaim(params.claim, params.options);
|
|
109
106
|
return {
|
|
110
107
|
ok: true,
|
|
111
108
|
data: {
|
|
@@ -122,7 +119,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
122
119
|
},
|
|
123
120
|
async createTrail(params) {
|
|
124
121
|
try {
|
|
125
|
-
const trail =
|
|
122
|
+
const trail = createMovementTrail({
|
|
126
123
|
subjectId: params.subjectId,
|
|
127
124
|
deviceId: params.deviceId,
|
|
128
125
|
samples: params.samples.map((sample) => ({
|
|
@@ -159,7 +156,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
159
156
|
assertLocationClaim(params.claim);
|
|
160
157
|
const claim = params.claim;
|
|
161
158
|
const issuer = params.context?.['issuer'] ?? config.issuer;
|
|
162
|
-
const unsigned =
|
|
159
|
+
const unsigned = createUnsignedLocationProof({
|
|
163
160
|
claim,
|
|
164
161
|
...(issuer !== undefined ? { issuer } : {}),
|
|
165
162
|
});
|
|
@@ -167,12 +164,12 @@ function createLocationPortAdapter(config = {}) {
|
|
|
167
164
|
let proofId;
|
|
168
165
|
if (config.seed) {
|
|
169
166
|
if (config.leaseProvider) {
|
|
170
|
-
proof = await
|
|
167
|
+
proof = await signLocationProofWithLease(unsigned, config.seed, config.leaseProvider, {
|
|
171
168
|
treeId: config.leaseTreeId,
|
|
172
169
|
});
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
175
|
-
proof =
|
|
172
|
+
proof = signLocationProof(unsigned, config.seed, config.keyIndex ?? 0);
|
|
176
173
|
}
|
|
177
174
|
proofId = proof.proofId;
|
|
178
175
|
}
|
|
@@ -188,7 +185,7 @@ function createLocationPortAdapter(config = {}) {
|
|
|
188
185
|
},
|
|
189
186
|
async verifyProof(params) {
|
|
190
187
|
try {
|
|
191
|
-
const result =
|
|
188
|
+
const result = verifyLocationProof(params.proof, { now: params.now });
|
|
192
189
|
return {
|
|
193
190
|
ok: true,
|
|
194
191
|
data: {
|
package/dist/lookup.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLookupPortAdapter = createLookupPortAdapter;
|
|
4
|
-
const manifest_1 = require("@totemsdk/manifest");
|
|
1
|
+
import { encodeManifest } from '@totemsdk/manifest';
|
|
5
2
|
/**
|
|
6
3
|
* Wraps a LookupClient as an EdgeLookupPort.
|
|
7
4
|
*
|
|
@@ -12,7 +9,7 @@ const manifest_1 = require("@totemsdk/manifest");
|
|
|
12
9
|
* those bytes with its session Ed25519 keypair — no WOTS key index is
|
|
13
10
|
* consumed. Fire-and-forget: the lookup node sends no ACK.
|
|
14
11
|
*/
|
|
15
|
-
function createLookupPortAdapter(client) {
|
|
12
|
+
export function createLookupPortAdapter(client) {
|
|
16
13
|
return {
|
|
17
14
|
async lookup(params) {
|
|
18
15
|
try {
|
|
@@ -39,7 +36,7 @@ function createLookupPortAdapter(client) {
|
|
|
39
36
|
},
|
|
40
37
|
async announce(params) {
|
|
41
38
|
try {
|
|
42
|
-
const manifestBytes =
|
|
39
|
+
const manifestBytes = encodeManifest(params.signed);
|
|
43
40
|
if (params.kind === 'app') {
|
|
44
41
|
await client.announceApp({
|
|
45
42
|
manifest: manifestBytes,
|
package/dist/manifest.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createManifestPortAdapter = createManifestPortAdapter;
|
|
4
|
-
const manifest_1 = require("@totemsdk/manifest");
|
|
1
|
+
import { signManifest, verifyManifest } from '@totemsdk/manifest';
|
|
2
|
+
import { createUnifiedChildTreeKey } from '@totemsdk/core';
|
|
5
3
|
/**
|
|
6
4
|
* Wraps @totemsdk/manifest's signManifest / verifyManifest as an EdgeManifestPort.
|
|
7
5
|
*
|
|
@@ -11,11 +9,11 @@ const manifest_1 = require("@totemsdk/manifest");
|
|
|
11
9
|
* Callers are responsible for key-lease reservation before calling sign().
|
|
12
10
|
* This adapter does not interact with @totemsdk/wots-lease.
|
|
13
11
|
*/
|
|
14
|
-
function createManifestPortAdapter() {
|
|
12
|
+
export function createManifestPortAdapter() {
|
|
15
13
|
return {
|
|
16
14
|
async sign(manifest, seed, keyIndex) {
|
|
17
15
|
try {
|
|
18
|
-
const signed = await
|
|
16
|
+
const signed = await signManifest(manifest, createUnifiedChildTreeKey(seed, 0), keyIndex);
|
|
19
17
|
return { ok: true, data: { signed } };
|
|
20
18
|
}
|
|
21
19
|
catch (err) {
|
|
@@ -24,7 +22,7 @@ function createManifestPortAdapter() {
|
|
|
24
22
|
},
|
|
25
23
|
async verify(signed) {
|
|
26
24
|
try {
|
|
27
|
-
const result =
|
|
25
|
+
const result = verifyManifest(signed);
|
|
28
26
|
return { ok: true, data: { valid: result.valid, reason: result.reason } };
|
|
29
27
|
}
|
|
30
28
|
catch (err) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* negotiation-transport.ts — NegotiationTransport adapters over Edge ports.
|
|
3
|
+
*
|
|
4
|
+
* Two adapters:
|
|
5
|
+
* - createStreamNegotiationTransport: raw byte stream (EdgeStreamPort).
|
|
6
|
+
* Messages are framed as length-prefixed JSON. The sender address is
|
|
7
|
+
* resolved by the caller (the stream is a single authenticated peer).
|
|
8
|
+
* - createPubSubNegotiationTransport: topic-based (EdgePubSubPort).
|
|
9
|
+
* Each negotiation uses a topic derived from the negotiationId; the
|
|
10
|
+
* sender address is carried in the envelope.
|
|
11
|
+
*
|
|
12
|
+
* Transport metadata stays separate from economic protocol objects. The
|
|
13
|
+
* NegotiationEngine never sees sockets/topics/connection IDs.
|
|
14
|
+
*/
|
|
15
|
+
import type { NegotiationTransport } from '@totemsdk/edge';
|
|
16
|
+
import type { EdgePubSubPort, EdgeStreamPort } from '@totemsdk/edge';
|
|
17
|
+
export interface StreamNegotiationTransportConfig {
|
|
18
|
+
stream: EdgeStreamPort;
|
|
19
|
+
/** The authenticated sender address for this stream (resolved by caller). */
|
|
20
|
+
sender: string;
|
|
21
|
+
/** The local recipient address. */
|
|
22
|
+
recipient: string;
|
|
23
|
+
/** Max message size in bytes (default 64 KiB). */
|
|
24
|
+
maxBytes?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a NegotiationTransport over a raw byte stream.
|
|
28
|
+
*
|
|
29
|
+
* Messages are framed as `[4-byte BE length][JSON bytes]`. The stream is
|
|
30
|
+
* assumed to be a single authenticated peer connection, so the sender address
|
|
31
|
+
* is fixed by the caller.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createStreamNegotiationTransport(config: StreamNegotiationTransportConfig): NegotiationTransport;
|
|
34
|
+
export interface PubSubNegotiationTransportConfig {
|
|
35
|
+
pubsub: EdgePubSubPort;
|
|
36
|
+
/** The local recipient address. */
|
|
37
|
+
recipient: string;
|
|
38
|
+
/** Topic prefix (default 'totem.negotiation'). */
|
|
39
|
+
topicPrefix?: string;
|
|
40
|
+
/** Max message size in bytes (default 64 KiB). */
|
|
41
|
+
maxBytes?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a NegotiationTransport over a pub/sub transport.
|
|
45
|
+
*
|
|
46
|
+
* Each negotiation uses a topic derived from its negotiationId. The sender
|
|
47
|
+
* address is carried in the envelope (a `sender` field on the message), so
|
|
48
|
+
* the ingress pipeline can authenticate it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createPubSubNegotiationTransport(config: PubSubNegotiationTransportConfig): NegotiationTransport;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* negotiation-transport.ts — NegotiationTransport adapters over Edge ports.
|
|
3
|
+
*
|
|
4
|
+
* Two adapters:
|
|
5
|
+
* - createStreamNegotiationTransport: raw byte stream (EdgeStreamPort).
|
|
6
|
+
* Messages are framed as length-prefixed JSON. The sender address is
|
|
7
|
+
* resolved by the caller (the stream is a single authenticated peer).
|
|
8
|
+
* - createPubSubNegotiationTransport: topic-based (EdgePubSubPort).
|
|
9
|
+
* Each negotiation uses a topic derived from the negotiationId; the
|
|
10
|
+
* sender address is carried in the envelope.
|
|
11
|
+
*
|
|
12
|
+
* Transport metadata stays separate from economic protocol objects. The
|
|
13
|
+
* NegotiationEngine never sees sockets/topics/connection IDs.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Create a NegotiationTransport over a raw byte stream.
|
|
17
|
+
*
|
|
18
|
+
* Messages are framed as `[4-byte BE length][JSON bytes]`. The stream is
|
|
19
|
+
* assumed to be a single authenticated peer connection, so the sender address
|
|
20
|
+
* is fixed by the caller.
|
|
21
|
+
*/
|
|
22
|
+
export function createStreamNegotiationTransport(config) {
|
|
23
|
+
const { stream, sender, recipient } = config;
|
|
24
|
+
const maxBytes = config.maxBytes ?? 64 * 1024;
|
|
25
|
+
return {
|
|
26
|
+
async send(_recipient, message) {
|
|
27
|
+
const bytes = new TextEncoder().encode(JSON.stringify(message));
|
|
28
|
+
if (bytes.length > maxBytes) {
|
|
29
|
+
throw new Error(`negotiation message exceeds ${maxBytes} bytes`);
|
|
30
|
+
}
|
|
31
|
+
const frame = new Uint8Array(4 + bytes.length);
|
|
32
|
+
new DataView(frame.buffer).setUint32(0, bytes.length);
|
|
33
|
+
frame.set(bytes, 4);
|
|
34
|
+
// Raw byte-stream send does NOT prove durable remote processing —
|
|
35
|
+
// return no receipt so the outbox drainer does not mark delivered.
|
|
36
|
+
stream.send(frame);
|
|
37
|
+
return undefined;
|
|
38
|
+
},
|
|
39
|
+
subscribe(handler) {
|
|
40
|
+
let buffer = new Uint8Array(0);
|
|
41
|
+
const off = stream.onData((chunk) => {
|
|
42
|
+
buffer = concatBytes(buffer, chunk);
|
|
43
|
+
while (buffer.length >= 4) {
|
|
44
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, 4);
|
|
45
|
+
const len = view.getUint32(0);
|
|
46
|
+
if (buffer.length < 4 + len)
|
|
47
|
+
break;
|
|
48
|
+
const payload = buffer.slice(4, 4 + len);
|
|
49
|
+
buffer = buffer.slice(4 + len);
|
|
50
|
+
try {
|
|
51
|
+
const message = JSON.parse(new TextDecoder().decode(payload));
|
|
52
|
+
void handler(message, { sender, recipient });
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Malformed frame — drop.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return off;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function topicFor(topicPrefix, negotiationId) {
|
|
64
|
+
return `${topicPrefix}.${negotiationId}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a NegotiationTransport over a pub/sub transport.
|
|
68
|
+
*
|
|
69
|
+
* Each negotiation uses a topic derived from its negotiationId. The sender
|
|
70
|
+
* address is carried in the envelope (a `sender` field on the message), so
|
|
71
|
+
* the ingress pipeline can authenticate it.
|
|
72
|
+
*/
|
|
73
|
+
export function createPubSubNegotiationTransport(config) {
|
|
74
|
+
const { pubsub, recipient } = config;
|
|
75
|
+
const topicPrefix = config.topicPrefix ?? 'totem.negotiation';
|
|
76
|
+
const maxBytes = config.maxBytes ?? 64 * 1024;
|
|
77
|
+
return {
|
|
78
|
+
async send(recipientAddress, message) {
|
|
79
|
+
const negotiationId = message.negotiationId;
|
|
80
|
+
if (!negotiationId)
|
|
81
|
+
throw new Error('negotiation message missing negotiationId');
|
|
82
|
+
const topic = topicFor(topicPrefix, negotiationId);
|
|
83
|
+
const envelope = { ...message, sender: recipientAddress, recipient };
|
|
84
|
+
const bytes = new TextEncoder().encode(JSON.stringify(envelope));
|
|
85
|
+
if (bytes.length > maxBytes) {
|
|
86
|
+
throw new Error(`negotiation message exceeds ${maxBytes} bytes`);
|
|
87
|
+
}
|
|
88
|
+
// Pub/sub publish() proves local broker transmission, not durable remote
|
|
89
|
+
// processing — return no receipt so the outbox drainer does not mark
|
|
90
|
+
// delivered on local send alone.
|
|
91
|
+
await pubsub.publish(topic, bytes);
|
|
92
|
+
return undefined;
|
|
93
|
+
},
|
|
94
|
+
subscribe(handler) {
|
|
95
|
+
return pubsub.onMessage(({ topic, payload }) => {
|
|
96
|
+
if (!topic.startsWith(topicPrefix))
|
|
97
|
+
return;
|
|
98
|
+
try {
|
|
99
|
+
const envelope = JSON.parse(new TextDecoder().decode(payload));
|
|
100
|
+
const sender = envelope.sender ?? 'unknown';
|
|
101
|
+
void handler(envelope, { sender, recipient });
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Malformed message — drop.
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
111
|
+
// Helpers
|
|
112
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
113
|
+
function concatBytes(a, b) {
|
|
114
|
+
const out = new Uint8Array(a.length + b.length);
|
|
115
|
+
out.set(a, 0);
|
|
116
|
+
out.set(b, a.length);
|
|
117
|
+
return out;
|
|
118
|
+
}
|
package/dist/omnia.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOmniaHostPort = createOmniaHostPort;
|
|
4
1
|
function methodName(operation) {
|
|
5
2
|
return `totem_omnia${operation[0].toUpperCase()}${operation.slice(1)}`;
|
|
6
3
|
}
|
|
7
|
-
function createOmniaHostPort(config) {
|
|
4
|
+
export function createOmniaHostPort(config) {
|
|
8
5
|
const request = config.fetch ?? globalThis.fetch;
|
|
9
6
|
const endpoint = config.endpoint.replace(/\/$/, '');
|
|
10
7
|
async function call(operation, params = {}) {
|
package/dist/payment-l1.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMinimaL1PaymentPort = createMinimaL1PaymentPort;
|
|
4
1
|
/**
|
|
5
2
|
* Minima L1 payment adapter.
|
|
6
3
|
*
|
|
@@ -18,7 +15,7 @@ exports.createMinimaL1PaymentPort = createMinimaL1PaymentPort;
|
|
|
18
15
|
* .then(r => r.minedHex),
|
|
19
16
|
* })
|
|
20
17
|
*/
|
|
21
|
-
function createMinimaL1PaymentPort(config) {
|
|
18
|
+
export function createMinimaL1PaymentPort(config) {
|
|
22
19
|
return {
|
|
23
20
|
async pay(params) {
|
|
24
21
|
try {
|
package/dist/payment-l2.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOmniaL2PaymentPort = createOmniaL2PaymentPort;
|
|
4
|
-
const omnia_router_1 = require("@totemsdk/omnia-router");
|
|
1
|
+
import { findRoute, buildPaymentRequest, executeMultiHopPayment, } from '@totemsdk/omnia-router';
|
|
5
2
|
const _SCALE = 100000000n;
|
|
6
3
|
function _toScaled(s) {
|
|
7
4
|
const [i, f = ''] = s.split('.');
|
|
@@ -18,14 +15,14 @@ function _toScaled(s) {
|
|
|
18
15
|
* 2. Reveal phase — reveals the preimage in reverse to settle all hops.
|
|
19
16
|
* Rollback (best-effort timeoutHTLC) fires on any failure.
|
|
20
17
|
*/
|
|
21
|
-
function createOmniaL2PaymentPort(config) {
|
|
18
|
+
export function createOmniaL2PaymentPort(config) {
|
|
22
19
|
const htlcTimeoutBlocks = config.htlcTimeoutBlocks ?? 144n;
|
|
23
20
|
return {
|
|
24
21
|
async pay(params) {
|
|
25
22
|
try {
|
|
26
23
|
const tokenId = params.tokenId ?? '0x00';
|
|
27
24
|
const amount = _toScaled(params.amount);
|
|
28
|
-
const route =
|
|
25
|
+
const route = findRoute(config.graph, config.localPublicKeyDigest, params.recipient, amount, tokenId, config.routeOptions);
|
|
29
26
|
if (!route) {
|
|
30
27
|
return {
|
|
31
28
|
ok: false,
|
|
@@ -35,8 +32,8 @@ function createOmniaL2PaymentPort(config) {
|
|
|
35
32
|
}
|
|
36
33
|
const currentBlock = await config.getCurrentBlock();
|
|
37
34
|
const expiryBlock = currentBlock + htlcTimeoutBlocks;
|
|
38
|
-
const request =
|
|
39
|
-
const result = await
|
|
35
|
+
const request = buildPaymentRequest(amount, tokenId, expiryBlock);
|
|
36
|
+
const result = await executeMultiHopPayment(config.ops, config.channels, route, request, config.leaseProviders);
|
|
40
37
|
if (!result.success) {
|
|
41
38
|
return {
|
|
42
39
|
ok: false,
|
package/dist/policy.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPolicyPortAdapter = createPolicyPortAdapter;
|
|
4
1
|
function isMiddleware(p) {
|
|
5
2
|
return 'evaluate' in p && typeof p.evaluate === 'function';
|
|
6
3
|
}
|
|
@@ -12,7 +9,7 @@ function isMiddleware(p) {
|
|
|
12
9
|
* `action`/`subject` params are provided, it builds a minimal AgentProposal
|
|
13
10
|
* (legacy path).
|
|
14
11
|
*/
|
|
15
|
-
function createPolicyPortAdapter(policy) {
|
|
12
|
+
export function createPolicyPortAdapter(policy) {
|
|
16
13
|
return {
|
|
17
14
|
async check(params) {
|
|
18
15
|
try {
|
package/dist/proof.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createProofPortAdapter = createProofPortAdapter;
|
|
4
|
-
const proof_1 = require("@totemsdk/proof");
|
|
1
|
+
import { createProof, signProof, signWithLease, toHex, sha3_256 } from '@totemsdk/proof';
|
|
5
2
|
function rawPayloadEvidence(rawPayload) {
|
|
6
3
|
if (!rawPayload || rawPayload.length === 0)
|
|
7
4
|
return undefined;
|
|
8
|
-
const hash =
|
|
5
|
+
const hash = toHex(sha3_256(rawPayload));
|
|
9
6
|
return { id: 'payload:' + hash, kind: 'raw-payload', hash };
|
|
10
7
|
}
|
|
11
8
|
/**
|
|
@@ -15,7 +12,7 @@ function rawPayloadEvidence(rawPayload) {
|
|
|
15
12
|
* without seed only an UnsignedProof is returned and MUST NOT be
|
|
16
13
|
* presented as a completed proof.
|
|
17
14
|
*/
|
|
18
|
-
function createProofPortAdapter(config) {
|
|
15
|
+
export function createProofPortAdapter(config) {
|
|
19
16
|
const { provider, issuer, defaultKind = 'attestation' } = config;
|
|
20
17
|
return {
|
|
21
18
|
async createProof(params) {
|
|
@@ -23,13 +20,13 @@ function createProofPortAdapter(config) {
|
|
|
23
20
|
const kind = params.context?.['kind'] ?? defaultKind;
|
|
24
21
|
const rawPayload = params.context?.['rawPayload'];
|
|
25
22
|
const evidence = rawPayloadEvidence(rawPayload);
|
|
26
|
-
const unsigned =
|
|
23
|
+
const unsigned = createProof({
|
|
27
24
|
kind,
|
|
28
25
|
subject: { id: params.subject, kind: 'edge-subject' },
|
|
29
26
|
issuer,
|
|
30
27
|
payload: {
|
|
31
28
|
claims: params.claims,
|
|
32
|
-
...(rawPayload !== undefined ? { rawPayloadHash:
|
|
29
|
+
...(rawPayload !== undefined ? { rawPayloadHash: toHex(sha3_256(rawPayload)) } : {}),
|
|
33
30
|
...(params.context ?? {}),
|
|
34
31
|
},
|
|
35
32
|
...(evidence !== undefined ? { evidence: [evidence] } : {}),
|
|
@@ -39,12 +36,12 @@ function createProofPortAdapter(config) {
|
|
|
39
36
|
let proofId;
|
|
40
37
|
if (config.seed) {
|
|
41
38
|
if (config.leaseProvider) {
|
|
42
|
-
proof = await
|
|
39
|
+
proof = await signWithLease(unsigned, config.seed, config.leaseProvider, {
|
|
43
40
|
treeId: config.leaseTreeId,
|
|
44
41
|
});
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
proof =
|
|
44
|
+
proof = signProof(unsigned, config.seed, config.keyIndex ?? 0);
|
|
48
45
|
}
|
|
49
46
|
proofId = proof.proofId;
|
|
50
47
|
}
|
package/dist/pubsub.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* EdgePubSubPort adapter — wraps @totemsdk/pubsub-transport's IPubSubTransport
|
|
4
3
|
* as a first-class EdgePubSubPort for EdgeRuntimePorts.pubsub.
|
|
@@ -7,9 +6,7 @@
|
|
|
7
6
|
* the raw pub/sub port without the rule engine, sensor bridge, proof
|
|
8
7
|
* publisher, command handler, or MachinePay credit enforcement.
|
|
9
8
|
*/
|
|
10
|
-
|
|
11
|
-
exports.createPubSubPortAdapter = createPubSubPortAdapter;
|
|
12
|
-
function createPubSubPortAdapter(transport) {
|
|
9
|
+
export function createPubSubPortAdapter(transport) {
|
|
13
10
|
return {
|
|
14
11
|
async connect() {
|
|
15
12
|
await transport.connect();
|