Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcblock/forge-message

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/forge-message - npm Package Compare versions

Comparing version 0.21.0 to 0.22.0

65

lib/message.js

@@ -6,2 +6,6 @@ /**

* @requires @arcblock/forge-proto
* @example
* yarn add @arcblock/forge-message
*
* const { createMessage, fakeMessage, formatMessage } = require('@arcblock/forge-message');
*/

@@ -61,4 +65,17 @@

* @static
* @param {string} type
* @param {string} type - Message type string, should be defined in forge-abi or forge-core-protocol
* @returns {object}
* @example
* const { fakeMessage} = require('@arcblock/forge-message');
* const message = fakeMessage('CreateAssetTx');
* // will output
* {
* moniker: 'arcblock',
* data: { type: 'string', value: 'ABCD 1234' },
* readonly: true,
* transferrable: true,
* ttl: 2,
* parent: 'arcblock',
* address: 'F2D072CBD4954A20F26280730795D91AC1039996CEB6E24A31E9CE548DCB5E55',
* }
*/

@@ -148,3 +165,3 @@ function fakeMessage(type) {

if (type === 'json') {
return JSON.parse(Buffer.from(data, 'base64').toString('utf8'));
return data;
}

@@ -253,2 +270,13 @@

* @returns {object} Message instance
* @example
* const { createMessage } = require('@arcblock/forge-message');
* const message = createMessage ('CreateAssetTx', {
* moniker: 'asset',
* address: 'zaAKEJRKQWsdfjksdfjkASRD',
* });
*
* message.getMoniker(); // 'asset'
* message.getAddress(); // 'zaAKEJRKQWsdfjksdfjkASRD'
* message.getReadonly(); // false
* message.setReadonly(true);
*/

@@ -365,3 +393,3 @@ function createMessage(type, params) {

if (typeUrl === 'json') {
return { type: typeUrl, value: JSON.parse(Buffer.from(value)) };
return { type: typeUrl, value: JSON.parse(Buffer.from(value, 'base64')) };
}

@@ -395,16 +423,23 @@

const anyMessage = new Any();
if (data.typeUrl && data.value && !data.type) {
// avoid duplicate serialization
anyMessage.setTypeUrl(data.typeUrl);
if (data.typeUrl === 'json') {
anyMessage.setValue(Uint8Array.from(Buffer.from(JSON.stringify(data.value))));
try {
if (data.typeUrl && data.value && !data.type) {
// avoid duplicate serialization
anyMessage.setTypeUrl(data.typeUrl);
if (data.typeUrl === 'fg:x:address') {
anyMessage.setValue(data.value);
} else if (data.typeUrl === 'json') {
anyMessage.setValue(Uint8Array.from(Buffer.from(JSON.stringify(data.value))));
} else {
anyMessage.setValue(Uint8Array.from(Buffer.from(data.value, 'base64')));
}
} else {
anyMessage.setValue(Uint8Array.from(Buffer.from(data.value, 'base64')));
const { value: anyValue, type: anyType } = data;
const typeUrl = toTypeUrl(anyType);
const anyValueBinary = createMessage(anyType, anyValue);
anyMessage.setTypeUrl(typeUrl);
anyMessage.setValue(anyValueBinary.serializeBinary());
}
} else {
const { value: anyValue, type: anyType } = data;
const typeUrl = toTypeUrl(anyType);
const anyValueBinary = createMessage(anyType, anyValue);
anyMessage.setTypeUrl(typeUrl);
anyMessage.setValue(anyValueBinary.serializeBinary());
} catch (err) {
console.error('error encode any type', data);
throw err;
}

@@ -411,0 +446,0 @@

{
"name": "@arcblock/forge-message",
"description": "Utility functions to encode and decode message that can send to forge",
"version": "0.21.0",
"version": "0.22.0",
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",

@@ -21,4 +21,4 @@ "engines": {

"dependencies": {
"@arcblock/forge-proto": "^0.21.0",
"@arcblock/forge-util": "^0.21.0",
"@arcblock/forge-proto": "^0.22.0",
"@arcblock/forge-util": "^0.22.0",
"camelcase": "^5.0.0",

@@ -31,2 +31,3 @@ "debug": "^4.1.1",

"jest": "^23.5.0",
"jsdoc-to-markdown": "^4.0.1",
"remark-cli": "^5.0.0",

@@ -68,3 +69,4 @@ "remark-preset-github": "^0.0.9"

"lint": "eslint lib index.js lite.js tests",
"upgrade": "npm run format-docs && npm run generate-dts",
"upgrade": "yarn format-docs && yarn generate-dts",
"generate-docs": "jsdoc2md lib/message.js > docs/README.md",
"format-docs": "remark . -o",

@@ -74,6 +76,6 @@ "generate-dts": "j2d index.js",

"prepush": "CI=1 yarn test",
"test": "npm run lint && node tools/jest.js",
"coverage": "npm run lint && yarn test -- --coverage"
"test": "yarn lint && node tools/jest.js",
"coverage": "yarn lint && yarn test -- --coverage"
},
"gitHead": "70d1b0561d18f4a2082d379d836ef44ef7ac5317"
"gitHead": "1e2bc71da51158cd827b3b5e544d91a73fdfadf4"
}

@@ -7,17 +7,20 @@ # [**@arcblock/forge-message**](https://github.com/arcblock/forge-js)

## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Documentation](#documentation)
- [Contributors](#contributors)
* [Install](#install)
* [Usage](#usage)
* [Documentation](#documentation)
* [Contributors](#contributors)
## Install
```sh
npm install @arcblock/forge-message
// or
npm i @arcblock/forge-message
// OR
yarn add @arcblock/forge-message
```
## Usage

@@ -44,1 +47,13 @@

```
## Documentation
For full documentation, checkout [README.md](./docs/README.md).
## Contributors
| Name | Website |
| -------------- | -------------------------- |
| **wangshijun** | <https://ocap.arcblock.io> |
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