@sallt/pepper_wallet (NodeJS)

@sallt/pepper_wallet

Sallt ํ”„๋กœ์ ํŠธ์˜ SymKeystoreLoader ํ”„๋กœ์ ํŠธ๋ฅผ Node.js์™€ Web์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก WebAssembly๋กœ ๊ฐœ๋ฐœ๋œ ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค.

๊ธฐ๋Šฅ ๊ฐœ์„ ์ด๋‚˜ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด ์˜ˆ๊ณ ์—†์ด ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—…๋ฐ์ดํŠธ์‹œ ์•ˆ๋‚ด๋ฅผ ๊ผญ ํ™•์ธํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Sallt ํ”„๋กœ์ ํŠธ๋Š” Dart/Flutter ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํฌ๋กœ์Šคํ”Œ๋žซํผ์œผ๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Dart๋กœ ๋งŒ๋“ค์–ด์ง„ SDK ํŒจํ‚ค์ง€๋„ ํ›Œ๋ฅญํ•œ ์„ฑ๋Šฅ๊ณผ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜์ง€๋งŒ, Dart๋กœ ๋งŒ๋“ค์–ด์ง„ ์ปดํฌ๋„ŒํŠธ ๋ฐ ์„œ๋ฒ„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜, Flutter๋กœ ๋งŒ๋“ค์–ด์ง„ ๋ชจ๋ฐ”์ผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‚˜ ์‹ฑ๊ธ€ ํŽ˜์ด์ง€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜(SPA)์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ˆœ์ˆ˜ํ•œ ์›น์ด๋‚˜ Node ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์‚ฌ์šฉ์ด ์ œํ•œ๋ฉ๋‹ˆ๋‹ค.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด WebAssembly๋กœ ๊ฐœ๋ฐœ๋œ pepper-wallet๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, Node.js์™€ ์›น์—์„œ๋„ SymKeystoreLoader ํŒจํ‚ค์ง€์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ค์น˜๋ฐฉ๋ฒ•

NPM ์„ค์น˜ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋ฅผ ํ†ตํ•ด ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

์ž์ฒด NPM Registry๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ, npm config๋ฅผ ํ†ตํ•ด ์ถ”๊ฐ€ ์„ค์ •์„ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

npm config set registry=https://registry.yarnpkg.com/
npm config set @sallt:registry=https://nexus.symverse.com/repository/sallt-npm/
npm config set //nexus.symverse.com/repository/sallt-npm/:_auth=Z3Vlc3Q6Z3Vlc3Q=
npm config set always-auth=true

๋˜๋Š”,

.npmrc ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ ์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

registry=https://registry.yarnpkg.com/
@sallt:registry=https://nexus.symverse.com/repository/sallt-npm/
//nexus.symverse.com/repository/sallt-npm/:_auth=Z3Vlc3Q6Z3Vlc3Q=
always-auth=true

์ดํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

npm install @sallt/pepper_wallet

์‚ฌ์šฉ๋ฐฉ๋ฒ•

import { SCrypt, Credentials, MsgHashAlgorithm, SymId, UInt256, UInt8, WorkNodes, Data, SymTransaction } from '@sallt/pepper_wallet';

// Parameters of the encrypted private key
let iv = "{16byte hex string}";
let ciphertext = "{32byte hex string}";
let dklen = 32;
let n = 262144;
let p = 1;
let r = 8;
let salt = "{32byte hex string}";

// Recovering the private key
let scrypt = new SCrypt(dklen, n, p, r, salt);
let credentials = new Credentials(scrypt, ciphertext, iv);
await credentials.initialize(_passphrase).then(
        async () => {
            // credentials is initialized
            // public key hash
            let publicKeyHash = credentials.publicKeyHash(MsgHashAlgorithm.Sha3_256);
            let pubKeyHash = Web3Utils.uint8ArrayToHexString(publicKeyHash);
        },
        async (error) => {
            // error
        }
);

// Composing a transaction
let symId = "{10byte hex string}";
let nonce = "{nonce in hex string}";
let gas_price = "{gas price in hex string}";
let gas_limit = "{gas limit in hex string}";
let recipient_sym_id = "{10byte hex string}";
let hex_amount = "{amount in hex string}";
let data = "{data in hex string}";
let transaction_type = "{0x00(original), 0x01(sct) or 0x02(deposit)}";
let work_node_id = "{10byte hex string}";
let extra_data = "{extra data in hex string}";

let symTransaction = new SymTransaction(
    SymId.fromHexString(symId),
    UInt256.fromHexString(nonce),
    UInt256.fromHexString(gas_price),
    UInt256.fromHexString(gas_limit),
    SymId.fromHexString(recipient_sym_id),
    UInt256.fromHexString(hex_amount),
    Data.fromHexString(data),
    UInt8.fromHexString(transaction_type),
    new WorkNodes(SymId.fromHexString(work_node_id)),
    Data.fromHexString(extra_data)
);

// Signing a transaction
let chain_id = 1;
let fork_id = 0;

let sha3Sign = _credentials.sign(MsgHashAlgorithm.Sha3_256, chain_id, fork_id, symTransaction.selfPtr());
let signedMsg = sha3Sign.hexSignedMsg();

// Send a transaction
// use webd3 ...no

๊ธฐ์—ฌํ•˜๊ธฐ

