Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function sendARK({ amount, receiver, wif, fee = 0 }) {
if (!Identities.Address.validate(receiver)) {
throw new Error(`Invalid script hash: "${receiver}"`);
}
if (amount <= 0) {
throw new Error(`Invalid amount: "${amount}"`);
}
console.log('Amount ', amount);
console.log('receiver ', receiver);
console.log('wif ', wif);
const send = async () => {
try {
// https://github.com/ArkEcosystem/core/blob/1cbc2a05a596340d4f261d162b8f426815908db6/packages/crypto/src/transactions/builders/transactions/transaction.ts
const transaction = Transactions.BuilderFactory.transfer() // specify 'transfer' as our AIP11 transaction type
.network(23)
.version(2)
protected async sendTransaction(transactions: any[]): Promise> {
if (!Array.isArray(transactions)) {
transactions = [transactions];
}
for (const transaction of transactions) {
let recipientId = transaction.recipientId;
if (!recipientId) {
recipientId = Identities.Address.fromPublicKey(transaction.senderPublicKey, this.network);
}
logger.info(
`[T] ${transaction.id} (${recipientId} / ${this.fromSatoshi(transaction.amount)} / ${this.fromSatoshi(
transaction.fee,
)})`,
);
}
return this.api.post("transactions", { transactions });
}
beforeEach(() => {
transactionObject = Transactions.BuilderFactory
.transfer()
.amount(1)
.fee(1)
.recipientId(recipientAddress)
spyDispatch = jest.spyOn(vmMock.$store, 'dispatch')
spyTranslate = jest.spyOn(vmMock, '$t')
wallet = {
address: Identities.Address.fromPassphrase(senderPassphrase),
publicKey: senderPublicKey,
ledgerIndex: 0
}
})
public applyBlock(block: Interfaces.IBlock): void {
const generatorPublicKey: string = block.data.generatorPublicKey;
let delegate: State.IWallet;
if (!this.has(generatorPublicKey)) {
const generator: string = Identities.Address.fromPublicKey(generatorPublicKey);
if (block.data.height === 1) {
delegate = new Wallet(generator);
delegate.publicKey = generatorPublicKey;
this.reindex(delegate);
} else {
app.forceExit(`Failed to lookup generator '${generatorPublicKey}' of block '${block.data.id}'.`);
}
} else {
delegate = this.findByPublicKey(block.data.generatorPublicKey);
}
const appliedTransactions: Interfaces.ITransaction[] = [];
try {
private createWallet(pubKeyHash: number) {
const passphrase = generateMnemonic();
const keys = Identities.Keys.fromPassphrase(passphrase);
return {
address: Identities.Address.fromPublicKey(keys.publicKey, pubKeyHash),
passphrase,
keys,
username: undefined,
};
}
isValid (value) {
if (!this.isRequired && value.replace(/\s+/, '') === '') {
return true
}
try {
Identities.Address.fromPublicKey(value)
return true
} catch (error) {
//
}
return false
}
}
async method(params: { passphrase: string }) {
const { publicKey }: Interfaces.IKeyPair = Identities.Keys.fromPassphrase(params.passphrase);
return {
publicKey,
address: Identities.Address.fromPublicKey(publicKey),
};
},
schema: {
public deleteWallet(publicKey) {
this.forgetByPublicKey(publicKey);
this.forgetByAddress(Identities.Address.fromPublicKey(publicKey));
}
public static getAddressFromPublicKey(
publicKey: string,
networkVersion: number
): string {
return Identities.Address.fromPublicKey(publicKey, networkVersion);
}
async method(params: { userId: string; bip38: string }) {
const encryptedWIF: string = await database.get(
Crypto.HashAlgorithms.sha256(Buffer.from(params.userId)).toString("hex"),
);
if (!encryptedWIF) {
return Boom.notFound(`User ${params.userId} could not be found.`);
}
const { keys, wif }: IWallet = decryptWIF(encryptedWIF, params.userId, params.bip38);
return {
publicKey: keys.publicKey,
address: Identities.Address.fromPublicKey(keys.publicKey),
wif,
};
},
schema: {