In order to facilitate the practical use of Skey Networktools, it is possible to generate SubAccounts with which actions can be performed on devices. For a given sub-account with its own seed we can sign a transaction which carries out some action on the device.
Schema of creating new SubAccount for payment Card in blockchain
This will allow the card owner and TSS to perform actions on the account.
4. Add entries into data storage of CARD account with public keys of Main User account and TSS account. These accounts will be able to perform actions on the Card account.
You can do it via data transaction, example:
import { getInstance } from "skey-lib";
import * as Transactions from "@waves/waves-transactions";
import * as Crypto from "@waves/ts-lib-crypto";
const chainId = "M"; // "A" for testnet
const instance = getInstance({
nodeUrl: "https://master.nodes.skey.network", // https://master.testnet.node.smartkeyplatform.io for testnet.
chainId,
});
const tssPublicKey = "..."; // public key of TSS account authorized to open
const publicKey = "4s1NSh7cwCEjfcqT33QfpR6M5YjoyBMGiC8YjFqXiwgs"; // request payload in 1)
const account = instance.createAccount(); // see 2)
// Faucet the account before executing code below - see 3)
const dataTx = Transactions.data(
{
data: [
{
key: "owner", // owner of subaccount
type: "string",
value: publicKey, // base58 string
},
{
key: "authorised", // account authorized to invoke 'deviceAction'
type: "string",
value: tssPublicKey, // base58 string
},
{
key: "card", // account generated for card
type: "string",
value: account.publicKey, // base58 string
},
{
key: "status",
type: "string",
value: "active",
},
{
key: "type",
type: "string",
value: "subAccount",
},
{
key: "subType",
type: "string",
value: "paymentCard",
},
{
key: "version",
type: "string",
value: "1",
},
{
key: "details",
type: "string",
value: JSON.stringify({
truncatedPan: "123456xxxxxx5432",
provider: "mastercard",
}),
},
],
fee: 10 ** 5,
chainId,
},
account.seed
);
instance
.broadcast(dataTx)
.then(() => {
console.log("data set successfully!");
})
.catch((e) => {
console.error("something went wrong: ", e);
});
5. Set script to CARD account. How to do it:
// after performing 5)
// This is an example - not a working script
const script = "base64:whatever";
const scriptTx = Transactions.setScript(
{
script,
chainId: "M", // "A" for testnet
fee: 10 ** 6,
},
account.seed
);
instance
.broadcast(dataTx)
.then(() => {
console.log("script set successfully!");
})
.catch((e) => {
console.error("something went wrong: ", e);
});