Skip to content

Commit

Permalink
Merge pull request #150 from o1-labs/fix/struct-to-fields
Browse files Browse the repository at this point in the history
Fix Struct.toFields()
  • Loading branch information
mitschabaude authored Sep 19, 2023
2 parents 1b07374 + ffaaf33 commit 03e1b6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/provable-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { createProvable, createHashInput, ProvableConstructor };

type ProvableConstructor<Field> = <A>(
typeObj: A,
options?: { customObjectKeys?: string[]; isPure?: boolean }
options?: { isPure?: boolean }
) => GenericProvableExtended<InferProvable<A, Field>, InferJson<A>, Field>;

function createProvable<Field>(): ProvableConstructor<Field> {
Expand All @@ -25,13 +25,13 @@ function createProvable<Field>(): ProvableConstructor<Field> {

function provable<A>(
typeObj: A,
options?: { customObjectKeys?: string[]; isPure?: boolean }
options?: { isPure?: boolean }
): ProvableExtended<InferProvable<A, Field>, InferJson<A>> {
type T = InferProvable<A, Field>;
type J = InferJson<A>;
let objectKeys =
typeof typeObj === 'object' && typeObj !== null
? options?.customObjectKeys ?? Object.keys(typeObj).sort()
? Object.keys(typeObj)
: [];
let nonCircuitPrimitives = new Set([
Number,
Expand Down
11 changes: 4 additions & 7 deletions lib/provable-snarky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ const HashInput = {

function provable<A>(
typeObj: A,
options?: { customObjectKeys?: string[]; isPure?: boolean }
options?: { isPure?: boolean }
): ProvableExtended<InferProvable<A>, InferJson<A>> {
type T = InferProvable<A>;
type J = InferJson<A>;
let objectKeys =
typeof typeObj === 'object' && typeObj !== null
? options?.customObjectKeys ?? Object.keys(typeObj).sort()
: [];
typeof typeObj === 'object' && typeObj !== null ? Object.keys(typeObj) : [];
let nonCircuitPrimitives = new Set([
Number,
String,
Expand Down Expand Up @@ -222,11 +220,10 @@ function provable<A>(
}

function provablePure<A>(
typeObj: A,
options: { customObjectKeys?: string[] } = {}
typeObj: A
): ProvablePure<InferProvable<A>> &
ProvableExtension<InferProvable<A>, InferJson<A>> {
return provable(typeObj, { ...options, isPure: true }) as any;
return provable(typeObj, { isPure: true }) as any;
}

// some type inference helpers
Expand Down
15 changes: 5 additions & 10 deletions mina-transaction/derived-leaves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,11 @@ function derivedLeafTypes<Field, Bool>({
};

const AuthRequired = {
...provable(
{ constant: Bool, signatureNecessary: Bool, signatureSufficient: Bool },
{
customObjectKeys: [
'constant',
'signatureNecessary',
'signatureSufficient',
],
}
),
...provable({
constant: Bool,
signatureNecessary: Bool,
signatureSufficient: Bool,
}),
emptyValue(): AuthRequired {
return {
constant: Bool(true),
Expand Down

0 comments on commit 03e1b6e

Please sign in to comment.