๋ณธ ํ”„๋กœ์ ํŠธ๋Š” Sallt ์„œ๋น„์Šค ์ƒํƒœ๊ณ„ ํ™•๋Œ€๋ฅผ ์œ„ํ•ด ๊ฐœ๋ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ์—ฌ๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ๋ฅผ ํ•จ๊ป˜ ๋ฐœ์ „์‹œ์ผœ ์ฃผ์„ธ์š”!

๋ผ์ด์„ผ์Šค

Apache-2.0

MIT

์ฐธ๊ณ 

Sallt

ํ•˜๋‹จ์˜ ๋‚ด์šฉ์€ Bundler๊ฐ€ ํฌํ•จ๋œ Web Javascript ์šฉ ํŒจํ‚ค์ง€ ๋ฐ ํŒจํ‚ค์ง€์˜ ์‚ฌ์šฉ ์„ค๋ช…์ด๋ฏ€๋กœ Node.js์—์„œ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ์—๋Š” ์ƒ๋‹จ์˜ ๋‚ด์šฉ๋งŒ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Pepper Wallet (WASM)

  • Pepper Wallet JS์˜ ๊ธฐ๋Šฅ์„ WASM์œผ๋กœ ๊ตฌํ˜„ํ•œ ๊ตฌํ˜„์ฒด ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค.

    • ๊ตฌ์กฐ์ฒด ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ ๊ตฌ์กฐ์ด๋ฏ€๋กœ Pepper Wallet JS๋ณด๋‹ค ๋” ๋‹ค์–‘ํ•œ ๋„๊ตฌ๊ฐ€ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

      • SCrypt, Aes128Ctr, Signer

  • Wallet ๊ด€๋ฆฌ ๊ธฐ๋Šฅ(์˜ˆ์ •)์„ ์ œ๊ณตํ•˜๋ฉฐ, ๋ธŒ๋ผ์šฐ์ € ๋‚ด์—์„œ ํ•ฉ๋ฆฌ์ ์ด๊ณ  ํšจ์œจ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ณด๊ด€ํ•˜๊ณ  ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • SCrypt๋ฅผ ํ†ตํ•ด 256๋น„ํŠธ ๊ธธ์ด์˜ Derived Key๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Aes128Ctr์„ ํ†ตํ•ด ํ‚ค์Šคํ† ์–ด์˜ Crypto(aes-128-ctr)์„ ๋””์ฝ”๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    • SCrypt๋กœ ๋งŒ๋“  DK์˜ ์•ž 128๋น„ํŠธ๋ฅผ ์•”ํ˜ธํ™” ํ‚ค๋กœ ์‚ฌ์šฉ

  • Signer๋ฅผ ํ†ตํ•ด SymVerse ๋„คํŠธ์›Œํฌ ๋ฐ Ethereum ๋„คํŠธ์›Œํฌ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์„œ๋ช…์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Pepper Wief (WASM)์„ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์—ฌ ์›น ์ž์ฒด์ ์ธ ์ง€๊ฐ‘ ์šด์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    • Wief ํฌ๋งท์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ธŒ๋ผ์šฐ์ € ์ €์žฅ์†Œ์— ๋ณด๊ด€

    • Wief ํฌ๋งท์„ ๋””์ฝ”๋“œํ•˜์—ฌ ์–ป์€ ๊ฐœ์ธํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Signer๋กœ ์„œ๋ช…

  • Pepper Web3 (WASM)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋žœ์žญ์…˜์„ ์ง์ ‘ ์ „์†กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    • let web3 = new Web3("{endpoint_url}"); let symWeb3 = web3.newSymWeb3();

    • let method = SymMethodContainer.{method_func}({params}); let response = await symWeb3.send(method);

ํŒจํ‚ค์ง€ ์ด๋ฆ„

pepper_wallet_rust

์ฐธ๊ณ 

์‚ฌ์šฉ์˜ˆ

  • SymTransaction ๋„๊ตฌ๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.

    • ๋ฐ์ดํ„ฐ ํƒ€์ž…์€ ์ง€์ •๋œ ํƒ€์ž…์„ ์‚ฌ์šฉํ•œ๋‹ค.

  • Credentials ๋„๊ตฌ์˜ sign ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋žœ์žญ์…˜์„ ์„œ๋ช…ํ•œ๋‹ค.

  • SymTransaction ํƒ€์ž…๊ณผ EthTransaction ํƒ€์ž…์„ ๊ฐ™์ด ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

    • ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ signSymTx, signEthTx ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

  • FunctionParameters ๋„๊ตฌ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด์„œ ํ•จ์ˆ˜์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•œ๋‹ค.

  • Function์˜ ์ž…๋ ฅ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ์ˆœ์„œ์— ๋งž๊ฒŒ ํƒ€์ž…๊ณผ ๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.

  • FunctionCoder ๋„๊ตฌ์˜ encode ๋ฉ”์†Œ๋“œ์— ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ์ฒด์™€ ํ•ด์‹œ ์ธ์ฝ”๋”ฉ ๊ทœ์น™์„ ์ง€์ •ํ•˜์—ฌ ์ธ์ฝ”๋”ฉํ•œ๋‹ค.

  • FunctionCoder ๋„๊ตฌ์˜ decode ๋ฉ”์†Œ๋“œ์— ์ธ์ฝ”๋”ฉ๋œ ๋ฐ์ดํ„ฐ์™€ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚˜์—ดํ•œ ๋ฌธ์ž์—ด์„ ๋„ฃ์–ด์ฃผ๋ฉด ํŒŒ์‹ฑํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

Last updated