Skip to content

Commit ae06bd6

Browse files
authored
Merge pull request #332 from near/0.7-release
0.7 release
2 parents 263c969 + 9a79166 commit ae06bd6

File tree

10 files changed

+139
-69
lines changed

10 files changed

+139
-69
lines changed

Diff for: RELEASE.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Release
2+
3+
This document describes step to do a new pre-release or formal release.
4+
5+
## Release Requirement
6+
- A formal release must be directly bump from a tested, DevRel Team approved pre-release, with no commits other than bump the version.
7+
- Pre-release can come with arbitrary commits to fix packaging and update documentations. Several pre-release can be released before a formal release to fix issues and address feedbacks.
8+
9+
## Steps for pre-release
10+
1. Create a new branch for the release.
11+
2. Bump version in packages/near-sdk-js/package.json and packages/near-contract-standards/package.json to the version about to release. It should be `x.y.z-0`, and next pre-release `x.y.z-1`, etc.
12+
3. Run `pnpm publish` in packages/near-sdk-js and in packages/near-contract-standards.
13+
4. Copy examples folder in this repo to another place, drop `node_modules`, change its package.json from:
14+
```
15+
"near-contract-standards": "workspace:*",
16+
"near-sdk-js": "workspace:*",
17+
```
18+
to the version you just released, e.g. `x.y.z-1`.
19+
5. Build and run example tests to ensure the packaging is correct.
20+
6. If it works, go to https://github.com/near/near-sdk-js/releases/new, create a tag for the new release from the branch you created in step 1, and write the release highlights.
21+
7. Ask the DevRel team to test the pre-release.
22+
23+
## Steps for formal release
24+
1. Create a new release branch from the candidate pre-release branch
25+
2. Bump version in packages/near-sdk-js/package.json and packages/near-contract-standards/package.json to the version about to release. It should be `x.y.z`.
26+
3. Run `pnpm publish` in packages/near-sdk-js and in packages/near-contract-standards.
27+
4. Go to https://github.com/near/near-sdk-js/releases/new, create a tag for the new release branch from the branch you created in step 1, and copy the highlights from latest pre-release candidate.
28+
5. Advertise it to the community!

Diff for: packages/near-contract-standards/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "near-contract-standards",
3-
"version": "1.0.0",
3+
"version": "0.7.0",
44
"description": "Compatible near-contract-standards implementation in JS",
55
"main": "index.js",
66
"type": "module",

Diff for: packages/near-sdk-js/README.md

+70-45
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ When call host function with inappropriate type, means incorrect number of argum
6060
- if argument is different than the required type, it'll be coerced to required type
6161
- if argument is different than the required type but cannot be coerced, will throw runtime type error, also with message and stacktrace
6262

63+
## Migrating from near-sdk-js 0.6.0
64+
65+
If you have a near-sdk-js 0.6.0 contract, you need to drop the `babel.config.json` because it is now inlined in near-sdk-js CLI.
66+
67+
Also `Bytes` type in 0.6.0 is replaced with `string` and `Uint8Array`. Because `Bytes` was an alias to `string`, this doesn't affect all collection APIs and most low level APIs. Some low level APIs below now also comes with a raw version, which ends with `Raw` and takes `Uint8Array` instead of `string`, for example, `storageRead` vs `storageReadRaw`. Some low level APIs have more sense to use `Uint8Array` instead of `string`, such as `sha256` and arguments for a function call type of promise, these are **BREAKING** changes. Please refer to next section for details: look for functions with `Uint8Array` argument and return types.
68+
6369
## NEAR-SDK-JS API Reference
6470

6571
All NEAR blockchain provided functionality (host functions) are defined in `src/api.ts` and exported as `near`. You can use them by:
@@ -83,18 +89,17 @@ pnpm build
8389
NEAR-SDK-JS is written in TypeScript, so every API function has a type specified by signature that looks familiar to JavaScript/TypeScript Developers. Two types in the signature need a special attention:
8490

