-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53c2d27
commit c230e9b
Showing
8 changed files
with
98 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
functionCall, | ||
getPlaintextFilesystemSigner, | ||
getTestnetRpcProvider, | ||
view, | ||
} from '@near-js/client'; | ||
import { formatNearAmount, parseNearAmount } from '@near-js/utils'; | ||
import chalk from 'chalk'; | ||
import { join } from 'node:path'; | ||
import { homedir } from 'node:os'; | ||
|
||
// On mainnet it's wrap.near, by the way | ||
const WRAP_NEAR_CONTRACT_ID = "wrap.testnet"; | ||
|
||
export default async function unwrapNear(accountId: string, unwrapAmount: bigint, wrapContract = WRAP_NEAR_CONTRACT_ID) { | ||
if (!accountId || !unwrapAmount) { | ||
console.log(chalk`{red pnpm unwrapNear -- ACCOUNT_ID UNWRAP_AMOUNT [WRAP_CONTRACT]}`); | ||
return; | ||
} | ||
|
||
const credentialsPath = join(homedir(), '.near-credentials'); | ||
|
||
// initialize testnet RPC provider | ||
const rpcProvider = getTestnetRpcProvider(); | ||
// initialize the transaction signer using a pre-existing key for `accountId` | ||
const { signer } = getPlaintextFilesystemSigner({ account: accountId, network: 'testnet', filepath: credentialsPath }); | ||
|
||
const getStorageBalance = () => view({ | ||
account: wrapContract, | ||
method: 'storage_balance_of', | ||
args: { account_id: accountId }, | ||
deps: { rpcProvider }, | ||
}) as Promise<{ available: string, total: string }>; | ||
|
||
const { total: preTotal, available: preAvailable } = (await getStorageBalance()) || {}; | ||
|
||
await functionCall({ | ||
sender: accountId, | ||
receiver: wrapContract, | ||
method: 'near_withdraw', | ||
args: { amount: parseNearAmount(unwrapAmount.toString()) }, | ||
deposit: 1n, | ||
deps: { | ||
rpcProvider, | ||
signer, | ||
}, | ||
}); | ||
|
||
const { total: postTotal, available: postAvailable } = await getStorageBalance(); | ||
console.log(chalk`{white ------------------------------------------------------------------------ }`); | ||
console.log(chalk`{bold.green RESULTS} {white Unwrapped ${unwrapAmount}yN with ${wrapContract}}`); | ||
console.log(chalk`{white ------------------------------------------------------------------------ }`); | ||
console.log(chalk`{bold.white Starting Balance} {white |} {bold.yellow ${formatNearAmount(preAvailable)} / ${formatNearAmount(preTotal)}}`); | ||
console.log(chalk`{bold.white Ending Balance} {white |} {bold.yellow ${formatNearAmount(postAvailable)} / ${formatNearAmount(postTotal)}}`); | ||
console.log(chalk`{white ------------------------------------------------------------------------ }`); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getTestnetRpcProvider } from '@near-js/client'; | ||
import { KeyType, PublicKey } from '@near-js/crypto'; | ||
import { baseDecode } from '@near-js/utils'; | ||
|
||
const ACCOUNT_ID = 'gornt.testnet'; | ||
const TX_HASH = '4tMHzHU5p9dXc4WqopReNZ2TMJxZyu913zK4Fn9nMRoB'; | ||
|
||
export default async function verifySignature(accountId: string = ACCOUNT_ID, transactionHash: string = TX_HASH) { | ||
// initialize testnet RPC provider | ||
const rpcProvider = getTestnetRpcProvider(); | ||
|
||
const { transaction: { public_key, signature } } = await rpcProvider.getTransaction({ transactionHash, account: accountId }); | ||
|
||
const hashBytes = baseDecode(transactionHash); | ||
const publicKeyBytes = baseDecode(public_key.slice('ed25519:'.length)); | ||
const signatureBytes = baseDecode(signature.slice('ed25519:'.length)); | ||
const publicKey = new PublicKey({ keyType: KeyType.ED25519, data: publicKeyBytes }); | ||
|
||
const isVerified = publicKey.verify(hashBytes, signatureBytes); | ||
|
||
console.log(isVerified); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.