bitbadgesjs
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "bitbadgesjs", | ||
"version": "0.0.2", | ||
"main": "index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
"description": "JS and TS libs for BitBadges", | ||
"version": "0.0.3", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"_moduleAliases": { | ||
"~bitbadgesjs": "dist" | ||
}, | ||
"author": "Guillermo Paoletti <guillermo.paoletti@gmail.com>, Trevor Miller <trevormil@comcast.net>", | ||
"repository": "https://github.com/bitbadges/bitbadgesjs", | ||
"workspaces": { | ||
"packages": [ | ||
"packages/*" | ||
] | ||
}, | ||
"scripts": { | ||
"build": "lerna run --parallel build", | ||
"lerna:publish": "lerna publish from-package", | ||
"build:watch": "lerna run --parallel build:watch", | ||
"build:fresh": "yarn clean && yarn build", | ||
"build:patch:publish": "yarn build:fresh && yarn patch && yarn lerna:publish", | ||
"patch": "lerna version patch", | ||
"clean": "lerna run --parallel clean && shx rm -rf .build-cache *.log coverage junit.xml", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest", | ||
"postinstall": "shx mkdir -p dist && link-module-alias", | ||
"build": "tsc --build tsconfig.build.json && link-module-alias", | ||
"build:watch": "tsc --build -w tsconfig.build.json && link-module-alias", | ||
"clean": "tsc --build tsconfig.build.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache", | ||
"test": "jest", | ||
"test:unit": "jest test/unit", | ||
"test:integration": "jest test/unit", | ||
"test:watch": "jest --watch", | ||
"test:ci": "jest --coverage --ci --reporters='jest-junit'", | ||
"test:unit": "jest packages/*/test/unit", | ||
"test:integration": "jest packages/*/test/integration", | ||
"coverage": "jest --coverage", | ||
"coverage:unit": "yarn test:unit --coverage", | ||
"coverage:integration": "yarn test:integration --coverage", | ||
"lint": "eslint -c './.eslintrc.js' './packages/**/*.{ts,js}'", | ||
"lint:ci": "yarn lint . --format junit", | ||
"lint:md": "markdownlint --ignore node_modules --ignore .git", | ||
"format": "yarn lint --fix", | ||
"format:md": "yarn lint:md --fix", | ||
"husky-skip": "cross-env HUSKY_SKIP_HOOKS=1", | ||
"commit": "git cz", | ||
"prepare": "husky install", | ||
"lerna": "lerna" | ||
"dev": "ts-node-dev -r tsconfig-paths/register src/index.ts", | ||
"start": "node dist/index.js" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx}": [ | ||
"eslint --fix" | ||
], | ||
"*.md": [ | ||
"yarn format:md" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^16.2.0", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@types/jest": "^27.0.1", | ||
"@types/node": "^16.9.2", | ||
"@typescript-eslint/eslint-plugin": "^4.31.1", | ||
"@typescript-eslint/parser": "^4.31.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-import-resolver-typescript": "^2.5.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-jest": "^24.4.2", | ||
"eslint-plugin-markdown": "^2.2.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"jest-junit": "^13.0.0", | ||
"lerna": "^5.4.3", | ||
"dependencies": { | ||
"bitbadgesjs-address-converter": "^0.0.2", | ||
"bitbadgesjs-eip712": "^0.0.27", | ||
"bitbadgesjs-proto": "^0.0.27", | ||
"bitbadgesjs-provider": "^0.0.1", | ||
"bitbadgesjs-transactions": "^0.0.34", | ||
"@types/node": "^17.0.21", | ||
"link-module-alias": "^1.2.0", | ||
"lint-staged": "^11.1.2", | ||
"markdownlint-cli": "^0.31.1", | ||
"prettier": "^2.4.1", | ||
"shx": "^0.3.4", | ||
"ts-jest": "^27.0.5", | ||
"ts-node-dev": "^1.1.8", | ||
"tsconfig-paths": "^3.11.0", | ||
"typescript": "^4.4.3" | ||
"shx": "^0.3.4" | ||
} | ||
} |
193
README.md
@@ -1,192 +0,3 @@ | ||
# evmosjs | ||
# Evmosjs | ||
[![Total alerts](https://img.shields.io/lgtm/alerts/g/tharsis/evmosjs.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tharsis/evmosjs/alerts/) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/tharsis/evmosjs.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tharsis/evmosjs/context:javascript) | ||
JS and TS libs for Evmos | ||
## Example | ||
### Get account information | ||
Get the account number, sequence and pubkey from an address. | ||
NOTE: if the address had not sent any transaction to the blockchain, the pubkey value are going to be empty. | ||
```ts | ||
import { ethToEvmos } from '@tharsis/address-converter' | ||
import { generateEndpointAccount } from '@tharsis/provider' | ||
const sender = 'evmos1...' | ||
let destination = '0x....' | ||
// The address must be bech32 encoded | ||
if (destination.split('0x').length == 2) { | ||
destination = ethToEvmos(destination) | ||
} | ||
// Query the node | ||
const options = { | ||
method: 'GET', | ||
headers: { 'Content-Type': 'application/json' }, | ||
} | ||
let addrRawData = await fetch( | ||
`http://127.0.0.1:1317${generateEndpointAccount(sender)}`, | ||
options, | ||
) | ||
// NOTE: the node returns status code 400 if the wallet doesn't exist, catch that error | ||
let addrData = await addRawData.json() | ||
// Response format at @tharsis/provider/rest/account/AccountResponse | ||
/* | ||
account: { | ||
'@type': string | ||
base_account: { | ||
address: string | ||
pub_key?: { | ||
'@type': string | ||
key: string | ||
} | ||
account_number: string | ||
sequence: string | ||
} | ||
code_hash: string | ||
} | ||
*/ | ||
``` | ||
### Create a MsgSend Transaction | ||
The transaction can be signed using EIP712 on Metamask and SignDirect on Keplr. | ||
```ts | ||
import { createMessageSend } from '@tharsis/transactions' | ||
const chain = { | ||
chainId: 9000, | ||
cosmosChainId: 'evmos_9000-1', | ||
} | ||
const sender = { | ||
accountAddress: 'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm', | ||
sequence: 1, | ||
accountNumber: 9, | ||
pubkey: 'AgTw+4v0daIrxsNSW4FcQ+IoingPseFwHO1DnssyoOqZ', | ||
} | ||
const fee = { | ||
amount: '20', | ||
denom: 'aevmos', | ||
gas: '200000', | ||
} | ||
const memo = '' | ||
const params = { | ||
destinationAddress: 'evmos1pmk2r32ssqwps42y3c9d4clqlca403yd9wymgr', | ||
amount: '1', | ||
denom: 'aevmos', | ||
} | ||
const msg = createMessageSend(chain, sender, fee, memo, params) | ||
// msg.signDirect is the transaction in Keplr format | ||
// msg.legacyAmino is the transaction with legacy amino | ||
// msg.eipToSign is the EIP712 data to sign with metamask | ||
``` | ||
### Signing with Metamask | ||
After creating the transaction we need to send the payload to metamask so it can be signed. With that signature we are going to add a Web3Extension to the Cosmos Transactions and broadcast it to the Evmos node. | ||
```ts | ||
// Follow the previous step to generate the msg object | ||
import { evmosToEth } from '@tharsis/address-converter' | ||
import { | ||
generateEndpointBroadcast, | ||
generatePostBodyBroadcast, | ||
} from '@tharsis/provider' | ||
import { | ||
createTxRawEIP712, | ||
signatureToWeb3Extension, | ||
} from '@tharsis/transactions' | ||
// Init Metamask | ||
await window.ethereum.enable() | ||
// Request the signature | ||
let signature = await window.ethereum.request({ | ||
method: 'eth_signTypedData_v4', | ||
params: [evmosToEth(sender.accountAddress), JSON.stringify(msg.eipToSign)], | ||
}) | ||
// The chain and sender objects are the same as the previous example | ||
let extension = signatureToWeb3Extension(chain, sender, signature) | ||
// Create the txRaw | ||
let rawTx = createTxRawEIP712( | ||
msg.legacyAmino.body, | ||
msg.legacyAmino.authInfo, | ||
extension, | ||
) | ||
// Broadcast it | ||
const postOptions = { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: generatePostBodyBroadcast(rawTx), | ||
} | ||
let broadcastPost = await fetch( | ||
`http://localhost:1317${generateEndpointBroadcast()}`, | ||
postOptions, | ||
) | ||
let response = await broadcastPost.json() | ||
``` | ||
### Signing with Keplr | ||
```ts | ||
// Follow the previous step to generate the msg object | ||
import { createTxRaw } from '@tharsis/proto' | ||
import { | ||
generateEndpointBroadcast, | ||
generatePostBodyBroadcast, | ||
} from '@tharsis/provider' | ||
let sign = await window?.keplr?.signDirect( | ||
chain.cosmosChainId, | ||
sender.accountAddress, | ||
{ | ||
bodyBytes: msg.signDirect.body.serializeBinary(), | ||
authInfoBytes: msg.signDirect.authInfo.serializeBinary(), | ||
chainId: chain.cosmosChainId, | ||
accountNumber: new Long(sender.accountNumber), | ||
}, | ||
// @ts-expect-error the types are not updated on Keplr side | ||
{ isEthereum: true }, | ||
) | ||
if (sign !== undefined) { | ||
let rawTx = createTxRaw(sign.signed.bodyBytes, sign.signed.authInfoBytes, [ | ||
new Uint8Array(Buffer.from(sign.signature.signature, 'base64')), | ||
]) | ||
// Broadcast it | ||
const postOptions = { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: generatePostBodyBroadcast(rawTx), | ||
} | ||
let broadcastPost = await fetch( | ||
`http://localhost:1317${generateEndpointBroadcast()}`, | ||
postOptions, | ||
) | ||
let response = await broadcastPost.json() | ||
} | ||
``` | ||
## TODO | ||
- Add docs and examples to all the packages. | ||
- Add more cosmos messages | ||
Main package |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
0
4000
8
6
42
2
4
1
1
+ Added@types/node@^17.0.21
+ Addedbitbadgesjs-eip712@^0.0.27
+ Addedbitbadgesjs-proto@^0.0.27
+ Addedbitbadgesjs-provider@^0.0.1
+ Addedlink-module-alias@^1.2.0
+ Addedshx@^0.3.4
+ Added@types/google-protobuf@3.15.12(transitive)
+ Added@types/node@17.0.45(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase-x@3.0.10(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbech32@2.0.0(transitive)
+ Addedbig-integer@1.6.36(transitive)
+ Addedbitbadgesjs-address-converter@0.0.2(transitive)
+ Addedbitbadgesjs-eip712@0.0.27(transitive)
+ Addedbitbadgesjs-proto@0.0.27(transitive)
+ Addedbitbadgesjs-provider@0.0.1(transitive)
+ Addedbitbadgesjs-transactions@0.0.34(transitive)
+ Addedblakejs@1.2.1(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcrypto-addr-codec@0.1.8(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgoogle-protobuf@3.21.4(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedlink-module-alias@1.2.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedprotoc-gen-ts@0.8.7(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedripemd160-min@0.0.6(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsha3@2.1.4(transitive)
+ Addedshelljs@0.8.5(transitive)
+ Addedshx@0.3.4(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)