/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/**
* @ignore Don't show this file in documentation.
*/ /** */
import { Keyring } from '@polkadot/api';
import { cryptoWaitReady, mnemonicGenerate, mnemonicToMiniSecret, randomAsHex, naclKeypairFromSeed, signatureVerify} from '@polkadot/util-crypto';
import {
createSignedTx,
createSigningPayload,
decode,
deriveAddress,
getRegistry,
getTxHash,
methods,
POLKADOT_SS58_FORMAT,
} from '../src';
import { rpcToNode, signWith } from './util';
import { stringToU8a, u8aToHex } from '@polkadot/util';
/**
* Entry point of the script. This script assumes a Polkadot node is running
* locally on `http://localhost:9933`.
*/
async function main(): Promise<void> {
// Wait for the promise to resolve async WASM
await cryptoWaitReady();
// Create a new keyring, and add an sr25519 type account
const keyring = new Keyring({ ss58Format: 42, type: 'sr25519' });
// Aries add TEST Start
const mnemonic = mnemonicGenerate();
console.log("memonic: ", mnemonic);
//these will be equivalent
console.log( "memonic addr: " , keyring.createFromUri(mnemonic).address);
const mnemonicMini = mnemonicToMiniSecret(mnemonic);
console.log("mnemonicMini addr: " , keyring.createFromUri(u8aToHex(mnemonicMini)).address);
const { publicKey, secretKey } = naclKeypairFromSeed(mnemonicMini);
console.log("publicKey: ", u8aToHex(publicKey), " secretKey: ", u8aToHex(secretKey));
// for ( var i=0; i <5; i++) {
// const randomMini = randomAsHex(32);
// console.log("randomMini: ", randomMini);
// const spsr = keyring.createFromUri(`${randomMini}`, {}, 'sr25519' );
// const sped = keyring.createFromUri(`${randomMini}`);
// console.log(" : " ,i , " sr25519 addr: " , deriveAddress(spsr.publicKey, POLKADOT_SS58_FORMAT), " default ed25519: ", deriveAddress(sped.publicKey, 42));
// }
// create an sr25519 pair from the mnemonic (keyring defaults)
// keyring.setSS58Format(POLKADOT_SS58_FORMAT);
const sp = keyring.createFromUri(mnemonic);
console.log(" name: ", sp.meta.name, " address: ", sp.address);
//转POLKADOT_SS58_FORMAT格式
const ss58Addr = deriveAddress(sp.publicKey, POLKADOT_SS58_FORMAT);
console.log(" ss58 addr: ", ss58Addr);
// Aries code end
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
polkadot 账户操作
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Githubhttps://github.com/polkadot-js/apps 是什么 polkadot-js...
- 一、使用while循环输出一个九九乘法表 如图输出结果: 二、使用循环(任意一种)计算0--100之间所有奇数的和...
- 引言: 最近开始学习“机器学习”,早就听说祖国宝岛的李宏毅老师的大名,一直没有时间看他的系列课程。今天听了一课,感...