1.1.48 • Published 3 months ago

@kitzen/wallet-core-essentials v1.1.48

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

wallet-core-essentials

npm version from kitzen with Love test Known Vulnerabilities

Kitzen Wallet Core Essentials is an open-source library, provides reusable components and core cryptographic wallet functionality for a different blockchains. It is a core part of Kitzen Wallet.

Installation

Modify package.json with

{  
  "scripts": {
    "postinstall": "patch-package"
  }
}

Copy patches

mkdir ./patches
cp ./node_modules/@tronscan/client/patches/* ./patches

Install the package

yarn add @kitzen/wallet-core-essentials

React-native installation

Create initialize.ts file and import it somewhere on the main entry, e.g. onm the react-native index.js

import {Buffer} from "buffer";
import {CryptoFactory} from "@kitzen/wallet-core-essentials";
import * as bip39 from "@kitzen/react-native-bip39";

global.Buffer = Buffer;
CryptoFactory.setBip39(bip39);

Web installation

Initialize factory, before using it:

import {Buffer} from "buffer";
import {CryptoFactory} from "@kitzen/wallet-core-essentials";
import {
  mnemonicToSeedSync,
  generateMnemonic
} from "bip39";

global.Buffer = Buffer;
CryptoFactory.setBip39({
  mnemonicToSeed: mnemonicToSeedSync,
  generateMnemonic: async(...args) => generateMnemonic(...args),
});

Library usage

You can access docs by themes here:

Testing

Library provides whole spectre of tests that occupies majority of cases that could happen or used in development. You can explore tests here

Tron hex message decode

There are 2 types of messages: with signature and without signature. You have to understand how protobuf works and it's structure and nested classes for Tron implementation. Take a look at node_modules/@tronscan/client/protobuf/core/Tron.proto You are interested in Transaction class. As you see it contains 2 fields.

  • raw_data (field number 1, type 'raw')
  • signature (field number 2, type 'repeated bytes')

If you have to parse such a hex message (with signature) you can do the following: With signature:

# pacman -S extra/protobuf
cd ./node_modules/@tronscan/client/protobuf
echo 'long-hex-message-string-like-a30174b6c2223' | xxd -r -p - > message.bin
protoc --decode protocol.Transaction core/Tron.proto < message.bin

You can also use https://protobuf-decoder.netlify.app/ but it won't show you fields names.

Let's say we have to decode a hex transaction without a signature. We clearly see that it's a type of raw by the Tron.proto file, so we do:

protoc --decode protocol.Transaction.raw core/Tron.proto < message.bin

Lets review the hex of Tron network Smart contract. This is a typical hex representation of the message that's being sent to backend api. And it's a binary representation of protobuf format.

name#hexdescription
Transaction0a 02 a5 91 22 08 71 30 31 ee 43 e2 4b 93 40 a0 95 dd ad a9 31 5a ae 01 08 1f 12 a9 01 0a 31 74 79 70 65 2e 67 6f 6f 67 6c 65 61 70 69 73 2e 63 6f 6d 2f 70 72 6f 74 6f 63 6f 6c 2e 54 72 69 67 67 65 72 53 6d 61 72 74 43 6f 6e 74 72 61 63 74 12 74 0a 15 41 7a 86 49 ab fa 3d 24 f8 d0 dc 70 d2 b6 d5 0e 4f 8a 6f 76 13 12 15 41 a6 14 f8 03 b6 fd 78 09 86 a4 2c 78 ec 9c 7f 77 e6 de d1 3c 22 44 a9 05 9c bb 00 00 00 00 00 00 00 00 00 00 00 00 1c 00 0d d5 6b 9e 63 4f e6 73 46 b8 90 45 99 0c b7 bb 82 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 70 f4 c3 d9 ad a9 31Hex representation of protobuf transaction, which is sent as message to backend API
transaction.type174 79 70 65 2E 67 6F 6F 67 6C 65 61 70 69 73 2E 63 6F 6D 2F 70 72 6F 74 6F 63 6F 6C 2E 54 72 69 67 67 65 72 53 6D 61 72 74 43 6F 6E 74 72 61 63 74type.googleapis.com/protocol.TriggerSmartContract
transaction.sender_address141 7a 86 49 ab fa 3d 24 f8 d0 dc 70 d2 b6 d5 0e 4f 8a 6f 76 13hex(base58("TM94JwXLN33Gw4L8KF1eBPaEEPcdQi6hht"))
transaction.contract_address241 a6 14 f8 03 b6 fd 78 09 86 a4 2c 78 ec 9c 7f 77 e6 de d1 3chex(base58("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")) // USDT address
transaction.param4a9 05 9c bb 00 00 00 00 00 00 00 00 00 00 00 00 1c 00 0d d5 6b 9e 63 4f e6 73 46 b8 90 45 99 0c b7 bb 82 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01Abi encoded transfer(address,uint256)
transaction.param.receiver_address1c 00 0d d5 6b 9e 63 4f e6 73 46 b8 90 45 99 0c b7 bb 82 1dhex(base58("CXFzBg8XjZF2NUjDSzSxXLBxeZxgPpS5o")), first T is dropped

Contributing

We deeply appreciate the valuable contributions made by our community. To provide feedback or report bugs, kindly open a GitHub issue. For code contributions, explore our "Contributing" guidelines and become part of our open-source community.

Thank you to all the dedicated individuals who contribute; your passion drives our success. Together, we shape the future of web3 industry.

1.1.48

3 months ago

1.1.47

3 months ago

1.1.46

3 months ago

1.1.45

4 months ago

1.1.44

4 months ago

1.1.43

4 months ago

1.1.42

4 months ago

1.1.41

4 months ago

1.1.40

5 months ago

1.1.38

5 months ago

1.1.37

5 months ago

1.1.39

5 months ago

1.1.36

5 months ago

1.1.35

5 months ago

1.1.34

5 months ago

1.1.33

5 months ago

1.1.32

5 months ago

1.1.31

5 months ago

1.1.30

5 months ago

1.1.29

5 months ago

1.1.28

6 months ago

1.1.27

6 months ago

1.1.26

6 months ago

1.1.25

6 months ago

1.1.24

7 months ago

1.1.22

7 months ago

1.1.21

7 months ago

1.1.20

7 months ago

1.1.19

7 months ago

1.1.18

8 months ago

1.1.17

8 months ago

1.1.16

8 months ago

1.1.15

8 months ago

1.1.14

8 months ago

1.1.13

8 months ago

1.1.12

8 months ago

1.1.11

8 months ago

1.1.10

9 months ago

1.1.9

9 months ago

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago