Skip to content

Commit

Permalink
UInt8Array needs to be encoded as BigInt string
Browse files Browse the repository at this point in the history
  • Loading branch information
johnqh committed Oct 25, 2023
1 parent a0057a8 commit 9d51080
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
21 changes: 16 additions & 5 deletions v4-client-js/__native__/__ios__/v4-native-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -200679,13 +200679,13 @@ exports.UserError = UserError;
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";
/* provided dependency */ var Buffer = __webpack_require__(/*! buffer */ "./node_modules/buffer/index.js")["Buffer"];

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.encodeJson = exports.stripHexPrefix = exports.convertPartialTransactionOptionsToFull = void 0;
const encoding_1 = __webpack_require__(/*! @cosmjs/encoding */ "./node_modules/@cosmjs/encoding/build/index.js");
exports.encodeJson = exports.bytesToBigInt = exports.stripHexPrefix = exports.convertPartialTransactionOptionsToFull = void 0;
const bignumber_js_1 = __importDefault(__webpack_require__(/*! bignumber.js */ "./node_modules/bignumber.js/bignumber.js"));
const long_1 = __importDefault(__webpack_require__(/*! long */ "./node_modules/long/src/long.js"));
const constants_1 = __webpack_require__(/*! ./constants */ "./src/lib/constants.ts");
Expand Down Expand Up @@ -200718,6 +200718,17 @@ function stripHexPrefix(input) {
return input;
}
exports.stripHexPrefix = stripHexPrefix;
function bytesToBigInt(u) {
if (u.length <= 1) {
return BigInt(0);
}
// eslint-disable-next-line no-bitwise
const negated = (u[0] & 1) === 1;
const hex = Buffer.from(u.slice(1)).toString('hex');
const abs = BigInt(`0x${hex}`);
return negated ? -abs : abs;
}
exports.bytesToBigInt = bytesToBigInt;
function encodeJson(object) {
// eslint-disable-next-line prefer-arrow-callback
return JSON.stringify(object, function replacer(_key, value) {
Expand All @@ -200730,16 +200741,16 @@ function encodeJson(object) {
return value.toString();
}
if ((value === null || value === void 0 ? void 0 : value.buffer) instanceof Uint8Array) {
return (0, encoding_1.toHex)(value.buffer);
return bytesToBigInt(value.buffer).toString();
}
else if (value instanceof Uint8Array) {
return (0, encoding_1.toHex)(value);
return bytesToBigInt(value).toString();
}
return value;
});
}
exports.encodeJson = encodeJson;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSwrQ0FBeUM7QUFDekMsZ0VBQXFDO0FBQ3JDLGdEQUF3QjtBQUd4QiwyQ0FBK0M7QUFFL0M7Ozs7O0dBS0c7QUFDSCxTQUFnQixzQ0FBc0MsQ0FDcEQseUJBQXFEO0lBRXJELElBQUkseUJBQXlCLEtBQUssU0FBUyxFQUFFO1FBQzNDLE9BQU8sU0FBUyxDQUFDO0tBQ2xCO0lBRUQsT0FBTztRQUNMLFFBQVEsRUFBRSw0QkFBZ0I7UUFDMUIsR0FBRyx5QkFBeUI7S0FDN0IsQ0FBQztBQUNKLENBQUM7QUFYRCx3RkFXQztBQUVEOzs7OztHQUtHO0FBQ0gsU0FBZ0IsY0FBYyxDQUFDLEtBQWE7SUFDMUMsSUFBSSxLQUFLLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsRUFBRTtRQUM3QixPQUFPLEtBQUssQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7S0FDdkI7SUFFRCxPQUFPLEtBQUssQ0FBQztBQUNmLENBQUM7QUFORCx3Q0FNQztBQUVELFNBQWdCLFVBQVUsQ0FBQyxNQUFlO0lBQ3hDLGlEQUFpRDtJQUNqRCxPQUFPLElBQUksQ0FBQyxTQUFTLENBQUMsTUFBTSxFQUFFLFNBQVMsUUFBUSxDQUFDLElBQUksRU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3JELHdFQUF3RTtRQUN4RSxJQUFJLEtBQUssWUFBWSxzQkFBUyxFQUFFO1lBQzlCLE9BQU8sS0FBSyxDQUFDLFFBQVEsRUFBRSxDQUFDO1NBQ3pCO1FBQ0QsSUFBSSxLQUFLLFlBQVksY0FBSSxFQUFFO1lBQ3pCLE9BQU8sS0FBSyxDQUFDLFFBQVEsRUFBRSxDQUFDO1NBQ3pCO1FBQ0QsSUFBSSxDQUFBLEtBQUssYUFBTCxLQUFLLHVCQUFMLEtBQUssQ0FBRSxNQUFNLGFBQVksVUFBVSxFQUFFO1lBQ3ZDLE9BQU8sYUFBYSxDQUFDLEtBQUssQ0FBQyxNQUFNLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQztTQUMvQzthQUFNLElBQUksS0FBSyxZQUFZLFVBQVUsRUFBRTtZQUN0QyxPQUFPLGFBQWEsQ0FBQyxLQUFLLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQztTQUN4QztRQUNELE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQyxDQUFDLENBQUM7QUFDTCxDQUFDO0FBbEJELGdDQWtCQyJ9

/***/ }),

Expand Down
15 changes: 13 additions & 2 deletions v4-client-js/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export function stripHexPrefix(input: string): string {
return input;
}

export function bytesToBigInt(u: Uint8Array): BigInt {
if (u.length <= 1) {
return BigInt(0);
}
// eslint-disable-next-line no-bitwise
const negated: boolean = (u[0] & 1) === 1;
const hex: string = Buffer.from(u.slice(1)).toString('hex');
const abs: bigint = BigInt(`0x${hex}`);
return negated ? -abs : abs;
}

export function encodeJson(object?: Object): string {
// eslint-disable-next-line prefer-arrow-callback
return JSON.stringify(object, function replacer(_key, value) {
Expand All @@ -50,9 +61,9 @@ export function encodeJson(object?: Object): string {
return value.toString();
}
if (value?.buffer instanceof Uint8Array) {
return toHex(value.buffer);
return bytesToBigInt(value.buffer).toString();
} else if (value instanceof Uint8Array) {
return toHex(value);
return bytesToBigInt(value).toString();
}
return value;
});
Expand Down

0 comments on commit 9d51080

Please sign in to comment.