UNPKG

noa-receipt

Version:

NOA Agent Action Receipt — open, offline-verifiable provenance for AI-agent actions. The governance/receipt organ only; the NOA brain is separate and proprietary.

409 lines (408 loc) • 20.6 kB
import { createHash as _createHashImport, createPublicKey as _createPublicKeyImport, generateKeyPairSync as _genKeyPairSyncImport, sign as _signImport, verify as _verifyImport, createPrivateKey as _createPrivateKeyImport, } from "node:crypto"; import { types as _nodeUtilTypes } from "node:util"; const _apply = Reflect.apply; const _includes = Array.prototype.includes; const _indexOf = Array.prototype.indexOf; const _lastIndexOf = Array.prototype.lastIndexOf; const _find = Array.prototype.find; const _findIndex = Array.prototype.findIndex; const _filter = Array.prototype.filter; const _map = Array.prototype.map; const _some = Array.prototype.some; const _every = Array.prototype.every; const _forEach = Array.prototype.forEach; const _join = Array.prototype.join; const _slice = Array.prototype.slice; const _sort = Array.prototype.sort; const _push = Array.prototype.push; const _concat = Array.prototype.concat; const _reduce = Array.prototype.reduce; const _reverse = Array.prototype.reverse; const _flat = Array.prototype.flat; const _isArray = Array.isArray; const _setHas = Set.prototype.has; const _setAdd = Set.prototype.add; const _setDelete = Set.prototype.delete; const _setForEach = Set.prototype.forEach; const _setSize = Reflect.getOwnPropertyDescriptor(Set.prototype, "size").get; const _mapGet = Map.prototype.get; const _mapSet = Map.prototype.set; const _mapHas = Map.prototype.has; const _mapDelete = Map.prototype.delete; const _mapForEach = Map.prototype.forEach; const _mapSize = Reflect.getOwnPropertyDescriptor(Map.prototype, "size").get; const _weakSetHas = WeakSet.prototype.has; const _weakSetAdd = WeakSet.prototype.add; const _weakMapGet = WeakMap.prototype.get; const _weakMapSet = WeakMap.prototype.set; const _weakMapHas = WeakMap.prototype.has; const _objectKeys = Object.keys; const _objectValues = Object.values; const _objectEntries = Object.entries; const _objectCreate = Object.create; const _objectFreeze = Object.freeze; const _objectIsFrozen = Object.isFrozen; const _objectDefineProperty = Object.defineProperty; const _objectGetOwnPropertyNames = Object.getOwnPropertyNames; const _objectSetPrototypeOf = Object.setPrototypeOf; const _objectAssign = Object.assign; const _hasOwnProperty = Object.prototype.hasOwnProperty; const _reflectOwnKeys = Reflect.ownKeys; const _reflectGetPrototypeOf = Reflect.getPrototypeOf; const _reflectGetOwnPropertyDescriptor = Reflect.getOwnPropertyDescriptor; const _reflectGet = Reflect.get; const _objectPrototype = Object.prototype; const _arrayPrototype = Array.prototype; const _jsonStringify = JSON.stringify; const _jsonParse = JSON.parse; const _strIncludes = String.prototype.includes; const _strStartsWith = String.prototype.startsWith; const _strEndsWith = String.prototype.endsWith; const _strIndexOf = String.prototype.indexOf; const _strSlice = String.prototype.slice; const _strSplit = String.prototype.split; const _strReplace = String.prototype.replace; const _strTrim = String.prototype.trim; const _strToLowerCase = String.prototype.toLowerCase; const _strToUpperCase = String.prototype.toUpperCase; const _strNormalize = String.prototype.normalize; const _strPadStart = String.prototype.padStart; const _strRepeat = String.prototype.repeat; const _strCharCodeAt = String.prototype.charCodeAt; const _strCodePointAt = String.prototype.codePointAt; const _strIsWellFormed = String.prototype.isWellFormed; const _strFromCharCode = String.fromCharCode; const _numberToString = Number.prototype.toString; const _objectIs = Object.is; const _numberParseInt = Number.parseInt; const _Number = Number; const _BigInt = BigInt; const _numberMaxSafeInteger = Number.MAX_SAFE_INTEGER; const _numberIsSafeInteger = Number.isSafeInteger; const _numberIsFinite = Number.isFinite; const _numberIsNaN = Number.isNaN; const _numberIsInteger = Number.isInteger; const _dateParse = Date.parse; const _dateNow = Date.now; const _regexpTest = RegExp.prototype.test; const _regexpExec = RegExp.prototype.exec; const _bufferFrom = Buffer.from; const _structuredClone = globalThis.structuredClone; const _bufferAlloc = Buffer.alloc; const _bufferConcat = Buffer.concat; const _bufferCompare = Buffer.compare; const _bufferIsBuffer = Buffer.isBuffer; const _bufToString = Buffer.prototype.toString; const _bufEquals = Buffer.prototype.equals; const _bufSlice = Buffer.prototype.subarray; const _bufWriteUInt16BE = Buffer.prototype.writeUInt16BE; const _bufWriteUInt32BE = Buffer.prototype.writeUInt32BE; const _bufWriteBigUInt64BE = Buffer.prototype.writeBigUInt64BE; const _bufReadUInt16BE = Buffer.prototype.readUInt16BE; const _bufReadUInt32BE = Buffer.prototype.readUInt32BE; const _bufReadBigUInt64BE = Buffer.prototype.readBigUInt64BE; const _typedArrayPrototype = _reflectGetPrototypeOf(Uint8Array.prototype); const _taDesc = (k) => { const d = _reflectGetOwnPropertyDescriptor(_typedArrayPrototype, k); if (d === undefined || d.get === undefined) throw new Error(`intrinsics: %TypedArray%.prototype.${k} accessor not found`); return d.get; }; const _taLengthGet = _taDesc("length"); const _taBufferGet = _taDesc("buffer"); const _taByteOffsetGet = _taDesc("byteOffset"); const _taByteLengthGet = _taDesc("byteLength"); const _Set = Set; const _Map = Map; const _WeakSet = WeakSet; const _isProxy = _nodeUtilTypes.isProxy; const _MUTATORS = _apply(_objectFreeze, undefined, [[ "push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin", ]]); export const INERT_ARRAY_PROTOTYPE = (() => { const proto = _apply(_objectCreate, undefined, [null]); const protoKeys = _apply(_reflectOwnKeys, undefined, [_arrayPrototype]); for (let i = 0; i < protoKeys.length; i++) { const key = protoKeys[i]; if (key === "constructor" || key === "length") continue; if (typeof key === "string" && _apply(_indexOf, _MUTATORS, [key]) !== -1) continue; if (key === Symbol.iterator || key === Symbol.unscopables) continue; const d = _apply(_reflectGetOwnPropertyDescriptor, undefined, [_arrayPrototype, key]); if (d === undefined) continue; if (!_apply(_hasOwnProperty, d, ["value"])) continue; _apply(_objectDefineProperty, undefined, [proto, key, { value: d.value, writable: false, enumerable: false, configurable: false, }]); } _apply(_objectDefineProperty, undefined, [proto, Symbol.iterator, { value: function inertIterator() { const self = this; let i = 0; const it = _apply(_objectCreate, undefined, [null]); _apply(_objectDefineProperty, undefined, [it, "next", { value: () => { const n = self.length; const r = _apply(_objectCreate, undefined, [null]); if (i < n) { r.value = self[i++]; r.done = false; } else { r.value = undefined; r.done = true; } return _apply(_objectFreeze, undefined, [r]); }, enumerable: false, writable: false, configurable: false, }]); _apply(_objectDefineProperty, undefined, [it, Symbol.iterator, { value: () => it, enumerable: false, writable: false, configurable: false, }]); return _apply(_objectFreeze, undefined, [it]); }, enumerable: false, writable: false, configurable: false, }]); return _apply(_objectFreeze, undefined, [proto]); })(); function _inert(a) { _apply(_objectSetPrototypeOf, undefined, [a, INERT_ARRAY_PROTOTYPE]); return a; } export function publishArray(a) { const out = []; for (let i = 0; i < a.length; i++) _apply(_push, out, [a[i]]); return out; } export function arrayIncludes(a, v) { return _apply(_includes, a, [v]); } export function arrayIndexOf(a, v) { return _apply(_indexOf, a, [v]); } export function arrayLastIndexOf(a, v) { return _apply(_lastIndexOf, a, [v]); } export function arrayFind(a, p) { return _apply(_find, a, [p]); } export function arrayFindIndex(a, p) { return _apply(_findIndex, a, [p]); } export function arrayFilter(a, p) { return _inert(_apply(_filter, a, [p])); } export function arrayMap(a, f) { return _inert(_apply(_map, a, [f])); } export function arraySome(a, p) { return _apply(_some, a, [p]); } export function arrayEvery(a, p) { return _apply(_every, a, [p]); } export function arrayForEach(a, f) { _apply(_forEach, a, [f]); } export function arrayJoin(a, sep) { return _apply(_join, a, [sep]); } export function arraySlice(a, start, end) { return _inert(_apply(_slice, a, [start, end])); } export function arraySort(a, cmp) { return _apply(_sort, a, [cmp]); } export function arrayPush(a, v) { return _apply(_push, a, [v]); } export function arrayConcat(a, b) { return _inert(_apply(_concat, a, [b])); } export function arrayReduce(a, f, init) { return _apply(_reduce, a, [f, init]); } export function arrayReverse(a) { return _apply(_reverse, a, []); } export function arrayFlat(a, depth = 1) { return _inert(_apply(_flat, a, [depth])); } export function isArray(v) { return _apply(_isArray, undefined, [v]); } export function arrayLength(a) { return _reflectGet(a, "length") >>> 0; } export function setHas(s, v) { return _apply(_setHas, s, [v]); } export function setAdd(s, v) { return _apply(_setAdd, s, [v]); } export function setDelete(s, v) { return _apply(_setDelete, s, [v]); } export function setSize(s) { return _apply(_setSize, s, []); } export function setToArray(s) { const out = []; _apply(_setForEach, s, [(v) => { _apply(_push, out, [v]); }]); return _inert(out); } export function mapGet(m, k) { return _apply(_mapGet, m, [k]); } export function mapSet(m, k, v) { return _apply(_mapSet, m, [k, v]); } export function mapHas(m, k) { return _apply(_mapHas, m, [k]); } export function mapDelete(m, k) { return _apply(_mapDelete, m, [k]); } export function mapSize(m) { return _apply(_mapSize, m, []); } export function mapValuesToArray(m) { const out = []; _apply(_mapForEach, m, [(v) => { _apply(_push, out, [v]); }]); return _inert(out); } export function mapEntriesToArray(m) { const out = []; _apply(_mapForEach, m, [(v, k) => { _apply(_push, out, [_inert([k, v])]); }]); return _inert(out); } export function weakSetHas(s, v) { return _apply(_weakSetHas, s, [v]); } export function weakSetAdd(s, v) { return _apply(_weakSetAdd, s, [v]); } export function weakMapGet(m, k) { return _apply(_weakMapGet, m, [k]); } export function weakMapSet(m, k, v) { return _apply(_weakMapSet, m, [k, v]); } export function weakMapHas(m, k) { return _apply(_weakMapHas, m, [k]); } export function objectKeys(o) { return _inert(_apply(_objectKeys, undefined, [o])); } export function objectValues(o) { return _inert(_apply(_objectValues, undefined, [o])); } export function objectEntries(o) { const es = _apply(_objectEntries, undefined, [o]); for (let i = 0; i < es.length; i++) _inert(es[i]); return _inert(es); } export function objectCreateNull() { return _apply(_objectCreate, undefined, [null]); } export function objectFreeze(o) { return _apply(_objectFreeze, undefined, [o]); } export function objectIsFrozen(o) { return _apply(_objectIsFrozen, undefined, [o]); } export function objectDefineProperty(o, k, d) { return _apply(_objectDefineProperty, undefined, [o, k, d]); } export function objectGetOwnPropertyNames(o) { return _inert(_apply(_objectGetOwnPropertyNames, undefined, [o])); } export function objectSetPrototypeOf(o, p) { return _apply(_objectSetPrototypeOf, undefined, [o, p]); } export function objectAssign(t, s) { return _apply(_objectAssign, undefined, [t, s]); } export function hasOwn(o, k) { return _apply(_hasOwnProperty, o, [k]); } export function ownKeys(o) { return _inert(_apply(_reflectOwnKeys, undefined, [o])); } export function getPrototypeOf(o) { return _apply(_reflectGetPrototypeOf, undefined, [o]); } export function getOwnPropertyDescriptor(o, k) { return _apply(_reflectGetOwnPropertyDescriptor, undefined, [o, k]); } export const OBJECT_PROTOTYPE = _objectPrototype; export const ARRAY_PROTOTYPE = _arrayPrototype; export function jsonStringify(v, replacer, space) { return _apply(_jsonStringify, undefined, [v, replacer, space]); } export function jsonParse(s) { return _apply(_jsonParse, undefined, [s]); } export function strIncludes(s, v) { return _apply(_strIncludes, s, [v]); } export function strStartsWith(s, v) { return _apply(_strStartsWith, s, [v]); } export function strEndsWith(s, v) { return _apply(_strEndsWith, s, [v]); } export function strIndexOf(s, v) { return _apply(_strIndexOf, s, [v]); } export function strSlice(s, a, b) { return _apply(_strSlice, s, [a, b]); } export function strSplit(s, sep) { return _inert(_apply(_strSplit, s, [sep])); } export function strReplace(s, pat, rep) { return _apply(_strReplace, s, [pat, rep]); } export function strTrim(s) { return _apply(_strTrim, s, []); } export function strToLowerCase(s) { return _apply(_strToLowerCase, s, []); } export function strToUpperCase(s) { return _apply(_strToUpperCase, s, []); } export function strNormalize(s, form) { return _apply(_strNormalize, s, [form]); } export function strPadStart(s, len, pad) { return _apply(_strPadStart, s, [len, pad]); } export function strRepeat(s, n) { return _apply(_strRepeat, s, [n]); } export function strCharCodeAt(s, i) { return _apply(_strCharCodeAt, s, [i]); } export function strCodePointAt(s, i) { return _apply(_strCodePointAt, s, [i]); } export function strIsWellFormed(s) { return _apply(_strIsWellFormed, s, []); } export function strFromCharCode(code) { return _apply(_strFromCharCode, undefined, [code]); } export function strStartsWithAt(s, v, pos) { return _apply(_strStartsWith, s, [v, pos]); } export function numToString(n, radix) { return _apply(_numberToString, n, [radix]); } export function objectIs(a, b) { return _apply(_objectIs, undefined, [a, b]); } export function parseIntRadix(s, radix) { return _apply(_numberParseInt, undefined, [s, radix]); } export function toNumber(v) { return _Number(v); } export function isSafeInteger(v) { return _apply(_numberIsSafeInteger, undefined, [v]); } export function isFiniteNumber(v) { return _apply(_numberIsFinite, undefined, [v]); } export function isNaNValue(v) { return _apply(_numberIsNaN, undefined, [v]); } export function isInteger(v) { return _apply(_numberIsInteger, undefined, [v]); } export function dateParse(s) { return _apply(_dateParse, undefined, [s]); } export function dateNow() { return _apply(_dateNow, undefined, []); } export function regexpTest(re, s) { return _apply(_regexpTest, re, [s]); } export function regexpExec(re, s) { const m = _apply(_regexpExec, re, [s]); return m === null ? null : _inert(m); } export function bufferFrom(v, enc) { return _apply(_bufferFrom, undefined, [v, enc]); } export function bufferAlloc(n) { return _apply(_bufferAlloc, undefined, [n]); } export function bufferConcat(list) { return _apply(_bufferConcat, undefined, [list]); } export function bufferCompare(a, b) { return _apply(_bufferCompare, undefined, [a, b]); } export function isBuffer(v) { return _apply(_bufferIsBuffer, undefined, [v]); } export function structuredCloneValue(v) { return _apply(_structuredClone, undefined, [v]); } export function bufToString(b, enc) { return _apply(_bufToString, b, [enc]); } export function bufEquals(a, b) { return _apply(_bufEquals, a, [b]); } export function bufSubarray(b, s, e) { return _apply(_bufSlice, b, [s, e]); } const _createHash = _createHashImport; const _hashProto = Object.getPrototypeOf(_createHash("sha256")); const _hashUpdate = _hashProto.update; const _hashDigest = _hashProto.digest; const _createPublicKey = _createPublicKeyImport; const _bootstrapKP = _genKeyPairSyncImport("ed25519"); const _keyExportPub = Object.getPrototypeOf(_bootstrapKP.publicKey).export; const _keyExportPriv = Object.getPrototypeOf(_bootstrapKP.privateKey).export; export function bufferFromArrayBuffer(ab, off, len) { return _apply(_bufferFrom, undefined, [ab, off, len]); } export function bufReadUInt16BE(b, off) { return _apply(_bufReadUInt16BE, b, [off]); } export function bufReadUInt32BE(b, off) { return _apply(_bufReadUInt32BE, b, [off]); } export function bufReadBigUInt64BE(b, off) { return _apply(_bufReadBigUInt64BE, b, [off]); } export function bufWriteUInt16BE(b, v, off) { return _apply(_bufWriteUInt16BE, b, [v, off]); } export function bufWriteUInt32BE(b, v, off) { return _apply(_bufWriteUInt32BE, b, [v, off]); } export function bufWriteBigUInt64BE(b, v, off) { return _apply(_bufWriteBigUInt64BE, b, [v, off]); } export function sha256With(data, encoding) { const h = _createHash("sha256"); _apply(_hashUpdate, h, [data]); return _apply(_hashDigest, h, encoding === undefined ? [] : [encoding]); } export function createPublicKeyCaptured(opts) { return _createPublicKey(opts); } export function keyExportSpkiDer(key) { return _apply(_keyExportPub, key, [{ type: "spki", format: "der" }]); } export function keyExportPkcs8Der(key) { return _apply(_keyExportPriv, key, [{ type: "pkcs8", format: "der" }]); } const _setProto = Set.prototype; const _mapProto = Map.prototype; const _weakSetProto = WeakSet.prototype; const _weakMapProto = WeakMap.prototype; export function collectionBrand(v) { if (v === null || typeof v !== "object") return null; let p = _apply(_reflectGetPrototypeOf, undefined, [v]); while (p !== null) { if (p === _setProto) return "Set"; if (p === _mapProto) return "Map"; if (p === _weakSetProto) return "WeakSet"; if (p === _weakMapProto) return "WeakMap"; p = _apply(_reflectGetPrototypeOf, undefined, [p]); } return null; } const _cryptoSign = _signImport; const _cryptoVerify = _verifyImport; const _createPrivateKey = _createPrivateKeyImport; const _generateKeyPairSync = _genKeyPairSyncImport; const _asymmetricKeyTypeGet = (() => { let p = _apply(_reflectGetPrototypeOf, undefined, [_bootstrapKP.publicKey]); while (p !== null) { const d = _apply(_reflectGetOwnPropertyDescriptor, undefined, [p, "asymmetricKeyType"]); if (d !== undefined && d.get !== undefined) return d.get; p = _apply(_reflectGetPrototypeOf, undefined, [p]); } throw new Error("intrinsics: KeyObject.asymmetricKeyType accessor not found — the curve pin cannot be captured"); })(); export function ed25519Verify(message, key, signature) { return _cryptoVerify(null, message, key, signature); } export function ed25519Sign(message, key) { return _cryptoSign(null, message, key); } export function createPrivateKeyCaptured(opts) { return _createPrivateKey(opts); } export function generateEd25519KeyPair() { return _generateKeyPairSync("ed25519"); } export function asymmetricKeyType(key) { return _apply(_asymmetricKeyTypeGet, key, []); } export function toBigInt(v) { return _BigInt(v); } export function bigIntToNumber(v) { return _Number(v); } export const MAX_SAFE_INTEGER = _numberMaxSafeInteger; export function byteLength(b) { return _apply(_taLengthGet, b, []); } export function taBuffer(b) { return _apply(_taBufferGet, b, []); } export function taByteOffset(b) { return _apply(_taByteOffsetGet, b, []); } export function taByteLength(b) { return _apply(_taByteLengthGet, b, []); } export function newSet(init) { const s = new _Set(); if (init !== undefined) { for (let i = 0; i < init.length; i++) _apply(_setAdd, s, [init[i]]); } return s; } export function newMap() { return new _Map(); } export function newWeakSet() { return new _WeakSet(); } export function isProxy(v) { return _apply(_isProxy, undefined, [v]); } export function strCodePointCount(s) { let count = 0; const len = s.length; for (let i = 0; i < len; i++) { const c = _apply(_strCharCodeAt, s, [i]); if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) { const c2 = _apply(_strCharCodeAt, s, [i + 1]); if (c2 >= 0xdc00 && c2 <= 0xdfff) i++; } count++; } return count; }