TON contracts for Agorata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.2 KiB

2 years ago
const main = require('../contracts/main');
const subcommand = require('subcommand');
const {Address} = require("ton");
const {keyPairFromSeed, getSecureRandomBytes, keyPairFromSecretKey} = require("ton-crypto");
const {Base64} = require('@tonconnect/protocol');
const BN = require("bn.js");
2 years ago
const argv = process.argv.slice(2);
let commands = [
{
name: 'buy-message',
2 years ago
options: [ // cliclopts options
// {
// name: 'loud',
// boolean: true,
// default: false,
// abbr: 'v',
// help: 'print out all output loudly'
// }
{
name: 'domain'
},
{
name: 'collection'
},
{
name: 'buyer',
help: 'Buyer\'s address'
},
{
name: 'key',
help: 'Secret key, hex-encoded'
}
],
command: function message(args) {
let collection = Address.parse(args._[1]);
if (args._[2] !== '') {
let buyer = Address.parse(args._[2]);
let key = Buffer.from(args._[3], 'hex');
let signature = main.signBuy(args._[0], collection, buyer, key);
let msg = main.createItem({domain: args._[0], signature})
console.log(Base64.encode(msg.toBoc()) + ' ' + collection.toString());
} else {
let msg = main.createItem({domain: args._[0], signature: '0'})
console.log(Base64.encode(msg.toBoc()) + ' ' + collection.toString());
}
2 years ago
}
},
{
name: 'keygen',
command: async function keygen(args) {
let keypair = keyPairFromSeed(await getSecureRandomBytes(32));
console.log(keypair.secretKey.toString('hex'));
}
},
{
name: 'getpub', // get public key as BN from b64 secret key
options: [
{
name: 'key',
help: 'Secret key, hex-encoded'
}
],
command: function getpub(args) {
let keypair = keyPairFromSecretKey(Buffer.from(args._[0], 'base64'));
console.log(new BN(keypair.publicKey))
}
},
{
name: 'content-message',
options: [
{
name: 'domain',
help: 'domain name to set content for (test for test.example.ton)'
},
{
name: 'zone',
help: 'zone name to set content for (example.ton for test.example.ton)'
},
{
name: 'address',
help: 'address of the collection contract'
},
{
name: 'workchain',
help: '0 for mainnet, 1 for testnet'
}
],
command: function set_content(args) {
let msg = main.setContent({domain: args._[0], zone: args._[1]});
let addr = main.getItemAddr(Address.parse(args._[2]), args._[0], args._[3] === '1' ? -1 : 0);
console.log(Base64.encode(msg.toBoc()) + ' ' + addr.toString());
}
2 years ago
}
]
let match = subcommand(commands);
let opts = match(argv);