Files
js/test/gen/capabilities_zap.ts
zeekay 696e182d6b chore: replace Cap'n Proto codec with native ZAP wire runtime
@zap-proto/zap is the native ZAP TS implementation (zero-copy,
byte-compat with github.com/zap-proto/go). The previous content
was an absorbed fork of unjs/capnp-es (now archived as zap-es).
ZAP is not Cap'n Proto. Reset to v0.1.0; no tags until 1.0 works
end-to-end across @zap-proto/{zap,web,mcp} + the esign migration.
2026-06-15 15:26:39 -07:00

201 lines
6.3 KiB
TypeScript

// Code generated by zapgen --target=ts; DO NOT EDIT.
// source: capabilities.zap
import {
Builder,
Message,
StructView,
type ListView,
} from "@zap-proto/zap";
export type id32 = Uint8Array & { readonly __brand: "id32" };
export type sig3408 = Uint8Array & { readonly __brand: "sig3408" };
const capabilityOff = {
Kind: 0,
Target: 4,
Holder: 36,
Issuer: 68,
Permissions: 100,
Parent: 108,
IssuedAt: 140,
ExpiresAt: 148,
Caveats: 156,
Sig: 164,
} as const;
const capabilitySize = 3572;
/** Zero-copy view into a ZAP-encoded Capability message. */
export class Capability extends StructView {
/** Parse `b` and return a typed view. Throws on a wire-level check failure (magic, version, size). */
static wrap(b: Uint8Array): Capability {
const root = Message.parse(b).root();
return new Capability(root.data, root.offset);
}
get kind(): number { return this.u32(capabilityOff.Kind); }
get target(): Uint8Array { return this.bytesFixed(capabilityOff.Target, 32); }
get holder(): Uint8Array { return this.bytesFixed(capabilityOff.Holder, 32); }
get issuer(): Uint8Array { return this.bytesFixed(capabilityOff.Issuer, 32); }
get permissions(): bigint { return this.u64(capabilityOff.Permissions); }
get parent(): Uint8Array { return this.bytesFixed(capabilityOff.Parent, 32); }
get issuedAt(): bigint { return this.u64(capabilityOff.IssuedAt); }
get expiresAt(): bigint { return this.u64(capabilityOff.ExpiresAt); }
get caveats(): ListView { return this.list(capabilityOff.Caveats); }
get sig(): Uint8Array { return this.bytesFixed(capabilityOff.Sig, 3408); }
}
/** Field values for newCapability. */
export interface CapabilityInput {
kind: number;
target: Uint8Array;
holder: Uint8Array;
issuer: Uint8Array;
permissions: bigint;
parent: Uint8Array;
issuedAt: bigint;
expiresAt: bigint;
caveats: Uint8Array[];
sig: Uint8Array;
}
/** Build a ZAP-encoded Capability message from `in` and return the bytes. */
export function newCapability(in_: CapabilityInput): Uint8Array {
const b = new Builder(256);
const ob = b.startObject(capabilitySize);
ob.setU32(capabilityOff.Kind, in_.kind);
ob.setBytesFixed(capabilityOff.Target, in_.target);
ob.setBytesFixed(capabilityOff.Holder, in_.holder);
ob.setBytesFixed(capabilityOff.Issuer, in_.issuer);
ob.setU64(capabilityOff.Permissions, in_.permissions);
ob.setBytesFixed(capabilityOff.Parent, in_.parent);
ob.setU64(capabilityOff.IssuedAt, in_.issuedAt);
ob.setU64(capabilityOff.ExpiresAt, in_.expiresAt);
const caveatsLB = b.startList();
for (const elem of in_.caveats) caveatsLB.addObjectBytes(elem);
ob.setList(capabilityOff.Caveats, caveatsLB.finishOffset(), in_.caveats.length);
ob.setBytesFixed(capabilityOff.Sig, in_.sig);
ob.finishAsRoot();
return b.finish();
}
const caveatOff = {
Kind: 0,
Value: 4,
} as const;
const caveatSize = 12;
/** Zero-copy view into a ZAP-encoded Caveat message. */
export class Caveat extends StructView {
/** Parse `b` and return a typed view. Throws on a wire-level check failure (magic, version, size). */
static wrap(b: Uint8Array): Caveat {
const root = Message.parse(b).root();
return new Caveat(root.data, root.offset);
}
get kind(): number { return this.u32(caveatOff.Kind); }
get value(): Uint8Array { return this.bytes(caveatOff.Value); }
}
/** Field values for newCaveat. */
export interface CaveatInput {
kind: number;
value: Uint8Array;
}
/** Build a ZAP-encoded Caveat message from `in` and return the bytes. */
export function newCaveat(in_: CaveatInput): Uint8Array {
const b = new Builder(256);
const ob = b.startObject(caveatSize);
ob.setU32(caveatOff.Kind, in_.kind);
ob.setBytes(caveatOff.Value, in_.value);
ob.finishAsRoot();
return b.finish();
}
const revocationOff = {
CapID: 0,
RevokedAt: 32,
RevokerSig: 40,
} as const;
const revocationSize = 3448;
/** Zero-copy view into a ZAP-encoded Revocation message. */
export class Revocation extends StructView {
/** Parse `b` and return a typed view. Throws on a wire-level check failure (magic, version, size). */
static wrap(b: Uint8Array): Revocation {
const root = Message.parse(b).root();
return new Revocation(root.data, root.offset);
}
get capID(): Uint8Array { return this.bytesFixed(revocationOff.CapID, 32); }
get revokedAt(): bigint { return this.u64(revocationOff.RevokedAt); }
get revokerSig(): Uint8Array { return this.bytesFixed(revocationOff.RevokerSig, 3408); }
}
/** Field values for newRevocation. */
export interface RevocationInput {
capID: Uint8Array;
revokedAt: bigint;
revokerSig: Uint8Array;
}
/** Build a ZAP-encoded Revocation message from `in` and return the bytes. */
export function newRevocation(in_: RevocationInput): Uint8Array {
const b = new Builder(256);
const ob = b.startObject(revocationSize);
ob.setBytesFixed(revocationOff.CapID, in_.capID);
ob.setU64(revocationOff.RevokedAt, in_.revokedAt);
ob.setBytesFixed(revocationOff.RevokerSig, in_.revokerSig);
ob.finishAsRoot();
return b.finish();
}
const capProofOff = {
Leaf: 0,
Chain: 4,
} as const;
const capProofSize = 12;
/** Zero-copy view into a ZAP-encoded CapProof message. */
export class CapProof extends StructView {
/** Parse `b` and return a typed view. Throws on a wire-level check failure (magic, version, size). */
static wrap(b: Uint8Array): CapProof {
const root = Message.parse(b).root();
return new CapProof(root.data, root.offset);
}
get leaf(): Capability {
const o = this.object(capProofOff.Leaf);
return new Capability(o.data, o.offset);
}
get chain(): ListView { return this.list(capProofOff.Chain); }
}
/** Field values for newCapProof. */
export interface CapProofInput {
leaf: Uint8Array;
chain: Uint8Array[];
}
/** Build a ZAP-encoded CapProof message from `in` and return the bytes. */
export function newCapProof(in_: CapProofInput): Uint8Array {
const b = new Builder(256);
const ob = b.startObject(capProofSize);
if (in_.leaf.length > 0) {
const nested = b.startObject(in_.leaf.length);
nested.setBytesFixed(0, in_.leaf);
ob.setObject(capProofOff.Leaf, nested.finish());
}
const chainLB = b.startList();
for (const elem of in_.chain) chainLB.addObjectBytes(elem);
ob.setList(capProofOff.Chain, chainLB.finishOffset(), in_.chain.length);
ob.finishAsRoot();
return b.finish();
}