@verana-labs/vs-agent-model 1.9.0-dev.9 → 1.9.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.
@@ -0,0 +1,33 @@
1
+ export declare enum ECS {
2
+ SERVICE = "ecs-service",
3
+ ORG = "ecs-org",
4
+ PERSONA = "ecs-persona",
5
+ USER_AGENT = "ecs-user-agent"
6
+ }
7
+ export declare function mapToEcosystem(input: string): string;
8
+ export declare const ECS_SCHEMA_DIGESTS: Record<ECS, string>;
9
+ /**
10
+ * Identifies the ECS type for a given JSON schema object by computing its
11
+ * SHA-384 digest (without the $id field) and comparing against known ECS digests.
12
+ *
13
+ * @returns The matching ECS type or null if no match is found.
14
+ */
15
+ export declare function identifySchema(schemaObj: Record<string, unknown>): Promise<ECS | null>;
16
+ type W3CCred = {
17
+ credentialSubject?: {
18
+ jsonSchema?: {
19
+ $ref?: string;
20
+ };
21
+ };
22
+ };
23
+ export declare function resolveVTCType(item: {
24
+ credential?: {
25
+ credentialSchema?: {
26
+ id?: string;
27
+ };
28
+ };
29
+ }): Promise<ECS | 'other'>;
30
+ export declare function resolveJSCType(item: {
31
+ credential?: W3CCred;
32
+ }): Promise<ECS | 'other'>;
33
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ECS_SCHEMA_DIGESTS = exports.ECS = void 0;
15
+ exports.mapToEcosystem = mapToEcosystem;
16
+ exports.identifySchema = identifySchema;
17
+ exports.resolveVTCType = resolveVTCType;
18
+ exports.resolveJSCType = resolveJSCType;
19
+ var ECS;
20
+ (function (ECS) {
21
+ ECS["SERVICE"] = "ecs-service";
22
+ ECS["ORG"] = "ecs-org";
23
+ ECS["PERSONA"] = "ecs-persona";
24
+ ECS["USER_AGENT"] = "ecs-user-agent";
25
+ })(ECS || (exports.ECS = ECS = {}));
26
+ const urlMap = new Map([
27
+ ['vpr:verana:vna-mainnet-1', 'https://idx.testnet.verana.network/verana'],
28
+ ['vpr:verana:vna-testnet-1', 'https://idx.testnet.verana.network/verana'],
29
+ ['vpr:verana:vna-devnet-1', 'https://idx.devnet.verana.network/verana'],
30
+ ]);
31
+ function mapToEcosystem(input) {
32
+ for (const [key, value] of urlMap.entries()) {
33
+ if (input.includes(key)) {
34
+ input = input.replace(key, value);
35
+ }
36
+ }
37
+ return input;
38
+ }
39
+ exports.ECS_SCHEMA_DIGESTS = {
40
+ [ECS.SERVICE]: 'sha384-PVseqJJjEGMVRcht77rE2yLqRnCiLBRLOklSuAshSEXK3eyITmUpDBhpQryJ/XIx',
41
+ [ECS.ORG]: 'sha384-XF10SsOaav+i+hBaXP29coZWZeaCZocFvfP9ZeHh9B7++q7YGA2QLTbFZqtYs/zA',
42
+ [ECS.PERSONA]: 'sha384-4vkQl6Ro6fudr+g5LL2NQJWVxaSTaYkyf0yVPVUmzA2leNNn0sJIsM07NlOAG/2I',
43
+ [ECS.USER_AGENT]: 'sha384-yLRK2mCokVjRlGX0nVzdEYQ1o6YWpQqgdg6+HlSxCePP+D7wvs0+70TJACLZfbF/',
44
+ };
45
+ // RFC 8785 JSON Canonicalization Scheme
46
+ function canonicalize(value) {
47
+ if (value === null || typeof value !== 'object')
48
+ return JSON.stringify(value);
49
+ if (Array.isArray(value))
50
+ return '[' + value.map(canonicalize).join(',') + ']';
51
+ const obj = value;
52
+ return ('{' +
53
+ Object.keys(obj)
54
+ .sort()
55
+ .map(k => `${JSON.stringify(k)}:${canonicalize(obj[k])}`)
56
+ .join(',') +
57
+ '}');
58
+ }
59
+ async function computeSchemaDigest(schemaObj) {
60
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
+ const { $id: _ } = schemaObj, schemaWithoutId = __rest(schemaObj, ["$id"]);
62
+ const canonical = canonicalize(schemaWithoutId);
63
+ const encoded = new TextEncoder().encode(canonical);
64
+ const hashBuffer = await crypto.subtle.digest('SHA-384', encoded);
65
+ const bytes = new Uint8Array(hashBuffer);
66
+ let binary = '';
67
+ for (let i = 0; i < bytes.length; i++)
68
+ binary += String.fromCharCode(bytes[i]);
69
+ return `sha384-${btoa(binary)}`;
70
+ }
71
+ /**
72
+ * Identifies the ECS type for a given JSON schema object by computing its
73
+ * SHA-384 digest (without the $id field) and comparing against known ECS digests.
74
+ *
75
+ * @returns The matching ECS type or null if no match is found.
76
+ */
77
+ async function identifySchema(schemaObj) {
78
+ const actualDigest = await computeSchemaDigest(schemaObj);
79
+ for (const [schemaName, refDigest] of Object.entries(exports.ECS_SCHEMA_DIGESTS)) {
80
+ if (refDigest === actualDigest)
81
+ return schemaName;
82
+ }
83
+ return null;
84
+ }
85
+ async function resolveBySubjectRef(subjectRef) {
86
+ var _a;
87
+ const schemaFetchUrl = mapToEcosystem(subjectRef);
88
+ const schemaObj = await fetch(schemaFetchUrl).then(r => (r.ok ? r.json() : null));
89
+ if (!schemaObj)
90
+ return 'other';
91
+ return (_a = (await identifySchema(schemaObj))) !== null && _a !== void 0 ? _a : 'other';
92
+ }
93
+ async function resolveFromW3CCred(cred) {
94
+ var _a, _b;
95
+ const ref = (_b = (_a = cred.credentialSubject) === null || _a === void 0 ? void 0 : _a.jsonSchema) === null || _b === void 0 ? void 0 : _b.$ref;
96
+ if (!ref)
97
+ return 'other';
98
+ return resolveBySubjectRef(ref);
99
+ }
100
+ async function resolveVTCType(item) {
101
+ var _a, _b;
102
+ try {
103
+ const schemaUrl = (_b = (_a = item.credential) === null || _a === void 0 ? void 0 : _a.credentialSchema) === null || _b === void 0 ? void 0 : _b.id;
104
+ if (!schemaUrl)
105
+ return 'other';
106
+ const w3cCred = await fetch(schemaUrl).then(r => (r.ok ? r.json() : null));
107
+ if (!w3cCred)
108
+ return 'other';
109
+ return resolveFromW3CCred(w3cCred);
110
+ }
111
+ catch (_c) {
112
+ return 'other';
113
+ }
114
+ }
115
+ async function resolveJSCType(item) {
116
+ try {
117
+ if (!item.credential)
118
+ return 'other';
119
+ return resolveFromW3CCred(item.credential);
120
+ }
121
+ catch (_a) {
122
+ return 'other';
123
+ }
124
+ }
125
+ //# sourceMappingURL=ecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecs.js","sourceRoot":"","sources":["../../src/utils/ecs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAaA,wCAOC;AA0CD,wCAMC;AAmBD,wCAcC;AAED,wCAOC;AA9GD,IAAY,GAKX;AALD,WAAY,GAAG;IACb,8BAAuB,CAAA;IACvB,sBAAe,CAAA;IACf,8BAAuB,CAAA;IACvB,oCAA6B,CAAA;AAC/B,CAAC,EALW,GAAG,mBAAH,GAAG,QAKd;AAED,MAAM,MAAM,GAAG,IAAI,GAAG,CAAiB;IACrC,CAAC,0BAA0B,EAAE,2CAA2C,CAAC;IACzE,CAAC,0BAA0B,EAAE,2CAA2C,CAAC;IACzE,CAAC,yBAAyB,EAAE,0CAA0C,CAAC;CACxE,CAAC,CAAA;AAEF,SAAgB,cAAc,CAAC,KAAa;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAEY,QAAA,kBAAkB,GAAwB;IACrD,CA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D,IAAI,CAAC,GAAG;QAAE,OAAO,OAAO,CAAA;IACxB,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC;AAEM,KAAK,UAAU,cAAc,CAAC,IAEpC;;IACC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAA,MAAA,IAAI,CAAC,UAAU,0CAAE,gBAAgB,0CAAE,EAAE,CAAA;QACvD,IAAI,CAAC,SAAS;YAAE,OAAO,OAAO,CAAA;QAE9B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1E,IAAI,CAAC,OAAO;YAAE,OAAO,OAAO,CAAA;QAE5B,OAAO,kBAAkB,CAAC,OAAkB,CAAC,CAAA;IAC/C,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,cAAc,CAAC,IAA8B;IACjE,IAAI,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,OAAO,CAAA;QACpC,OAAO,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC5C,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './stats';
2
2
  export * from './dateUtils';
3
+ export * from './ecs';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./stats"), exports);
18
18
  __exportStar(require("./dateUtils"), exports);
19
+ __exportStar(require("./ecs"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,8CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,8CAA2B;AAC3B,wCAAqB"}
package/package.json CHANGED
@@ -2,7 +2,19 @@
2
2
  "name": "@verana-labs/vs-agent-model",
3
3
  "main": "build/index",
4
4
  "types": "build/index",
5
- "version": "1.9.0-dev.9",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./build/index.d.ts",
8
+ "require": "./build/index.js",
9
+ "default": "./build/index.js"
10
+ },
11
+ "./ecs": {
12
+ "types": "./build/utils/ecs.d.ts",
13
+ "require": "./build/utils/ecs.js",
14
+ "default": "./build/utils/ecs.js"
15
+ }
16
+ },
17
+ "version": "1.9.0",
6
18
  "repository": {
7
19
  "type": "git",
8
20
  "url": "https://github.com/verana-labs/vs-agent"