const nearAPI = require('near-api-js')
const { Base64 } = require('js-base64')
const authToken = async (accountId, signer, networkId) => {
const arr = new Array(accountId)
for (var i = 0; i < accountId.length; i++) {
arr[i] = accountId.charCodeAt(i)
const msgBuf = new Uint8Array(arr)
const signedMsg = await signer.signMessage(
const pubKey = Buffer.from(signedMsg.publicKey.data).toString('hex')
const signature = Buffer.from(signedMsg.signature).toString('hex')
const payload = [accountId, pubKey, signature]
return Base64.encode(payload.join('&'))
const main = async () => {
nodeUrl: 'https://rpc.testnet.near.org',
walletUrl: 'https://wallet.testnet.near.org',
appName: 'Paras Testnet',
contractName: `paras-token-v2.testnet`
// Login and init contract
const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(
`${process.env.HOME}/.near-credentials/`
const signer = new nearAPI.InMemorySigner(keyStore)
const connection = await nearAPI.connect({
const account_id = 'orang.testnet'
const account = await connection.account(account_id)
const authorizationHeader = await authToken(account_id, signer, config.networkId)
console.log(`Authorization Header : ${authorizationHeader}`)