0.3.7 • Published 2 years ago
mns-zkapp v0.3.7
Mina zkApp: Mns Zkapp
How to build
npm run build
How to run tests
npm run test
npm run testw # watch mode
RecordJSON DESC
export interface RecordJSON {
/**
* Record Key. All characters must be lowercase.
*
* @type {string}
* @memberof RecordJSON
*/
key: string;
/**
* Record Kind. Such as: address, profile
*
* @type {string}
* @memberof RecordJSON
*/
kind: string;
/**
* The record label field allows the user to freely input a string with a length of no more than 31 characters
*
* @type {string}
* @memberof RecordJSON
*/
label: string;
/**
* Time To Live. Default value: 300
*
* @type {number}
* @memberof RecordJSON
*/
ttl: number;
/**
* Record Value.
*
* @type {string}
* @memberof RecordJSON
*/
value: string;
}
The record kind field can take the following values:
export enum RecordKind {
Address = 'address',
Profile = 'profile',
Custom = 'custom',
}
How to generate a key:
let qa = MnsFactory.getQAInstance(
'https://proxy.berkeley.minaexplorer.com/graphql',
zkappAddress,
100_000_000
);
qa.createAddressKey('mina'); // return a key: "address.mina"
qa.createProfileKey('twitter'); // return a key: "profile.twitter"
qa.createCustomKey('mykey'); // return a key: custom.mykey
At present, the agreed keys are:
address.mina, address.btc, address.eth profile.twitter, profile.facebook, profile.telegram, profile.discord
How to use
import {
MnsFactory,
Account,
AccountJSON,
stringToField,
Permit,
PERMIT_UPDATE_REGISTER_FEE
} from 'mns-zkapp';
import {
compactMerkleProofToJson,
MemoryStore,
SparseMerkleTree,
} from 'snarky-smt';
import {
fetchAccount,
Field,
isReady,
PrivateKey,
shutdown,
UInt64,
} from 'snarkyjs';
await isReady;
let zkappKey = PrivateKey.fromBase58(TEST_ZKAPP_KEY);
let zkappAddress = zkappKey.toPublicKey();
let qa = MnsFactory.getQAInstance(
'https://proxy.berkeley.minaexplorer.com/graphql',
zkappAddress,
100_000_000
);
// to use this test, change this private key to an account which has enough MINA to pay fees
let feePayerKey = PrivateKey.fromBase58(TEST_FEEPAYER_KEY);
let feePayerPublicKey = feePayerKey.toPublicKey();
let response = await fetchAccount(feePayerPublicKey);
if (response.error) throw Error(response.error.statusText);
let { nonce, balance } = response.account;
console.log(
`Using fee payer account with nonce ${nonce}, balance ${balance}`
);
// check if the zkapp is already deployed, based on whether the account exists and its first zkapp state is != 0
let x = await qa.getMnsRegisterFee();
let isDeployed = x?.equals(UInt64.fromNumber(0)).not().toBoolean() ?? false;
// if the zkapp is not deployed yet, create a deploy transaction
if (!isDeployed) {
console.log(`Deploying zkapp for public key ${zkappAddress.toBase58()}.`);
await qa.deploy(zkappKey, feePayerKey, feePayerPublicKey);
}
while (!isDeployed) {
console.log('just wait 1 min...');
await sleep(1 * 60 * 1000);
let x = await qa.getMnsRegisterFee();
isDeployed = x?.equals(UInt64.fromNumber(0)).not().toBoolean() ?? false;
}
// if the zkapp is not deployed yet, create an update transaction
if (isDeployed) {
let x = qa.getMnsZkapp().registerFee.get();
console.log(`Found deployed zkapp, registerFee: ${x} .`);
const newRegisterFee = 20_000_000;
const callerNonce = await qa.getAccountNonce(feePayerKey.toPublicKey());
const updateFeePermit = new Permit(PERMIT_UPDATE_REGISTER_FEE, callerNonce);
const ownerSignature = qa.createMnsOwnerSignature(
feePayerKey,
updateFeePermit
);
await qa.updateRegisterFee(
feePayerKey,
newRegisterFee,
updateFeePermit,
ownerSignature
);
let tree = await SparseMerkleTree.buildNewTree<Field, Account>(
new MemoryStore<Account>()
);
let cproof = await tree.proveCompact(stringToField('ok'));
let proof = compactMerkleProofToJson(cproof);
let account = AccountJSON.default('ok', feePayerPublicKey.toBase58());
await qa.registerAccount(feePayerKey, feePayerKey, account, proof);
}
License
0.3.0
2 years ago
0.3.6
2 years ago
0.3.5
2 years ago
0.3.7
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.4
2 years ago
0.3.3
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.9
2 years ago
0.1.8
2 years ago
0.1.7
2 years ago
0.1.6
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago