@totemsdk/edge-adapters 0.2.1 → 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.js +9 -12
- 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.js +18 -41
- 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.js +2 -6
- 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.js +1 -4
- package/dist/purchase-lookup.js +1 -4
- package/dist/purchase-payment.js +4 -7
- package/dist/sqlite-commerce-store.js +4 -9
- package/dist/stream.js +1 -4
- package/package.json +28 -22
package/dist/index.js
CHANGED
|
@@ -1,41 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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; } });
|
|
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) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* negotiation-transport.ts — NegotiationTransport adapters over Edge ports.
|
|
4
3
|
*
|
|
@@ -13,9 +12,6 @@
|
|
|
13
12
|
* Transport metadata stays separate from economic protocol objects. The
|
|
14
13
|
* NegotiationEngine never sees sockets/topics/connection IDs.
|
|
15
14
|
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createStreamNegotiationTransport = createStreamNegotiationTransport;
|
|
18
|
-
exports.createPubSubNegotiationTransport = createPubSubNegotiationTransport;
|
|
19
15
|
/**
|
|
20
16
|
* Create a NegotiationTransport over a raw byte stream.
|
|
21
17
|
*
|
|
@@ -23,7 +19,7 @@ exports.createPubSubNegotiationTransport = createPubSubNegotiationTransport;
|
|
|
23
19
|
* assumed to be a single authenticated peer connection, so the sender address
|
|
24
20
|
* is fixed by the caller.
|
|
25
21
|
*/
|
|
26
|
-
function createStreamNegotiationTransport(config) {
|
|
22
|
+
export function createStreamNegotiationTransport(config) {
|
|
27
23
|
const { stream, sender, recipient } = config;
|
|
28
24
|
const maxBytes = config.maxBytes ?? 64 * 1024;
|
|
29
25
|
return {
|
|
@@ -74,7 +70,7 @@ function topicFor(topicPrefix, negotiationId) {
|
|
|
74
70
|
* address is carried in the envelope (a `sender` field on the message), so
|
|
75
71
|
* the ingress pipeline can authenticate it.
|
|
76
72
|
*/
|
|
77
|
-
function createPubSubNegotiationTransport(config) {
|
|
73
|
+
export function createPubSubNegotiationTransport(config) {
|
|
78
74
|
const { pubsub, recipient } = config;
|
|
79
75
|
const topicPrefix = config.topicPrefix ?? 'totem.negotiation';
|
|
80
76
|
const maxBytes = config.maxBytes ?? 64 * 1024;
|
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();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* purchase-authority.ts — AuthorityPort adapter over @totemsdk/agent-policy.
|
|
4
3
|
*
|
|
@@ -13,8 +12,6 @@
|
|
|
13
12
|
* is the trusted boundary that decides whether the local authority approves
|
|
14
13
|
* the economic commitment.
|
|
15
14
|
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createPurchaseAuthorityAdapter = createPurchaseAuthorityAdapter;
|
|
18
15
|
function isMiddleware(p) {
|
|
19
16
|
return 'evaluate' in p && typeof p.evaluate === 'function';
|
|
20
17
|
}
|
|
@@ -24,7 +21,7 @@ function isMiddleware(p) {
|
|
|
24
21
|
* approve() builds an AgentProposal from the agreement + intent and evaluates
|
|
25
22
|
* it through the policy. Returns `{ allowed, reason }`.
|
|
26
23
|
*/
|
|
27
|
-
function createPurchaseAuthorityAdapter(config) {
|
|
24
|
+
export function createPurchaseAuthorityAdapter(config) {
|
|
28
25
|
const { policy } = config;
|
|
29
26
|
const agentId = config.agentId ?? 'edge-purchase-agent';
|
|
30
27
|
const risk = config.risk ?? 'medium';
|
package/dist/purchase-lookup.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* purchase-lookup.ts — PurchaseLookupPort adapter over @totemsdk/lookup-client.
|
|
4
3
|
*
|
|
@@ -10,8 +9,6 @@
|
|
|
10
9
|
* returned manifest's signature, identity binding, expiry, and capabilities
|
|
11
10
|
* before negotiation/payment. This adapter only fetches candidates.
|
|
12
11
|
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createPurchaseLookupAdapter = createPurchaseLookupAdapter;
|
|
15
12
|
/**
|
|
16
13
|
* Create a PurchaseLookupPort adapter over a LookupClient.
|
|
17
14
|
*
|
|
@@ -20,7 +17,7 @@ exports.createPurchaseLookupAdapter = createPurchaseLookupAdapter;
|
|
|
20
17
|
* falls back to app queries. Returns `{ id, manifest: Uint8Array, nodeId }`
|
|
21
18
|
* candidates for the buyer's manifest-verification pipeline.
|
|
22
19
|
*/
|
|
23
|
-
function createPurchaseLookupAdapter(config) {
|
|
20
|
+
export function createPurchaseLookupAdapter(config) {
|
|
24
21
|
const { client } = config;
|
|
25
22
|
return {
|
|
26
23
|
async query(params) {
|
package/dist/purchase-payment.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* purchase-payment.ts — PurchasePaymentPort adapter with an atomic claim.
|
|
4
3
|
*
|
|
@@ -19,9 +18,7 @@
|
|
|
19
18
|
* `PAYMENT_STATE_UNKNOWN` rather than risking a second payment. The owner
|
|
20
19
|
* reconciles that window against the payment ledger.
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
exports.createPurchasePaymentAdapter = createPurchasePaymentAdapter;
|
|
24
|
-
const storage_1 = require("@totemsdk/storage");
|
|
21
|
+
import { MemoryStore, assertCapabilities, } from '@totemsdk/storage';
|
|
25
22
|
const DEFAULT_NAMESPACE = 'totem_payment:v1:';
|
|
26
23
|
/** In-process serialization so concurrent claims never double-pay on one store. */
|
|
27
24
|
const locks = new WeakMap();
|
|
@@ -35,15 +32,15 @@ function withPaymentLock(store, fn) {
|
|
|
35
32
|
/**
|
|
36
33
|
* Create a PurchasePaymentPort with an atomic idempotency-key claim.
|
|
37
34
|
*/
|
|
38
|
-
function createPurchasePaymentAdapter(config) {
|
|
35
|
+
export function createPurchasePaymentAdapter(config) {
|
|
39
36
|
const { port } = config;
|
|
40
37
|
const namespace = config.namespace ?? DEFAULT_NAMESPACE;
|
|
41
38
|
const store = config.store ??
|
|
42
|
-
new
|
|
39
|
+
new MemoryStore(); // dev mode — volatile, process-local
|
|
43
40
|
if (config.store) {
|
|
44
41
|
// No silent downgrade: a consumer-supplied store must be able to claim
|
|
45
42
|
// (CAS) and acknowledge durable writes unless explicitly opted out.
|
|
46
|
-
|
|
43
|
+
assertCapabilities(store, {
|
|
47
44
|
conditional: true,
|
|
48
45
|
acknowledge: config.requireAckMode ?? 'durably-acknowledged',
|
|
49
46
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* sqlite-commerce-store.ts — Production SQLite-backed CommerceStore.
|
|
4
3
|
*
|
|
@@ -28,10 +27,7 @@
|
|
|
28
27
|
* All statements use positional `?` parameters so the same SQL runs on the
|
|
29
28
|
* real better-sqlite3 native binding and the node:sqlite jest mock.
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
|
-
exports.SQLiteCommerceStore = void 0;
|
|
33
|
-
exports.createSQLiteCommerceStore = createSQLiteCommerceStore;
|
|
34
|
-
const sqlite_1 = require("@totemsdk/storage/sqlite");
|
|
30
|
+
import { SqliteStore } from '@totemsdk/storage/sqlite';
|
|
35
31
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
36
32
|
// Serialization helpers
|
|
37
33
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -154,9 +150,9 @@ const SCHEMA = `
|
|
|
154
150
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
155
151
|
// SQLite CommerceStore
|
|
156
152
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
157
|
-
class SQLiteCommerceStore {
|
|
153
|
+
export class SQLiteCommerceStore {
|
|
158
154
|
constructor(config) {
|
|
159
|
-
this.store = new
|
|
155
|
+
this.store = new SqliteStore(config.filename, {
|
|
160
156
|
createKvTable: false,
|
|
161
157
|
wal: config.wal,
|
|
162
158
|
busyTimeoutMs: config.busyTimeoutMs ?? 5000,
|
|
@@ -405,12 +401,11 @@ class SQLiteCommerceStore {
|
|
|
405
401
|
};
|
|
406
402
|
}
|
|
407
403
|
}
|
|
408
|
-
exports.SQLiteCommerceStore = SQLiteCommerceStore;
|
|
409
404
|
/**
|
|
410
405
|
* Create a SQLite-backed CommerceStore.
|
|
411
406
|
*
|
|
412
407
|
* @param config filename (or ':memory:') + WAL/busy options.
|
|
413
408
|
*/
|
|
414
|
-
function createSQLiteCommerceStore(config) {
|
|
409
|
+
export function createSQLiteCommerceStore(config) {
|
|
415
410
|
return new SQLiteCommerceStore(config);
|
|
416
411
|
}
|
package/dist/stream.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* EdgeStreamPort adapter — wraps @totemsdk/stream-transport's IStreamTransport
|
|
4
3
|
* as a first-class EdgeStreamPort for EdgeRuntimePorts.stream.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
exports.createStreamPortAdapter = createStreamPortAdapter;
|
|
8
|
-
function createStreamPortAdapter(transport) {
|
|
5
|
+
export function createStreamPortAdapter(transport) {
|
|
9
6
|
return {
|
|
10
7
|
async send(data) {
|
|
11
8
|
await transport.send(data);
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/edge-adapters",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Reference adapters bridging Totem SDK packages to @totemsdk/edge port interfaces",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/cjs/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/cjs/index.d.ts",
|
|
15
|
+
"default": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
},
|
|
14
19
|
"files": [
|
|
@@ -20,17 +25,17 @@
|
|
|
20
25
|
"@totemsdk/storage": "^0.1.0"
|
|
21
26
|
},
|
|
22
27
|
"peerDependencies": {
|
|
23
|
-
"@totemsdk/agent-policy": "
|
|
24
|
-
"@totemsdk/chain-provider": "
|
|
25
|
-
"@totemsdk/lookup-client": "
|
|
28
|
+
"@totemsdk/agent-policy": ">=0.3.1 <1.0.0",
|
|
29
|
+
"@totemsdk/chain-provider": ">=0.2.1 <1.0.0",
|
|
30
|
+
"@totemsdk/lookup-client": ">=0.2.0 <1.0.0",
|
|
31
|
+
"@totemsdk/omnia-router": ">=0.3.0 <1.0.0",
|
|
32
|
+
"@totemsdk/pubsub-transport": ">=0.2.0 <1.0.0",
|
|
33
|
+
"@totemsdk/stream-transport": ">=0.2.0 <1.0.0",
|
|
26
34
|
"@totemsdk/identity": "^1.0.1",
|
|
27
|
-
"@totemsdk/
|
|
28
|
-
"@totemsdk/manifest": "^1.0.0",
|
|
29
|
-
"@totemsdk/omnia-router": "^0.2.1",
|
|
35
|
+
"@totemsdk/manifest": "^2.0.0",
|
|
30
36
|
"@totemsdk/proof": "^1.0.0",
|
|
31
|
-
"@totemsdk/pubsub-transport": "^0.2.0",
|
|
32
37
|
"@totemsdk/root-identity": "^1.0.9",
|
|
33
|
-
"@totemsdk/
|
|
38
|
+
"@totemsdk/location-proof": "^1.0.0"
|
|
34
39
|
},
|
|
35
40
|
"peerDependenciesMeta": {
|
|
36
41
|
"@totemsdk/agent-policy": {
|
|
@@ -75,18 +80,18 @@
|
|
|
75
80
|
"typescript": "^7.0.2",
|
|
76
81
|
"@totemsdk/agent-policy": "^0.3.1",
|
|
77
82
|
"@totemsdk/chain-provider": "^0.2.1",
|
|
83
|
+
"@totemsdk/edge": "^1.3.0",
|
|
78
84
|
"@totemsdk/core": "^1.2.11",
|
|
79
|
-
"@totemsdk/edge": "^1.2.0",
|
|
80
85
|
"@totemsdk/identity": "^1.0.1",
|
|
86
|
+
"@totemsdk/manifest": "^2.0.0",
|
|
81
87
|
"@totemsdk/lookup-client": "^0.2.0",
|
|
82
|
-
"@totemsdk/
|
|
83
|
-
"@totemsdk/omnia-router": "^0.2.1",
|
|
84
|
-
"@totemsdk/pubsub-transport": "^0.2.0",
|
|
88
|
+
"@totemsdk/omnia-router": "^0.3.0",
|
|
85
89
|
"@totemsdk/location-proof": "^1.0.0",
|
|
86
|
-
"@totemsdk/root-identity": "^1.0.9",
|
|
87
90
|
"@totemsdk/proof": "^1.0.0",
|
|
88
|
-
"@totemsdk/
|
|
89
|
-
"@totemsdk/
|
|
91
|
+
"@totemsdk/pubsub-transport": "^0.2.0",
|
|
92
|
+
"@totemsdk/root-identity": "^1.0.9",
|
|
93
|
+
"@totemsdk/stream-transport": "^0.2.0",
|
|
94
|
+
"@totemsdk/txpow": "^1.0.2"
|
|
90
95
|
},
|
|
91
96
|
"engines": {
|
|
92
97
|
"node": ">=18.0.0"
|
|
@@ -117,8 +122,9 @@
|
|
|
117
122
|
"bugs": {
|
|
118
123
|
"url": "https://github.com/Totem-Edge/totem-sdk/issues"
|
|
119
124
|
},
|
|
125
|
+
"type": "module",
|
|
120
126
|
"scripts": {
|
|
121
|
-
"build": "tsc",
|
|
127
|
+
"build": "tsc && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'})+'\\n')\"",
|
|
122
128
|
"clean": "rm -rf dist",
|
|
123
129
|
"test": "jest"
|
|
124
130
|
}
|