Skip to content

Commit

Permalink
Merge branch 'main' into feature/flexible-subschema
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Nov 4, 2024
2 parents 2d01f9e + 34f1114 commit f9efb97
Show file tree
Hide file tree
Showing 15 changed files with 938 additions and 81 deletions.
4 changes: 2 additions & 2 deletions examples/unique-hash.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ const spec = Spec(
// we expose a unique hash of the credential data, to be used as nullifier
// note: since the credential contains a 16 byte = 128 bit random ID, it has enough
// entropy such that exposing this hash will not reveal the credential data
let ouputClaim = Operation.record({
let outputClaim = Operation.record({
nullifier: Operation.hash(credential, appId),
});

return { assert, ouputClaim };
return { assert, outputClaim };
}
);

Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"@types/node": "^22.5.5",
"prettier": "^2.3.2",
"typescript": "^5.6.3",
"vite": "^4.3.9"
"vite": "^4.3.9",
"zod": "^3.23.8"
},
"peerDependencies": {
"o1js": "^2.0.0"
Expand Down
5 changes: 4 additions & 1 deletion src/credential-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ const Credential = {
toJSON(credential: StoredCredential) {
let json = {
version: credential.version,
witness: serializeNestedProvableValue(credential.witness),
witness:
credential.witness === undefined
? { type: 'unsigned' }
: serializeNestedProvableValue(credential.witness),
metadata: credential.metadata,
credential: serializeNestedProvableValue(credential.credential),
};
Expand Down
2 changes: 1 addition & 1 deletion src/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function convertSpecFromSerializable(parsedSpec: any): Spec {
inputs,
logic: {
assert: deserializeNode(inputs, parsedSpec.logic.assert),
ouputClaim: deserializeNode(inputs, parsedSpec.logic.data),
outputClaim: deserializeNode(inputs, parsedSpec.logic.outputClaim),
},
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/program-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Spec<Output, Inputs extends Record<string, Input>>(
[K in keyof Inputs]: Node<GetData<Inputs[K]>>;
}) => {
assert?: Node<Bool>;
ouputClaim: Node<Output>;
outputClaim: Node<Output>;
}
): Spec<Output, Inputs>;

Expand Down Expand Up @@ -115,10 +115,10 @@ function Spec<Output, Inputs extends Record<string, Input>>(
}
let logic = spec(inputNodes);
let assertNode = logic.assert ?? Node.constant(Bool(true));
let ouputClaim: Node<Output> =
logic.ouputClaim ?? (Node.constant(undefined) as any);
let outputClaim: Node<Output> =
logic.outputClaim ?? (Node.constant(undefined) as any);

return { inputs, logic: { assert: assertNode, ouputClaim } };
return { inputs, logic: { assert: assertNode, outputClaim } };
}

const Operation = {
Expand Down Expand Up @@ -193,7 +193,7 @@ type Node<Data = any> =

type OutputNode<Data = any> = {
assert?: Node<Bool>;
ouputClaim?: Node<Data>;
outputClaim?: Node<Data>;
};

const Node = {
Expand Down Expand Up @@ -636,7 +636,7 @@ function privateInputTypes({ inputs }: Spec): NestedProvableFor<{

function publicOutputType(spec: Spec): ProvablePure<any> {
let root = dataInputTypes(spec);
let outputTypeNested = Node.evalType(root, spec.logic.ouputClaim);
let outputTypeNested = Node.evalType(root, spec.logic.outputClaim);
let outputType = NestedProvable.get(outputTypeNested);
assertPure(outputType);
return outputType;
Expand Down
2 changes: 1 addition & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function createProgram<S extends Spec>(
credentialOutputs
);
let assertion = Node.eval(root, spec.logic.assert);
let outputClaim = Node.eval(root, spec.logic.ouputClaim);
let outputClaim = Node.eval(root, spec.logic.outputClaim);
assertion.assertTrue('Program assertion failed!');
return { publicOutput: outputClaim };
},
Expand Down
2 changes: 1 addition & 1 deletion src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function convertSpecToSerializable(spec: Spec): Record<string, any> {
inputs: serializeInputs(spec.inputs),
logic: {
assert: serializeNode(spec.logic.assert),
data: serializeNode(spec.logic.ouputClaim),
outputClaim: serializeNode(spec.logic.outputClaim),
},
};
}
Expand Down
Loading

0 comments on commit f9efb97

Please sign in to comment.