pulsar-contracts
Version:
40 lines • 1.54 kB
JavaScript
import { Field, MerkleList, Poseidon } from 'o1js';
import { PulsarAction } from './PulsarAction.js';
export { merkleActionsAdd, emptyActionListHash, actionListAdd, ActionList, MerkleActions, };
const encoder = new TextEncoder();
function bytes(s) {
return [...encoder.encode(s)];
}
function prefixToField(prefix) {
const size = Field.sizeInBytes ?? 32;
if (prefix.length >= size)
throw Error('prefix too long');
return Field.fromBytes(bytes(prefix).concat(Array(size - prefix.length).fill(0)));
}
function initState() {
return [Field(0), Field(0), Field(0)];
}
function salt(prefix) {
return Poseidon.update(initState(), [prefixToField(prefix)]);
}
function emptyHashWithPrefix(prefix) {
return salt(prefix)[0];
}
const merkleActionsAdd = (hash, actionsListHash) => {
return Poseidon.hashWithPrefix('MinaZkappSeqEvents**', [
hash,
actionsListHash,
]);
};
const emptyActionListHash = emptyHashWithPrefix('MinaZkappActionsEmpty');
const actionListAdd = (hash, action) => {
return Poseidon.hashWithPrefix('MinaZkappSeqEvents**', [
hash,
Poseidon.hashWithPrefix('MinaZkappEvent******', PulsarAction.toFields(action)),
]);
};
class ActionList extends MerkleList.create(PulsarAction, actionListAdd, emptyHashWithPrefix('MinaZkappActionsEmpty')) {
}
class MerkleActions extends MerkleList.create(ActionList.provable, (hash, x) => merkleActionsAdd(hash, x.hash), emptyHashWithPrefix('MinaZkappActionStateEmptyElt')) {
}
//# sourceMappingURL=actionHelpers.js.map