8591
- Most of the API take `bigint` instead of Number as type. This because JavaScript Number cannot hold 64 bit and 128 bit integer without losing precision.
86-
- `Bytes` in both arguments and return represent a byte buffer, internally it's a JavaScript String Object. Any binary data `0x00-0xff` is stored as the char '\x00-\xff'. This is because QuickJS doesn't have Uint8Array in C API.
87-
- To ensure correctness, every `Bytes` argument need to be pass in with the `bytes()` function to runtime type check it's indeed a `Bytes`.
88-
- If `Bytes` is too long that `bytes()` can cause gas limit problem, such as in factory contract, represents the content of contract to be deployed. In this case you can precheck and guarantee the correctness of the content and use without `bytes()`.
92+
- For those API that takes or returns raw bytes, it is a JavaScript `Uint8Array`. You can use standard `Uint8Array` methods on it or decode it to string with `decode` or `str`. The differece between `decode` and `str` is: `decode` decode the array as UTF-8 sequence. `str` simply converts each Uint8 to one char with that char code.
8993

9094
### Context API
9195

9296
```
9397
function currentAccountId(): string;
9498
function signerAccountId(): string;
95-
function signerAccountPk(): Bytes;
99+
function signerAccountPk(): Uint8Array;
96100
function predecessorAccountId(): string;
97-
function input(): Bytes;
101+
function inputRaw(): Uint8Array;
102+
function input(): string;
98103
function blockIndex(): bigint;
99104
function blockHeight(): bigint;
100105
function blockTimestamp(): bigint;
@@ -115,30 +120,32 @@ function usedGas(): bigint;
115120
### Math API
116121

117122
```
118-
function randomSeed(): Bytes;
119-
function sha256(value: Bytes): Bytes;
120-
function keccak256(value: Bytes): Bytes;
121-
function keccak512(value: Bytes): Bytes;
122-
function ripemd160(value: Bytes): Bytes;
123-
function ecrecover(hash: Bytes, sign: Bytes, v: bigint, malleability_flag: bigint): Bytes | null;
123+
function randomSeed(): Uint8Array;
124+
function sha256(value: Uint8Array): Uint8Array;
125+
function keccak256(value: Uint8Array): Uint8Array;
126+
function keccak512(value: Uint8Array): Uint8Array;
127+
function ripemd160(value: Uint8Array): Uint8Array;
128+
function ecrecover(hash: Uint8Array, sign: Uint8Array, v: bigint, malleability_flag: bigint): Uint8Array | null;
124129
```
125130

126131
### Miscellaneous API
127132

128133
```
129-
function valueReturn(value: Bytes);
134+
function valueReturnRaw(value: Uint8Array);
135+
function valueReturn(value: string);
130136
function panic(msg?: string);
131-
function panicUtf8(msg: Bytes);
132-
function log(msg: string);
133-
function logUtf8(msg: Bytes);
134-
function logUtf16(msg: Bytes);
137+
function panicUtf8(msg: Uint8Array);
138+
function logUtf8(msg: Uint8Array);
139+
function logUtf16(msg: Uint8Array);
140+
function log(...params: unknown[]);
141+
135142
```
136143

137144
### Promises API
138145

139146
```
140-
function promiseCreate(account_id: string, method_name: string, arguments: Bytes, amount: bigint, gas: bigint): bigint;
141-
function promiseThen(promise_index: bigint, account_id: string, method_name: string, arguments: Bytes, amount: bigint, gas: bigint): bigint;
147+
function promiseCreate(account_id: string, method_name: string, arguments: Uint8Array, amount: bigint, gas: bigint): bigint;
148+
function promiseThen(promise_index: bigint, account_id: string, method_name: string, arguments: Uint8Array, amount: bigint, gas: bigint): bigint;
142149
function promiseAnd(...promise_idx: bigint): bigint;
143150
function promiseBatchCreate(account_id: string): bigint;
144151
function promiseBatchThen(promise_index: bigint, account_id: string): bigint;
@@ -147,34 +154,38 @@ function promiseBatchThen(promise_index: bigint, account_id: string): bigint;
147154
### Promise API actions
148155

149156
```
150-
function promiseBatchActionCreateAccount(promise_index: bigint);
151-
function promiseBatchActionDeployContract(promise_index: bigint, code: Bytes);
152-
function promiseBatchActionFunctionCall(promise_index: bigint, method_name: string, arguments: Bytes, amount: bigint, gas: bigint);
153-
function promiseBatchActionFunctionCallWeight(promise_index: bigint, method_name: string, arguments: Bytes, amount: bigint, gas: bigint, weight: bigint);
154-
155-
function promiseBatchActionTransfer(promise_index: bigint, amount: bigint);
156-
function promiseBatchActionStake(promise_index: bigint, amount: bigint, public_key: Bytes);
157-
function promiseBatchActionAddKeyWithFullAccess(promise_index: bigint, public_key: Bytes, nonce: bigint);
158-
function promiseBatchActionAddKeyWithFunctionCall(promise_index: bigint, public_key: Bytes, nonce: bigint, allowance: bigint, receiver_id: string, method_names: string);
159-
function promiseBatchActionDeleteKey(promise_index: bigint, public_key: Bytes);
160-
function promiseBatchActionDeleteAccount(promise_index: bigint, beneficiary_id: string);
157+
function promiseBatchActionCreateAccount(promise_index: PromiseIndex);
158+
function promiseBatchActionDeployContract(promise_index: PromiseIndex, code: Uint8Array);
159+
function promiseBatchActionFunctionCall(promise_index: PromiseIndex, method_name: string, arguments: Uint8Array, amount: bigint, gas: bigint);
160+
function promiseBatchActionFunctionCallWeight(promise_index: PromiseIndex, method_name: string, arguments: Uint8Array, amount: bigint, gas: bigint, weight: bigint);
161+
function promiseBatchActionTransfer(promise_index: PromiseIndex, amount: bigint);
162+
function promiseBatchActionStake(promise_index: PromiseIndex, amount: bigint, public_key: Uint8Array);
163+
function promiseBatchActionAddKeyWithFullAccess(promise_index: PromiseIndex, public_key: Uint8Array, nonce: bigint);
164+
function promiseBatchActionAddKeyWithFunctionCall(promise_index: PromiseIndex, public_key: Uint8Array, nonce: bigint, allowance: bigint, receiver_id: string, method_names: string);
165+
function promiseBatchActionDeleteKey(promise_index: PromiseIndex, public_key: Uint8Array);
166+
function promiseBatchActionDeleteAccount(promise_index: PromiseIndex, beneficiary_id: string);
161167
```
162168

163169
### Promise API results
164170

165171
```
166172
function promiseResultsCount(): bigint;
167-
function promiseResult(result_idx: bigint, register_id: bigint): bigint;
168-
function promiseReturn(promise_idx: bigint);
173+
function promiseResultRaw(result_idx: PromiseIndex): Uint8Array;
174+
function promiseResult(result_idx: PromiseIndex): string;
175+
function promiseReturn(promise_idx: PromiseIndex);
169176
```
170177

171178
### Storage API
172179

173180
```
174-
function storageWrite(key: Bytes, value: Bytes, register_id: bigint): bigint;
175-
function storageRead(key: Bytes, register_id: bigint): bigint;
176-
function storageRemove(key: Bytes, register_id: bigint): bigint;
177-
function storageHasKey(key: Bytes): bigint;
181+
function storageWriteRaw(key: Uint8Array, value: Uint8Array): boolean;
182+
function storageReadRaw(key: Uint8Array): Uint8Array | null;
183+
function storageRemoveRaw(key: Uint8Array): boolean;
184+
function storageHasKeyRaw(key: Uint8Array): boolean;
185+
function storageWrite(key: string, value: string): boolean;
186+
function storageRead(key: string): bigint;
187+
function storageRemove(key: string): bigint;
188+
function storageHasKey(key: string): bigint;
178189
```
179190

180191
### Validator API
@@ -187,9 +198,9 @@ function validatorTotalStake(): bigint;
187198
### Alt BN128
188199

189200
```
190-
function altBn128G1Multiexp(value: Bytes, register_id: bigint);
191-
function altBn128G1Sum(value: Bytes, register_id: bigint);
192-
function altBn128PairingCheck(value: Bytes): bigint;
201+
function altBn128G1Multiexp(value: Uint8Array): Uint8Array;
202+
function altBn128G1Sum(value: Uint8Array): Uint8Array;
203+
function altBn128PairingCheck(value: Uint8Array): boolean;
193204
```
194205

195206
### NearBindgen and other decorators
@@ -225,7 +236,7 @@ In order to initialize the contract, you need to add functions flagged with `@in
225236

226237
### Collections
227238

228-
A few useful on-chain persistent collections are provided. All keys, values and elements are of type `Bytes`.
239+
A few useful on-chain persistent collections are provided. All keys, values and elements are of type `string`.
229240

230241
#### Vector
231242

@@ -532,21 +543,35 @@ return promise;
532543

533544
### Types
534545

535-
NEAR-SDK-JS also includes type defintions that are equivalent to that in Rust SDK / nearcore. You can browse them in near-sdk-js/src/types. Most of them are just type alias to Bytes and bigint.
546+
NEAR-SDK-JS also includes type defintions that are equivalent to that in Rust SDK / nearcore. You can browse them in near-sdk-js/src/types. Most of them are just type alias to string and bigint.
536547

537548
#### Public Key
538549

539550
Public Key is representing a NEAR account's public key in a JavaScript class. You can either initiate a Public Key from binary data, or from a human readable string.
540551

541-
The binary data is in the same format as nearcore, but encoded in bytes. That's one byte to represent the curve type of the public key, either ed25519 (`\x00`), or secp256k1 ('\x01'), follows by the curve-specific public key data in bytes. Examples:
552+
The binary data is in the same format as nearcore in `Uint8Array`. That's one byte to represent the curve type of the public key, either ed25519 (`0x0`), or secp256k1 (`0x1`), follows by the curve-specific public key data in bytes. Examples:
542553

543554
```js
544555
new PublicKey(near.signerAccountPk());
545-
new PublicKey(
546-
"\x00\xeb\x7f\x5f\x11\xd1\x08\x1f\xe0\xd2\x24\xc5\x67\x36\x21\xad\xcb\x97\xd5\x13\xff\xa8\x5e\x55\xbc\x2b\x74\x4f\x0d\xb1\xe9\xf8\x1f"
556+
let pk = new PublicKey(
557+
new Uint8Array([
558+
// CurveType.ED25519 = 0
559+
0,
560+
// ED25519 PublicKey data
561+
186, 44, 216, 49, 157, 48, 151, 47, 23, 244, 137, 69, 78, 150, 54, 42, 30, 248,
562+
110, 26, 205, 18, 137, 154, 10, 208, 26, 183, 65, 166, 223, 18,
563+
])
547564
);
548-
new PublicKey(
549-
"\x01\xf2\x56\xc6\xe6\xc8\x0b\x21\x3f\x2a\xa0\xb0\x17\x44\x23\x5d\x51\x5c\x59\x44\x35\xbe\x65\x1b\x15\x88\x3a\x10\xdd\x47\x2f\xa6\x46\xce\x62\xea\xf3\x67\x0d\xc5\xcb\x91\x00\xa0\xca\x2a\x55\xb2\xc1\x47\xc1\xe9\xa3\x8c\xe4\x28\x87\x8e\x7d\x46\xe1\xfb\x71\x4a\x99"
565+
let pk = new PublicKey(
566+
new Uint8Array([
567+
// CurveType.SECP256K1 = 1
568+
1,
569+
// SECP256K1 PublicKey data
570+
242, 86, 198, 230, 200, 11, 33, 63, 42, 160, 176, 23, 68, 35, 93, 81, 92, 89,
571+
68, 53, 190, 101, 27, 21, 136, 58, 16, 221, 71, 47, 166, 70, 206, 98, 234, 243,
572+
103, 13, 197, 203, 145, 0, 160, 202, 42, 85, 178, 193, 71, 193, 233, 163, 140,
573+
228, 40, 135, 142, 125, 70, 225, 251, 113, 74, 153,
574+
])
550575
);
551576
```
552577

Diff for: packages/near-sdk-js/lib/cli/abi.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/near-sdk-js/lib/cli/cli.d.ts

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/near-sdk-js/lib/cli/cli.js

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/near-sdk-js/package.json

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "near-sdk-js",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "High Level JavaScript SDK for building smart contracts on NEAR",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -32,31 +32,37 @@
3232
},
3333
"author": "Near Inc <[email protected]>",
3434
"dependencies": {
35+
"@babel/core": "^7.20.5",
3536
"@babel/plugin-proposal-decorators": "^7.17.2",
3637
"@babel/preset-typescript": "^7.18.6",
37-
"@babel/core": "^7.20.5",
3838
"@babel/types": "^7.20.5",
3939
"@rollup/plugin-babel": "^5.3.1",
4040
"@rollup/plugin-commonjs": "^21.0.1",
4141
"@rollup/plugin-node-resolve": "^13.1.1",
4242
"@scure/base": "^1.1.1",
4343
"@types/estree": "^1.0.0",
44+
"@typescript-eslint/eslint-plugin": "^5.31.0",
45+
"@typescript-eslint/parser": "^5.31.0",
4446
"commander": "^9.4.1",
47+
"eslint": "^8.20.0",
48+
"json-schema": "0.4.0",
4549
"near-abi": "^0.1.0",
50+
"near-typescript-json-schema": "0.55.0",
4651
"rollup": "^2.61.1",
4752
"rollup-plugin-sourcemaps": "^0.6.3",
4853
"signale": "^1.4.0",
4954
"ts-morph": "^16.0.0",
50-
"typescript": "~4.7.2",
51-
"near-typescript-json-schema": "0.55.0",
52-
"json-schema": "0.4.0",
53-
"@typescript-eslint/eslint-plugin": "^5.31.0",
54-
"@typescript-eslint/parser": "^5.31.0",
55-
"eslint": "^8.20.0"
55+
"typescript": "~4.7.2"
5656
},
5757
"files": [
5858
"builder",
59-
"lib"
59+
"lib/*.js",
60+
"lib/*.d.ts",
61+
"lib/collections/*",
62+
"lib/types/*",
63+
"lib/cli/*.js",
64+
"lib/cli/*.d.ts",
65+
"lib/cli/build-tools/*"
6066
],
6167
"devDependencies": {
6268
"@rollup/plugin-typescript": "^8.3.2",
@@ -71,6 +77,7 @@
7177
"chalk": "^5.1.0",
7278
"eslint": "^8.23.1",
7379
"eslint-config-prettier": "^8.5.0",
80+
"json5": "^2.2.3",
7481
"npm-run-all": "^4.1.5",
7582
"prettier": "^2.7.1",
7683
"typescript": "^4.7.2"

Diff for: packages/near-sdk-js/src/cli/abi.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import ts, { ClassDeclaration, Decorator, NodeArray } from "typescript";
2+
import JSON5 from 'json5';
23
import * as abi from "near-abi";
34
import * as TJS from "near-typescript-json-schema";
45
import { JSONSchema7 } from "json-schema";
56
import * as fs from "fs";
67
import { LIB_VERSION } from "../version.js";
78

89
function parseMetadata(packageJsonPath: string): abi.AbiMetadata {
9-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
10+
const packageJson = JSON5.parse(fs.readFileSync(packageJsonPath, "utf8"));
1011

1112
let authors: string[] = [];
1213
if (packageJson["author"]) authors.push(packageJson["author"]);
@@ -71,7 +72,7 @@ export function runAbiCompilerPlugin(
7172
packageJsonPath: string,
7273
tsConfigJsonPath: string
7374
) {
74-
const tsConfig = JSON.parse(fs.readFileSync(tsConfigJsonPath, "utf8"));
75+
const tsConfig = JSON5.parse(fs.readFileSync(tsConfigJsonPath, "utf8"));
7576
const program = getProgramFromFiles([tsFile], tsConfig["compilerOptions"]);
7677
const typeChecker = program.getTypeChecker();
7778

0 commit comments

Comments
 (0)