Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov committed Jul 9, 2024
1 parent 1e29577 commit f9cd5d9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/from-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type GenericTypeMap<
PublicKey,
AuthRequired,
TokenId
// MayUseToken
> = {
Field: Field;
Bool: Bool;
Expand All @@ -30,6 +31,7 @@ type GenericTypeMap<
PublicKey: PublicKey;
AuthRequired: AuthRequired;
TokenId: TokenId;
// MayUseToken: MayUseToken;
};
type AnyTypeMap = GenericTypeMap<any, any, any, any, any, any, any, any>;

Expand Down
47 changes: 47 additions & 0 deletions mina-transaction/derived-leaves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ function derivedLeafTypes<Field, Bool>({
}),
Bool
),
MayUseToken: createMayUseToken(
provable({
parentsOwnToken: Bool,
inheritFromParent: Bool,
}),
Bool
),
ZkappUri: createZkappUri(Field, HashHelpers, packToFields),
};
}
Expand Down Expand Up @@ -95,6 +102,13 @@ function derivedLeafTypesSignable<Field, Bool>({
}),
Bool
),
MayUseToken: createMayUseToken(
signable({
parentsOwnToken: Bool,
inheritFromParent: Bool,
}),
Bool
),
ZkappUri: createZkappUri(Field, HashHelpers, packToFields),
};
}
Expand Down Expand Up @@ -234,3 +248,36 @@ function createZkappUri<Field>(
Field,
});
}

type MayUseToken<Bool> = {
parentsOwnToken: Bool;
inheritFromParent: Bool;
};

function createMayUseToken<
Field,
Bool,
Base extends GenericSignable<MayUseToken<Bool>, MayUseToken<boolean>, Field>
>(base: Base, Bool: GenericSignableBool<Field, Bool>) {
return {
...(base as Omit<Base, 'toJSON' | 'fromJSON'>),
empty(): MayUseToken<Bool> {
return {
parentsOwnToken: Bool(false),
inheritFromParent: Bool(false),
};
},
toJSON(x: MayUseToken<Bool>): Json.MayUseToken {
return {
parentsOwnToken: Bool.toJSON(x.parentsOwnToken),
inheritFromParent: Bool.toJSON(x.inheritFromParent),
};
},
fromJSON(json: Json.MayUseToken): MayUseToken<Bool> {
return {
parentsOwnToken: Bool.fromJSON(json.parentsOwnToken),
inheritFromParent: Bool.fromJSON(json.inheritFromParent),
};
},
};
}
18 changes: 16 additions & 2 deletions mina-transaction/transaction-leaves-bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ import {
} from '../../mina-signer/src/poseidon-bigint.js';
import { mocks, protocolVersions } from '../crypto/constants.js';

export { PublicKey, Field, Bool, AuthRequired, UInt64, UInt32, Sign, TokenId };
export {
PublicKey,
Field,
Bool,
AuthRequired,
UInt64,
UInt32,
Sign,
TokenId,
MayUseToken,
};

export {
Events,
Expand All @@ -34,12 +44,16 @@ type AuthRequired = {
signatureNecessary: Bool;
signatureSufficient: Bool;
};
type MayUseToken = {
parentsOwnToken: Bool;
inheritFromParent: Bool;
};
type TokenId = Field;
type StateHash = Field;
type TokenSymbol = { symbol: string; field: Field };
type ZkappUri = { data: string; hash: Field };

const { TokenId, StateHash, TokenSymbol, AuthRequired, ZkappUri } =
const { TokenId, StateHash, TokenSymbol, AuthRequired, ZkappUri, MayUseToken } =
derivedLeafTypesSignable({ Field, Bool, HashHelpers, packToFields });

type Event = Field[];
Expand Down
16 changes: 15 additions & 1 deletion mina-transaction/transaction-leaves-json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export { PublicKey, Field, Bool, AuthRequired, UInt64, UInt32, Sign, TokenId };
export {
PublicKey,
Field,
Bool,
AuthRequired,
UInt64,
UInt32,
Sign,
TokenId,
MayUseToken,
};

type Field = string;
type Bool = boolean;
Expand All @@ -8,3 +18,7 @@ type PublicKey = string;
type Sign = 'Positive' | 'Negative';
type AuthRequired = 'Signature' | 'Proof' | 'Either' | 'None' | 'Impossible';
type TokenId = Field;
type MayUseToken = {
parentsOwnToken: Bool;
inheritFromParent: Bool;
};
18 changes: 16 additions & 2 deletions mina-transaction/transaction-leaves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ import {
import { provable } from '../../lib/provable/types/provable-derivers.js';
import { mocks, protocolVersions } from '../crypto/constants.js';

export { PublicKey, Field, Bool, AuthRequired, UInt64, UInt32, Sign, TokenId };
export {
PublicKey,
Field,
Bool,
AuthRequired,
UInt64,
UInt32,
Sign,
TokenId,
MayUseToken,
};

export {
Events,
Expand All @@ -31,12 +41,16 @@ type AuthRequired = {
signatureNecessary: Bool;
signatureSufficient: Bool;
};
type MayUseToken = {
parentsOwnToken: Bool;
inheritFromParent: Bool;
};
type TokenId = Field;
type StateHash = Field;
type TokenSymbol = { symbol: string; field: Field };
type ZkappUri = { data: string; hash: Field };

const { TokenId, StateHash, TokenSymbol, AuthRequired, ZkappUri } =
const { TokenId, StateHash, TokenSymbol, AuthRequired, ZkappUri, MayUseToken } =
derivedLeafTypes({ Field, Bool, HashHelpers, packToFields });

type Event = Field[];
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-o1js-node-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ KIMCHI_BINDINGS="$MINA_PATH/src/lib/crypto/kimchi_bindings"

[ -d node_modules ] || npm i

export DUNE_USE_DEFAULT_LINKER="y"
# export DUNE_USE_DEFAULT_LINKER="y"

if [ -f "$BUILD_PATH/o1js_node.bc.js" ]; then
echo "found o1js_node.bc.js"
Expand Down

0 comments on commit f9cd5d9

Please sign in to comment.