@lemmaoracle/agent 0.0.24-alpha.1 → 0.0.24

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,3 @@
1
+ import type { AgentCredential, NormalizedAgentCredential } from "./types.js";
2
+ export declare const normalize: (cred: AgentCredential) => NormalizedAgentCredential;
3
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EAM1B,MAAM,YAAY,CAAC;AA8DpB,eAAO,MAAM,SAAS,GAAI,MAAM,eAAe,KAAG,yBA+CjD,CAAC"}
@@ -0,0 +1,82 @@
1
+ import * as R from "ramda";
2
+ const canonicalizeString = (s) => s.startsWith("0x") ? s.toLowerCase() : s.trim();
3
+ const canonicalizeOptional = (s) => R.isNil(s) ? "" : canonicalizeString(s);
4
+ const normalizeArrayField = (items) => {
5
+ const strings = R.map((item) => item.name, items);
6
+ const sorted = R.sort((a, b) => a.localeCompare(b), strings);
7
+ return R.join(",", R.uniq(sorted));
8
+ };
9
+ const normalizePermissions = (items) => {
10
+ const strings = R.map((p) => `${p.resource}:${p.action}`, items);
11
+ const sorted = R.sort((a, b) => a.localeCompare(b), strings);
12
+ return R.join(",", R.uniq(sorted));
13
+ };
14
+ const julianToGregorian = (jd) => {
15
+ const l = jd + 68569;
16
+ const n = Math.floor((4 * l) / 146097);
17
+ const l2 = l - Math.floor((146097 * n + 3) / 4);
18
+ const i = Math.floor((4000 * (l2 + 1)) / 1461001);
19
+ const l3 = l2 - Math.floor((1461 * i) / 4) + 31;
20
+ const j = Math.floor((80 * l3) / 2447);
21
+ const day = l3 - Math.floor((2447 * j) / 80);
22
+ const l4 = Math.floor(j / 11);
23
+ const month = j + 2 - 12 * l4;
24
+ const year = 100 * (n - 49) + i + l4;
25
+ return [year, month, day];
26
+ };
27
+ const normalizeTimestamp = (ts) => {
28
+ const totalSeconds = ts;
29
+ const days = Math.floor(totalSeconds / 86400);
30
+ const remaining = totalSeconds % 86400;
31
+ const hours = Math.floor(remaining / 3600);
32
+ const minutes = Math.floor((remaining % 3600) / 60);
33
+ const seconds = remaining % 60;
34
+ const [year, month, day] = julianToGregorian(days + 2440588);
35
+ const pad = (n, w) => String(n).padStart(w, "0");
36
+ return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}T${pad(hours, 2)}:${pad(minutes, 2)}:${pad(seconds, 2)}.000Z`;
37
+ };
38
+ const normalizeOptionalTimestamp = (ts) => R.isNil(ts) ? "none" : normalizeTimestamp(ts);
39
+ const normalizeSpendLimit = (limit) => R.isNil(limit) ? "unlimited" : String(limit);
40
+ const normalizeBool = (b) => b === true ? "true" : "false";
41
+ export const normalize = (cred) => {
42
+ const identity = {
43
+ agentId: canonicalizeString(cred.identity.agentId),
44
+ subjectId: canonicalizeString(cred.identity.subjectId),
45
+ controllerId: canonicalizeOptional(cred.identity.controllerId),
46
+ orgId: canonicalizeOptional(cred.identity.orgId),
47
+ };
48
+ const authority = {
49
+ roles: normalizeArrayField(cred.authority.roles),
50
+ scopes: normalizeArrayField(cred.authority.scopes),
51
+ permissions: normalizePermissions(cred.authority.permissions),
52
+ };
53
+ const fin = cred.financial ?? { spendLimit: undefined, currency: "USD", paymentPolicy: "" };
54
+ const financial = {
55
+ spendLimit: normalizeSpendLimit(fin.spendLimit),
56
+ currency: fin.currency ?? "USD",
57
+ paymentPolicy: fin.paymentPolicy ?? "",
58
+ };
59
+ const lifecycle = {
60
+ issuedAt: normalizeTimestamp(cred.lifecycle.issuedAt),
61
+ expiresAt: normalizeOptionalTimestamp(cred.lifecycle.expiresAt),
62
+ revoked: normalizeBool(cred.lifecycle.revoked),
63
+ revocationRef: cred.lifecycle.revocationRef ?? "",
64
+ };
65
+ const cc = cred.provenance.chainContext;
66
+ const provenance = {
67
+ issuerId: canonicalizeString(cred.provenance.issuerId),
68
+ sourceSystem: canonicalizeOptional(cred.provenance.sourceSystem),
69
+ generatorId: canonicalizeOptional(cred.provenance.generatorId),
70
+ chainId: cc?.chainId !== undefined ? String(cc.chainId) : "",
71
+ network: cc?.network ?? "",
72
+ };
73
+ return {
74
+ schema: cred.schema,
75
+ identity,
76
+ authority,
77
+ financial,
78
+ lifecycle,
79
+ provenance,
80
+ };
81
+ };
82
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAW3B,MAAM,kBAAkB,GAAG,CAAC,CAAS,EAAU,EAAE,CAC/C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAElD,MAAM,oBAAoB,GAAG,CAAC,CAAqB,EAAU,EAAE,CAC7D,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAE1C,MAAM,mBAAmB,GAAG,CAAC,KAAsC,EAAU,EAAE;IAC7E,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAsB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC7E,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CA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= ["cdylib", "lib"]
12
12
 
13
13
  [dependencies]
14
14
  wasm-bindgen = "0.2"
15
- js-sys = "0.3"
16
15
  serde = { version = "1", features = ["derive"] }
17
16
  serde_json = "1"
18
17
 
@@ -283,7 +283,6 @@ fn normalize_bool(b: &Option<bool>) -> String {
283
283
  #[derive(Serialize)]
284
284
  #[serde(tag = "error")]
285
285
  enum NormalizeError {
286
- StringifyFailed,
287
286
  ParseFailed(String),
288
287
  SerializeFailed(String),
289
288
  }
@@ -291,7 +290,6 @@ enum NormalizeError {
291
290
  #[derive(Serialize)]
292
291
  #[serde(tag = "error")]
293
292
  enum ValidationError {
294
- StringifyFailed,
295
293
  ParseFailed(String),
296
294
  InvalidSchema(String),
297
295
  EmptyAgentId,
@@ -303,47 +301,17 @@ enum ValidationError {
303
301
  EmptyIssuerId,
304
302
  }
305
303
 
306
- impl ValidationError {
307
- fn to_js_value(&self) -> JsValue {
308
- let json = serde_json::to_string(self).unwrap_or_else(|_| {
309
- r#"{"error":"SerializeFailed"}"#.to_string()
310
- });
311
- let obj = js_sys::Object::new();
312
- js_sys::Reflect::set(&obj, &"valid".into(), &false.into()).unwrap();
313
- let parsed = js_sys::JSON::parse(&json).unwrap_or_else(|_| {
314
- js_sys::Object::new().into()
315
- });
316
- if let Ok(err_obj) = parsed.dyn_into::<js_sys::Object>() {
317
- js_sys::Reflect::set(&obj, &"error".into(), &js_sys::Reflect::get(&err_obj, &"error".into()).unwrap_or_else(|_| "unknown".into())).unwrap();
318
- }
319
- obj.into()
320
- }
321
- }
322
-
323
- impl NormalizeError {
324
- fn to_js_value(&self) -> JsValue {
325
- let json = serde_json::to_string(self).unwrap_or_else(|_| {
326
- r#"{"error":"SerializeFailed"}"#.to_string()
327
- });
328
- JsValue::from_str(&json)
329
- }
330
- }
331
-
332
304
  // ── Core functions ───────────────────────────────────────────────────
333
305
 
306
+ /// Entry point called by Lemma SDK's `define()`.
307
+ /// Must be exported as `normalize` and accept/return JSON strings.
334
308
  #[wasm_bindgen]
335
- pub fn normalize(input: JsValue) -> JsValue {
336
- let input_str = match js_sys::JSON::stringify(&input) {
337
- Ok(s) => s.as_string().unwrap_or_else(|| String::from("{}")),
338
- Err(_) => {
339
- return NormalizeError::StringifyFailed.to_js_value();
340
- }
341
- };
342
-
343
- let cred: AgentCredentialInput = match serde_json::from_str(&input_str) {
309
+ pub fn normalize(raw_json: &str) -> String {
310
+ let cred: AgentCredentialInput = match serde_json::from_str(raw_json) {
344
311
  Ok(c) => c,
345
312
  Err(e) => {
346
- return NormalizeError::ParseFailed(e.to_string()).to_js_value();
313
+ let err = NormalizeError::ParseFailed(e.to_string());
314
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
347
315
  }
348
316
  };
349
317
 
@@ -405,97 +373,83 @@ pub fn normalize(input: JsValue) -> JsValue {
405
373
  provenance,
406
374
  };
407
375
 
408
- let output_json = match serde_json::to_string(&output) {
376
+ match serde_json::to_string(&output) {
409
377
  Ok(s) => s,
410
378
  Err(e) => {
411
- return NormalizeError::SerializeFailed(e.to_string()).to_js_value();
379
+ let err = NormalizeError::SerializeFailed(e.to_string());
380
+ serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string())
412
381
  }
413
- };
414
-
415
- // Return the normalized JSON as a string; Lemma SDK's define() handles JSON.parse
416
- JsValue::from_str(&output_json)
382
+ }
417
383
  }
418
384
 
419
385
  #[wasm_bindgen]
420
- pub fn validate(input: JsValue) -> JsValue {
421
- let input_str = match js_sys::JSON::stringify(&input) {
422
- Ok(s) => s.as_string().unwrap_or_else(|| String::from("{}")),
423
- Err(_) => {
424
- return ValidationError::StringifyFailed.to_js_value();
425
- }
426
- };
427
-
428
- let cred: AgentCredentialInput = match serde_json::from_str(&input_str) {
386
+ pub fn validate(raw_json: &str) -> String {
387
+ let cred: AgentCredentialInput = match serde_json::from_str(raw_json) {
429
388
  Ok(c) => c,
430
389
  Err(e) => {
431
- return ValidationError::ParseFailed(e.to_string()).to_js_value();
390
+ let err = ValidationError::ParseFailed(e.to_string());
391
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
432
392
  }
433
393
  };
434
394
 
435
395
  // Validate schema field
436
396
  if cred.schema != "agent-identity-authority-v1" {
437
- return ValidationError::InvalidSchema(cred.schema).to_js_value();
397
+ let err = ValidationError::InvalidSchema(cred.schema);
398
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
438
399
  }
439
400
 
440
401
  // Validate identity
441
402
  if cred.identity.agent_id.is_empty() {
442
- return ValidationError::EmptyAgentId.to_js_value();
403
+ let err = ValidationError::EmptyAgentId;
404
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
443
405
  }
444
406
  if cred.identity.subject_id.is_empty() {
445
- return ValidationError::EmptySubjectId.to_js_value();
407
+ let err = ValidationError::EmptySubjectId;
408
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
446
409
  }
447
410
 
448
- // Validate lifecycle (fract/negative checks removed — enforced by u64 deserializer)
411
+ // Validate lifecycle
449
412
  if let Some(ref exp) = cred.lifecycle.expires_at {
450
413
  if *exp > 4102444800u64 {
451
- return ValidationError::InvalidTimestamp("lifecycle.expiresAt must be ≤ 4102444800".to_string()).to_js_value();
414
+ let err = ValidationError::InvalidTimestamp("lifecycle.expiresAt must be ≤ 4102444800".to_string());
415
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
452
416
  }
453
417
  if *exp <= cred.lifecycle.issued_at {
454
- return ValidationError::InvalidTimestamp("lifecycle.expiresAt must be > lifecycle.issuedAt".to_string()).to_js_value();
418
+ let err = ValidationError::InvalidTimestamp("lifecycle.expiresAt must be > lifecycle.issuedAt".to_string());
419
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
455
420
  }
456
421
  }
457
422
 
458
423
  // Validate authority
459
424
  if cred.authority.roles.is_empty() {
460
- return ValidationError::EmptyRoles.to_js_value();
425
+ let err = ValidationError::EmptyRoles;
426
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
461
427
  }
462
428
 
463
429
  // Validate financial
464
430
  if let Some(ref fin) = cred.financial {
465
431
  if let Some(limit) = fin.spend_limit {
466
432
  if limit > 1_000_000_000_000u64 {
467
- return ValidationError::SpendLimitExceeded.to_js_value();
433
+ let err = ValidationError::SpendLimitExceeded;
434
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
468
435
  }
469
436
  }
470
437
  if let Some(ref currency) = fin.currency {
471
438
  if currency.len() != 3 || !currency.chars().all(|c| c.is_ascii_uppercase()) {
472
- return ValidationError::InvalidCurrency.to_js_value();
439
+ let err = ValidationError::InvalidCurrency;
440
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
473
441
  }
474
442
  }
475
443
  }
476
444
 
477
445
  // Validate provenance
478
446
  if cred.provenance.issuer_id.is_empty() {
479
- return ValidationError::EmptyIssuerId.to_js_value();
447
+ let err = ValidationError::EmptyIssuerId;
448
+ return serde_json::to_string(&err).unwrap_or_else(|_| r#"{"error":"SerializeFailed"}"#.to_string());
480
449
  }
481
450
 
482
451
  // All validations passed
483
- let ok = serde_json::json!({"valid": true});
484
- JsValue::from_str(&ok.to_string())
485
- }
486
-
487
- /// Lemma schema entry point
488
- /// Format: { result: normalized_json_string, valid: bool }
489
- #[wasm_bindgen]
490
- pub fn process(input: JsValue) -> JsValue {
491
- let normalized = normalize(input.clone());
492
- let is_valid = validate(input);
493
-
494
- let obj = js_sys::Object::new();
495
- js_sys::Reflect::set(&obj, &"result".into(), &normalized).unwrap();
496
- js_sys::Reflect::set(&obj, &"valid".into(), &is_valid).unwrap();
497
-
498
- obj.into()
452
+ r#"{"valid":true}"#.to_string()
499
453
  }
500
454
 
501
455
  #[cfg(test)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemmaoracle/agent",
3
- "version": "0.0.24-alpha.1",
3
+ "version": "0.0.24",
4
4
  "description": "Agent Identity + Authority Credential schema WASM for Lemma circuits",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "test": "cargo test --manifest-path normalize/Cargo.toml",
27
27
  "test:ts": "vitest run",
28
28
  "test:circuit": "cd circuits && npx vitest run",
29
- "register": "tsx scripts/register-schema.ts",
29
+ "register:schema": "tsx scripts/register-schema.ts",
30
30
  "register:circuit": "tsx scripts/register-circuit.ts"
31
31
  },
32
32
  "keywords": [
@@ -39,8 +39,8 @@
39
39
  "wasm"
40
40
  ],
41
41
  "dependencies": {
42
- "@lemmaoracle/sdk": "^0.0.23",
43
- "@lemmaoracle/spec": "^0.0.23",
42
+ "@lemmaoracle/sdk": "^0.0.24",
43
+ "@lemmaoracle/spec": "^0.0.24",
44
44
  "poseidon-lite": "0.3.0",
45
45
  "ramda": "0.30.1"
46
46
  },
@@ -36,10 +36,6 @@ wasm-pack build \
36
36
  --release \
37
37
  --scope lemma
38
38
 
39
- echo "2. Renaming for Lemma compatibility..."
40
- mv "$OUT_DIR/lemma_agent_bg.wasm" "$OUT_DIR/agent.wasm"
41
- mv "$OUT_DIR/lemma_agent.js" "$OUT_DIR/agent.js"
42
-
43
39
  echo "✅ WASM build complete!"
44
40
  echo "📁 Output: $OUT_DIR"
45
41
  echo "📦 Files generated:"