This file contains hidden or 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
| function determineSignByte(publicKey: string): string { | |
| if(publicKey.length !== 64) { | |
| throw new Error("required `public key` of length 32"); | |
| } | |
| const xCoordinate = BigInt("0x" + publicKey); | |
| return xCoordinate % BigInt(2) === BigInt(0) ? "02" : "03"; | |
| } | |
This file contains hidden or 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
| import 'dart:typed_data'; | |
| import 'package:pointycastle/digests/keccak.dart'; | |
| import 'package:pointycastle/ecc/api.dart'; | |
| import 'package:pointycastle/ecc/curves/secp256k1.dart'; | |
| BigInt decodeToBigInt(List<int> magnitude) { | |
| BigInt result; | |
| if (magnitude.length == 1) { | |
| result = BigInt.from(magnitude[0]); |
This file contains hidden or 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
| import 'dart:typed_data'; | |
| import 'package:convert/convert.dart'; | |
| import 'package:pointycastle/digests/keccak.dart'; | |
| /// This gist/function helps in convertion or verification of the ethereum address | |
| /// Why checksum is explained here: https://coincodex.com/article/2078/ethereum-address-checksum-explained/ | |
| String toChecksum(String ethAddress) { | |
| // Checking for 0x prefix | |
| String addrWithoutChecksum = ethAddress.substring(0, 2) == '0x' | |
| ? ethAddress.substring(2, ethAddress.length) |
This file contains hidden or 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
| var crypto = require("crypto"); | |
| var path = require("path"); | |
| var fs = require("fs"); | |
| var encryptStringWithRsaPublicKey = function(toEncrypt, publicKeyInPemPath) { | |
| var absolutePath = path.resolve(publicKeyInPemPath); | |
| var publicKey = fs.readFileSync(absolutePath, "utf8"); | |
| var buffer = Buffer.from(JSON.stringify(toEncrypt)); | |
| var encrypted = crypto.publicEncrypt(publicKey, buffer); | |
| return encrypted.toString("base64"); |