@mysten/bcs
Advanced tools
Comparing version 0.0.0-experimental-20230613234133 to 0.0.0-experimental-20230615203750
@@ -44,2 +44,3 @@ "use strict"; | ||
registerPrimitives: () => registerPrimitives, | ||
splitGenericParameters: () => splitGenericParameters, | ||
toB58: () => toB58, | ||
@@ -1108,3 +1109,6 @@ toB64: () => toB64, | ||
let typeName = name.slice(0, l_bound); | ||
let params = name.slice(l_bound + 1, name.length - r_bound - 1).split(",").map((e) => e.trim()); | ||
let params = splitGenericParameters( | ||
name.slice(l_bound + 1, name.length - r_bound - 1), | ||
this.schema.genericSeparators | ||
); | ||
return { name: typeName, params }; | ||
@@ -1292,2 +1296,25 @@ } | ||
} | ||
function splitGenericParameters(str, genericSeparators = ["<", ">"]) { | ||
const [left, right] = genericSeparators; | ||
const tok = []; | ||
let word = ""; | ||
let nestedAngleBrackets = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str[i]; | ||
if (char === left) { | ||
nestedAngleBrackets++; | ||
} | ||
if (char === right) { | ||
nestedAngleBrackets--; | ||
} | ||
if (nestedAngleBrackets === 0 && char === ",") { | ||
tok.push(word.trim()); | ||
word = ""; | ||
continue; | ||
} | ||
word += char; | ||
} | ||
tok.push(word.trim()); | ||
return tok; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1306,2 +1333,3 @@ 0 && (module.exports = { | ||
registerPrimitives, | ||
splitGenericParameters, | ||
toB58, | ||
@@ -1308,0 +1336,0 @@ toB64, |
124
CHANGELOG.md
# Change Log | ||
## 0.0.0-experimental-20230613234133 | ||
## 0.0.0-experimental-20230615203750 | ||
### Patch Changes | ||
- ca5c72815d: Fix a bcs decoding bug for u128 and u256 values | ||
- fdb569464e: Fixes an issue with a top level generic in a nested vector | ||
- 36f2edff31: Fix an issue with parsing struct types with nested type parameters | ||
## 0.7.2 | ||
### Patch Changes | ||
- ca5c72815d: Fix a bcs decoding bug for u128 and u256 values | ||
- fdb569464e: Fixes an issue with a top level generic in a nested vector | ||
## 0.7.1 | ||
@@ -14,3 +20,3 @@ | ||
- b4f0bfc76: Fix type definitions for package exports. | ||
- b4f0bfc76: Fix type definitions for package exports. | ||
@@ -21,30 +27,30 @@ ## 0.7.0 | ||
- 19b567f21: Unified self- and delegated staking flows. Removed fields from `Validator` (`stake_amount`, `pending_stake`, and `pending_withdraw`) and renamed `delegation_staking_pool` to `staking_pool`. Additionally removed the `validator_stake` and `delegated_stake` fields in the `ValidatorSet` type and replaced them with a `total_stake` field. | ||
- 5c3b00cde: Add object id to staking pool and pool id to staked sui. | ||
- 3d9a04648: Adds `deactivation_epoch` to staking pool object, and adds `inactive_pools` to the validator set object. | ||
- a8049d159: Fixes the issue with deep nested generics by introducing array type names | ||
- 19b567f21: Unified self- and delegated staking flows. Removed fields from `Validator` (`stake_amount`, `pending_stake`, and `pending_withdraw`) and renamed `delegation_staking_pool` to `staking_pool`. Additionally removed the `validator_stake` and `delegated_stake` fields in the `ValidatorSet` type and replaced them with a `total_stake` field. | ||
- 5c3b00cde: Add object id to staking pool and pool id to staked sui. | ||
- 3d9a04648: Adds `deactivation_epoch` to staking pool object, and adds `inactive_pools` to the validator set object. | ||
- a8049d159: Fixes the issue with deep nested generics by introducing array type names | ||
- all of the methods (except for aliasing) now allow passing in arrays instead | ||
of strings to allow for easier composition of generics and avoid using template | ||
strings | ||
- all of the methods (except for aliasing) now allow passing in arrays instead | ||
of strings to allow for easier composition of generics and avoid using template | ||
strings | ||
```js | ||
// new syntax | ||
bcs.registerStructType(["VecMap", "K", "V"], { | ||
keys: ["vector", "K"], | ||
values: ["vector", "V"], | ||
}); | ||
```js | ||
// new syntax | ||
bcs.registerStructType(['VecMap', 'K', 'V'], { | ||
keys: ['vector', 'K'], | ||
values: ['vector', 'V'], | ||
}); | ||
// is identical to an old string definition | ||
bcs.registerStructType("VecMap<K, V>", { | ||
keys: "vector<K>", | ||
values: "vector<V>", | ||
}); | ||
``` | ||
// is identical to an old string definition | ||
bcs.registerStructType('VecMap<K, V>', { | ||
keys: 'vector<K>', | ||
values: 'vector<V>', | ||
}); | ||
``` | ||
Similar approach applies to `bcs.ser()` and `bcs.de()` as well as to other register\* methods | ||
Similar approach applies to `bcs.ser()` and `bcs.de()` as well as to other register\* methods | ||
- a0955c479: Switch from 20 to 32-byte address. Match Secp256k1.deriveKeypair with Ed25519. | ||
- 0a7b42a6d: This changes almost all occurences of "delegate", "delegation" (and various capitalizations/forms) to their equivalent "stake"-based name. Function names, function argument names, RPC endpoints, Move functions, and object fields have been updated with this new naming convention. | ||
- 77bdf907f: When parsing u64, u128, and u256 values with bcs, they are now string encoded. | ||
- a0955c479: Switch from 20 to 32-byte address. Match Secp256k1.deriveKeypair with Ed25519. | ||
- 0a7b42a6d: This changes almost all occurences of "delegate", "delegation" (and various capitalizations/forms) to their equivalent "stake"-based name. Function names, function argument names, RPC endpoints, Move functions, and object fields have been updated with this new naming convention. | ||
- 77bdf907f: When parsing u64, u128, and u256 values with bcs, they are now string encoded. | ||
@@ -55,3 +61,3 @@ ## 0.6.1 | ||
- 0e202a543: Remove pending delegation switches. | ||
- 0e202a543: Remove pending delegation switches. | ||
@@ -62,11 +68,11 @@ ## 0.6.0 | ||
// new syntax | ||
bcs.registerStructType(["VecMap", "K", "V"], { | ||
keys: ["vector", "K"], | ||
values: ["vector", "V"], | ||
bcs.registerStructType(['VecMap', 'K', 'V'], { | ||
keys: ['vector', 'K'], | ||
values: ['vector', 'V'], | ||
}); | ||
// is identical to an old string definition | ||
bcs.registerStructType("VecMap<K, V>", { | ||
keys: "vector<K>", | ||
values: "vector<V>", | ||
bcs.registerStructType('VecMap<K, V>', { | ||
keys: 'vector<K>', | ||
values: 'vector<V>', | ||
}); | ||
@@ -77,14 +83,14 @@ ``` | ||
- 598f106ef: Adds base58 encoding support to bcs | ||
- 598f106ef: Adds base58 encoding support to bcs | ||
- two functions added: `fromB58` and `toB58` similar to existing encodings | ||
- `Reader.toString` and `de/encodeStr` methods support new `base58` value | ||
- adds a 3 built-in types "hex-string", "base58-string" and "base64-string" | ||
- adds constants for the built-ins: `BCS.BASE64`, `BCS.BASE58` and `BCS.HEX` | ||
- two functions added: `fromB58` and `toB58` similar to existing encodings | ||
- `Reader.toString` and `de/encodeStr` methods support new `base58` value | ||
- adds a 3 built-in types "hex-string", "base58-string" and "base64-string" | ||
- adds constants for the built-ins: `BCS.BASE64`, `BCS.BASE58` and `BCS.HEX` | ||
```js | ||
bcs.registerStructType("TestStruct", { | ||
hex: BCS.HEX, | ||
base58: BCS.BASE58, | ||
base64: BCS.BASE64, | ||
bcs.registerStructType('TestStruct', { | ||
hex: BCS.HEX, | ||
base58: BCS.BASE58, | ||
base64: BCS.BASE64, | ||
}); | ||
@@ -95,4 +101,4 @@ ``` | ||
- adds new `registerAlias` function which allows type aliases and tracks basic recursion | ||
- adds support for inline definitions in the `.de()` and `.ser()` methods | ||
- adds new `registerAlias` function which allows type aliases and tracks basic recursion | ||
- adds support for inline definitions in the `.de()` and `.ser()` methods | ||
@@ -103,5 +109,5 @@ ### Examples | ||
// inline definition example | ||
let struct = { name: "Alice", age: 25 }; | ||
let bytes = bcs.ser({ name: "string", age: "u8" }, struct).toBytes(); | ||
let restored = bcs.de({ name: "string", age: "u8" }, bytes); | ||
let struct = { name: 'Alice', age: 25 }; | ||
let bytes = bcs.ser({ name: 'string', age: 'u8' }, struct).toBytes(); | ||
let restored = bcs.de({ name: 'string', age: 'u8' }, bytes); | ||
@@ -113,4 +119,4 @@ // `restored` deeply equals `struct` | ||
// aliases for types | ||
bcs.registerAlias("Name", "string"); | ||
bcs.ser("Name", "Palpatine"); | ||
bcs.registerAlias('Name', 'string'); | ||
bcs.ser('Name', 'Palpatine'); | ||
``` | ||
@@ -122,3 +128,3 @@ | ||
- 1a0968636: Remove usage of bn.js, and use native bigints instead. | ||
- 1a0968636: Remove usage of bn.js, and use native bigints instead. | ||
@@ -129,7 +135,7 @@ ## 0.4.0 | ||
- 1591726e8: Support multiple instances of BCS | ||
- 1591726e8: Support multiple instances of BCS | ||
### Patch Changes | ||
- 1591726e8: Add support for generic types | ||
- 1591726e8: Add support for generic types | ||
@@ -140,3 +146,3 @@ ## 0.3.0 | ||
- d343b67e: Re-release packages | ||
- d343b67e: Re-release packages | ||
@@ -147,4 +153,4 @@ ## 0.2.1 | ||
- c5e4851b: Updated build process from TSDX to tsup. | ||
- e2aa08e9: Fix missing built files for packages. | ||
- c5e4851b: Updated build process from TSDX to tsup. | ||
- e2aa08e9: Fix missing built files for packages. | ||
@@ -155,5 +161,5 @@ Version history from v0.1.0 to this day. | ||
- `bcs.de(...)` now supports strings if encoding is passed as the last argument | ||
- `BCS` (upper) -> `bcs` (lower) renaming | ||
- Improved documentation, checked documentation examples for failures | ||
- `bcs.de(...)` now supports strings if encoding is passed as the last argument | ||
- `BCS` (upper) -> `bcs` (lower) renaming | ||
- Improved documentation, checked documentation examples for failures | ||
@@ -160,0 +166,0 @@ ## v0.1.0 |
@@ -567,1 +567,2 @@ import { toB64, fromB64 } from "./b64"; | ||
export declare function getSuiMoveConfig(): BcsConfig; | ||
export declare function splitGenericParameters(str: string, genericSeparators?: [string, string]): string[]; |
@@ -44,2 +44,3 @@ "use strict"; | ||
registerPrimitives: () => registerPrimitives, | ||
splitGenericParameters: () => splitGenericParameters, | ||
toB58: () => toB58, | ||
@@ -1108,3 +1109,6 @@ toB64: () => toB64, | ||
let typeName = name.slice(0, l_bound); | ||
let params = name.slice(l_bound + 1, name.length - r_bound - 1).split(",").map((e) => e.trim()); | ||
let params = splitGenericParameters( | ||
name.slice(l_bound + 1, name.length - r_bound - 1), | ||
this.schema.genericSeparators | ||
); | ||
return { name: typeName, params }; | ||
@@ -1292,2 +1296,25 @@ } | ||
} | ||
function splitGenericParameters(str, genericSeparators = ["<", ">"]) { | ||
const [left, right] = genericSeparators; | ||
const tok = []; | ||
let word = ""; | ||
let nestedAngleBrackets = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str[i]; | ||
if (char === left) { | ||
nestedAngleBrackets++; | ||
} | ||
if (char === right) { | ||
nestedAngleBrackets--; | ||
} | ||
if (nestedAngleBrackets === 0 && char === ",") { | ||
tok.push(word.trim()); | ||
word = ""; | ||
continue; | ||
} | ||
word += char; | ||
} | ||
tok.push(word.trim()); | ||
return tok; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1306,2 +1333,3 @@ 0 && (module.exports = { | ||
registerPrimitives, | ||
splitGenericParameters, | ||
toB58, | ||
@@ -1308,0 +1336,0 @@ toB64, |
{ | ||
"name": "@mysten/bcs", | ||
"version": "0.0.0-experimental-20230613234133", | ||
"version": "0.0.0-experimental-20230615203750", | ||
"description": "BCS - Canonical Binary Serialization implementation for JavaScript", | ||
@@ -54,3 +54,3 @@ "license": "Apache-2.0", | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.30.1" | ||
"vitest": "^0.32.0" | ||
}, | ||
@@ -57,0 +57,0 @@ "dependencies": { |
@@ -1425,6 +1425,6 @@ // Copyright (c) Mysten Labs, Inc. | ||
let typeName = name.slice(0, l_bound); | ||
let params = name | ||
.slice(l_bound + 1, name.length - r_bound - 1) | ||
.split(",") | ||
.map((e) => e.trim()); | ||
let params = splitGenericParameters( | ||
name.slice(l_bound + 1, name.length - r_bound - 1), | ||
this.schema.genericSeparators | ||
); | ||
@@ -1631,1 +1631,28 @@ return { name: typeName, params }; | ||
} | ||
export function splitGenericParameters(str: string, genericSeparators: [string, string] = ["<", ">"]) { | ||
const [left, right] = genericSeparators; | ||
const tok = []; | ||
let word = ""; | ||
let nestedAngleBrackets = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str[i]; | ||
if (char === left) { | ||
nestedAngleBrackets++; | ||
} | ||
if (char === right) { | ||
nestedAngleBrackets--; | ||
} | ||
if (nestedAngleBrackets === 0 && char === ',') { | ||
tok.push(word.trim()); | ||
word = ''; | ||
continue; | ||
} | ||
word += char; | ||
} | ||
tok.push(word.trim()); | ||
return tok; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
370859
6122