Socket
Socket
Sign inDemoInstall

bitbadgesjs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitbadgesjs - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

dist/index.d.ts

97

package.json
{
"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"
}
}

@@ -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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc