Skip to content

Commit

Permalink
Merge pull request #3500 from greymistcube/port/3.6.1-to-3.7.1
Browse files Browse the repository at this point in the history
🔀 Port 3.6.1 to 3.7.1
  • Loading branch information
greymistcube authored Nov 20, 2023
2 parents 14419c5 + 4423414 commit 488a305
Show file tree
Hide file tree
Showing 35 changed files with 2,566 additions and 2,648 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/yarn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
node-version: [19] # TODO: Add LTS
node-version: ['lts/*']
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"typescript.enablePromptUseWorkspaceTsdk": true,
"eslint.nodePath": ".yarn/sdks",
"[typescript]": {
"editor.defaultFormatter": "rome.rome",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.rome": true
Expand Down
9 changes: 0 additions & 9 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

This file was deleted.

28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

873 changes: 0 additions & 873 deletions .yarn/releases/yarn-3.4.1.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.1.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarn/sdks/typescript/lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const moduleWrapper = tsserver => {
str = `zip:${str}`;
} break;
}
} else {
str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`);
}
}

Expand Down
2 changes: 2 additions & 0 deletions .yarn/sdks/typescript/lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const moduleWrapper = tsserver => {
str = `zip:${str}`;
} break;
}
} else {
str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions .yarn/sdks/typescript/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const absRequire = createRequire(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/lib/typescript.js
// Setup the environment to be able to require typescript
require(absPnpApiPath).setup();
}
}

// Defer to the real typescript/lib/typescript.js your application uses
module.exports = absRequire(`typescript/lib/typescript.js`);
// Defer to the real typescript your application uses
module.exports = absRequire(`typescript`);
8 changes: 6 additions & 2 deletions .yarn/sdks/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"name": "typescript",
"version": "4.9.5-sdk",
"version": "5.2.2-sdk",
"main": "./lib/typescript.js",
"type": "commonjs"
"type": "commonjs",
"bin": {
"tsc": "./bin/tsc",
"tsserver": "./bin/tsserver"
}
}
10 changes: 4 additions & 6 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
compressionLevel: mixed

yarnPath: .yarn/releases/yarn-3.4.1.cjs
enableGlobalCache: false

yarnPath: .yarn/releases/yarn-4.0.1.cjs
21 changes: 17 additions & 4 deletions @planetarium/account-aws-kms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
"description": "Libplanet account implementation using AWS KMS",
"type": "module",
"main": "./dist/index.js",
"imports": {
"#crypto": {
"node": "./src/crypto/node.ts",
"default": "./src/crypto/browser.ts"
}
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"node": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"browser": "./dist/index.browser.mjs",
"default": "./dist/index.js"
}
},
"files": [
Expand Down Expand Up @@ -37,7 +47,7 @@
"@vitest/coverage-c8": "^0.29.3",
"@vitest/ui": "^0.29.3",
"es-aggregate-error": "^1.0.9",
"nanobundle": "^1.5.0",
"nanobundle": "^1.6.0",
"vite": "^4.1.1",
"vitest": "^0.29.3"
},
Expand All @@ -48,5 +58,8 @@
},
"peerDependencies": {
"@planetarium/account": "workspace:^"
},
"engines": {
"node": ">=19.0.0"
}
}
7 changes: 6 additions & 1 deletion @planetarium/account-aws-kms/src/AwsKmsAccount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AwsKmsKeyId } from "./AwsKmsKeyId.js";
import { KMSClient, SignCommand } from "@aws-sdk/client-kms";
import { Signature as NobleSignature } from "@noble/secp256k1";
import { crypto } from "#crypto";
import {
Address,
type Account,
Expand Down Expand Up @@ -36,9 +37,13 @@ export class AwsKmsAccount implements Account {
}

async sign(message: Message): Promise<Signature> {
const digest = await crypto.subtle.digest("SHA-256", message);
const digestArray = new Uint8Array(digest);

const cmd = new SignCommand({
KeyId: this.keyId,
Message: message,
Message: digestArray,
MessageType: "DIGEST",
SigningAlgorithm: "ECDSA_SHA_256",
});
const response = await this.#client.send(cmd);
Expand Down
5 changes: 5 additions & 0 deletions @planetarium/account-aws-kms/src/crypto/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare const globalThis: Record<string, any> | undefined;
export const crypto =
typeof globalThis === "object" && "crypto" in globalThis
? globalThis.crypto
: undefined;
6 changes: 6 additions & 0 deletions @planetarium/account-aws-kms/src/crypto/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as nc from "node:crypto";
export const crypto =
nc && typeof nc === "object" && "webcrypto" in nc
? // rome-ignore lint/suspicious/noExplicitAny: false
(nc.webcrypto as any)
: undefined;
8 changes: 5 additions & 3 deletions @planetarium/account-aws-kms/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"include": ["./src", "*.d.ts", "*.ts"],
"include": ["./src", "*.d.ts", "src/*.ts"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "dist",
"target": "ES2020",
"target": "ES2022",
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"lib": ["ES2020"]
"lib": ["ES2022"]
}
}
3 changes: 3 additions & 0 deletions @planetarium/account-aws-kms/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export default defineConfig({
test: {
cache: false,
testTimeout: 30000,
alias: {
"#crypto": "./src/crypto/node.ts",
},
},
});
2 changes: 1 addition & 1 deletion @planetarium/account-web3-secret-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@vitest/coverage-c8": "^0.29.2",
"@vitest/ui": "^0.29.2",
"fast-check": "^3.8.0",
"nanobundle": "^1.5.0",
"nanobundle": "^1.6.0",
"stream-buffers": "^3.0.2",
"vite": "^4.1.4",
"vitest": "^0.29.2"
Expand Down
2 changes: 1 addition & 1 deletion @planetarium/account-web3-secret-storage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "nodenext",
"module": "ESNext",
"module": "NodeNext",
"lib": ["ESNext", "DOM"]
}
}
2 changes: 1 addition & 1 deletion @planetarium/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@vitest/coverage-c8": "^0.29.2",
"@vitest/ui": "^0.29.2",
"fast-check": "^3.1.2",
"nanobundle": "^1.5.0",
"nanobundle": "^1.6.0",
"vite": "^4.1.1",
"vitest": "^0.29.2"
},
Expand Down
3 changes: 2 additions & 1 deletion @planetarium/account/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"include": ["./src", "*.d.ts", "*.ts"],
"compilerOptions": {
"outDir": "dist",
"target": "ES2020",
"target": "ES2022",
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"module": "nodenext",
"moduleResolution": "nodenext"
},
}
2 changes: 1 addition & 1 deletion @planetarium/tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@vitest/ui": "^0.29.2",
"execa": "^6.1.0",
"fast-check": "^3.1.2",
"nanobundle": "^1.5.0",
"nanobundle": "^1.6.0",
"vite": "^4.1.3",
"vitest": "^0.29.2"
},
Expand Down
8 changes: 4 additions & 4 deletions @planetarium/tx/src/tx/signed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ export type SignedTx<T extends UnsignedTx> = T & { signature: Signature };

export async function signTx(
tx: UnsignedTx,
signAccount: Account,
signAccount: Account
): Promise<SignedTx<typeof tx>> {
if (
!bytesEqual(
tx.publicKey,
(await signAccount.getPublicKey()).toBytes("uncompressed"),
(await signAccount.getPublicKey()).toBytes("uncompressed")
)
) {
throw new Error("Public keys in the tx and the signAccount are mismatched");
} else if (
!bytesEqual(
tx.signer,
Address.deriveFrom(await signAccount.getPublicKey()).toBytes(),
Address.deriveFrom(await signAccount.getPublicKey()).toBytes()
)
) {
throw new Error("The transaction signer does not match to the signAccount");
Expand All @@ -35,7 +35,7 @@ export async function signTx(
}

export function encodeSignedTx<T extends UnsignedTx>(
tx: SignedTx<T>,
tx: SignedTx<T>
): Dictionary {
const dict = encodeUnsignedTx(tx);
const sig = tx.signature.toBytes();
Expand Down
3 changes: 2 additions & 1 deletion @planetarium/tx/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"include": ["./src", "*.d.ts", "*.ts"],
"compilerOptions": {
"outDir": "dist",
"target": "ES2020",
"target": "ES2022",
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Version 3.7.1

To be released.

- Ported changes from [Libplanet 3.6.1] release. [[#3500]]

[Libplanet 2.0.1]: https://www.nuget.org/packages/Libplanet/3.6.1
[#3500]: https://github.com/planetarium/libplanet/3500


Version 3.7.0
-------------
Expand Down Expand Up @@ -35,6 +40,20 @@ Released on October 27, 2023.
[Bencodex.Json 0.16.0]: https://www.nuget.org/packages/Bencodex.json/0.16.0


Version 3.6.1
-------------

Released on November 20, 2023.

- (Libplanet.Store) Added optional `cache` parameter of type `HashNodeCache`
to `MerkleTrie()` constructors. [[#3495]]
- (Libplanet.Store) Added `HashNodeCache` class. [[#3495]]
- (Libplanet.Store) Changed internal caching strategy of `TrieStateStore` for
read/write optimization. [[#3495]]

[#3495]: https://github.com/planetarium/libplanet/pull/3495


Version 3.6.0
-------------

Expand Down
16 changes: 1 addition & 15 deletions Libplanet.Action/State/AccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,17 @@ namespace Libplanet.Action.State
public class AccountState : IAccountState
{
private ITrie _trie;
private AccountStateCache _cache;

public AccountState(ITrie trie)
{
_trie = trie;
_cache = new AccountStateCache();
}

/// <inheritdoc cref="IAccountState.Trie"/>
public ITrie Trie => _trie;

/// <inheritdoc cref="IAccountState.GetState"/>
public IValue? GetState(Address address)
{
if (_cache.TryGetValue(address, out IValue? cachedValue))
{
return cachedValue;
}
else
{
IValue? fetched = Trie.Get(ToStateKey(address));
_cache.AddOrUpdate(address, fetched);
return fetched;
}
}
public IValue? GetState(Address address) => Trie.Get(ToStateKey(address));

/// <inheritdoc cref="IAccountState.GetStates"/>
public IReadOnlyList<IValue?> GetStates(IReadOnlyList<Address> addresses) =>
Expand Down
Loading

0 comments on commit 488a305

Please sign in to comment.