Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
86c5009
changed to npmjs registry
Bunchhieng Oct 18, 2022
401e599
Merge branch 'main' of github.com:Terran-One/cosmwasm-vm-js
Bunchhieng Oct 19, 2022
c085c14
Merge branch 'main' of github.com:Terran-One/cosmwasm-vm-js
Bunchhieng Oct 20, 2022
68f5c3d
Merge branch 'main' of github.com:Terran-One/cosmwasm-vm-js
Bunchhieng Oct 20, 2022
631c3d7
ethereum_signature_verify_tests
Bunchhieng Oct 20, 2022
4aa2b26
Use BigInt instead of Uint8Array
Bunchhieng Oct 20, 2022
0405723
Merge branch 'main' of github.com:Terran-One/cosmwasm-vm-js
Bunchhieng Oct 20, 2022
b3bd858
updated
Bunchhieng Oct 20, 2022
87b158f
changed to npmjs registry
Bunchhieng Oct 18, 2022
afe7790
ethereum_signature_verify_tests
Bunchhieng Oct 20, 2022
a2d632a
Use BigInt instead of Uint8Array
Bunchhieng Oct 20, 2022
f52ec3e
Params for etherium transaction test (WIP)
Oct 21, 2022
4b3a32c
Merge branch 'main' into feature/ethereum_signature_verify_tests
lukedawilson Oct 21, 2022
8a39b7a
updated
Bunchhieng Oct 21, 2022
d8e7cc8
fix secp256k1_recover_pubkey
Kiruse Oct 21, 2022
0c171a9
updated
Bunchhieng Oct 21, 2022
6680bd5
updated
Bunchhieng Oct 21, 2022
5ccd520
updated
Bunchhieng Oct 21, 2022
8513c95
Merge branch 'main' of github.com:Terran-One/cosmwasm-vm-js
Bunchhieng Oct 21, 2022
7acc68b
Merge branch 'main' into feature/ethereum_signature_verify_tests
Bunchhieng Oct 21, 2022
4a95c40
no longer increment every commit
Bunchhieng Oct 21, 2022
c3e1a64
fixed merge conflict
Bunchhieng Oct 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
name: Auto-increment patch version number
on:
workflow_dispatch: {}
push:
branches:
- main
jobs:
build:
name: Bump version
if: "!contains(github.event.head_commit.message, 'ci-skip')"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
actions: read
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
token: ${{ secrets.PACKAGE_PAT }}
- name: Bump
id: bump-version
run: |
YARN_VERSION_GIT_TAG='' yarn version --patch
NEW_VERSION=$(grep -Po '(?<="version": ").*(?=",)' package.json)
echo "Bumped version to $NEW_VERSION."
echo "::set-output name=version::$NEW_VERSION"
- name: Pull Remote Changes
run: git pull --autostash
- uses: stefanzweifel/git-auto-commit-action@v4
name: Commit & Push
with:
commit_message: Bumped version to ${{ steps.bump-version.outputs.version }} [ci-skip]"
#name: Auto-increment patch version number
#on:
# workflow_dispatch: {}
# push:
# branches:
# - main
#jobs:
# build:
# name: Bump version
# if: "!contains(github.event.head_commit.message, 'ci-skip')"
# runs-on: ubuntu-latest
# permissions:
# id-token: write
# contents: read
# actions: read
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3
# with:
# token: ${{ secrets.PACKAGE_PAT }}
# - name: Bump
# id: bump-version
# run: |
# YARN_VERSION_GIT_TAG='' yarn version --patch
# NEW_VERSION=$(grep -Po '(?<="version": ").*(?=",)' package.json)
# echo "Bumped version to $NEW_VERSION."
# echo "::set-output name=version::$NEW_VERSION"
# - name: Pull Remote Changes
# run: git pull --autostash
# - uses: stefanzweifel/git-auto-commit-action@v4
# name: Commit & Push
# with:
# commit_message: Bumped version to ${{ steps.bump-version.outputs.version }} [ci-skip]"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
target/
.vscode/
.idea/
package-lock.json
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"dependencies": {
"@cosmjs/crypto": "^0.28.4",
"@cosmjs/encoding": "^0.28.4",
"@polkadot/util": "^10.1.11",
"@polkadot/util-crypto": "^10.1.11",
"@types/elliptic": "^6.4.14",
"@types/secp256k1": "^4.0.3",
"bech32": "^2.0.0",
Expand Down
91 changes: 46 additions & 45 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export class VMInstance {
}

public allocate(size: number): Region {
let { allocate, memory } = this.exports;
let {allocate, memory} = this.exports;
let regPtr = allocate(size);
return new Region(memory, regPtr);
}

public deallocate(region: Region): void {
let { deallocate } = this.exports;
let {deallocate} = this.exports;
deallocate(region.ptr);
}

Expand Down Expand Up @@ -95,35 +95,35 @@ export class VMInstance {
}

public instantiate(env: Env, info: MessageInfo, msg: object): Region {
let { instantiate } = this.exports;
let {instantiate} = this.exports;
let args = [env, info, msg].map((x) => this.allocate_json(x).ptr);
let result = instantiate(...args);
return this.region(result);
}

public execute(env: Env, info: MessageInfo, msg: object): Region {
let { execute } = this.exports;
let {execute} = this.exports;
let args = [env, info, msg].map((x) => this.allocate_json(x).ptr);
let result = execute(...args);
return this.region(result);
}

public query(env: Env, msg: object): Region {
let { query } = this.exports;
let {query} = this.exports;
let args = [env, msg].map((x) => this.allocate_json(x).ptr);
let result = query(...args);
return this.region(result);
}

public migrate(env: Env, msg: object): Region {
let { migrate } = this.exports;
let {migrate} = this.exports;
let args = [env, msg].map((x) => this.allocate_json(x).ptr);
let result = migrate(...args);
return this.region(result);
}

public reply(env: Env, msg: object): Region {
let { reply } = this.exports;
let {reply} = this.exports;
let args = [env, msg].map((x) => this.allocate_json(x).ptr);
let result = reply(...args);
return this.region(result);
Expand Down Expand Up @@ -174,9 +174,9 @@ export class VMInstance {
}

secp256k1_verify(
hash_ptr: number,
signature_ptr: number,
pubkey_ptr: number
hash_ptr: number,
signature_ptr: number,
pubkey_ptr: number
): number {
let hash = this.region(hash_ptr);
let signature = this.region(signature_ptr);
Expand All @@ -185,19 +185,19 @@ export class VMInstance {
}

secp256k1_recover_pubkey(
hash_ptr: number,
signature_ptr: number,
recover_param: number
): Uint8Array {
hash_ptr: number,
signature_ptr: number,
recover_param: number
): bigint {
let hash = this.region(hash_ptr);
let signature = this.region(signature_ptr);
return this.do_secp256k1_recover_pubkey(hash, signature, recover_param);
return BigInt(this.do_secp256k1_recover_pubkey(hash, signature, recover_param).ptr);
}

ed25519_verify(
message_ptr: number,
signature_ptr: number,
pubkey_ptr: number
message_ptr: number,
signature_ptr: number,
pubkey_ptr: number
): number {
let message = this.region(message_ptr);
let signature = this.region(signature_ptr);
Expand All @@ -206,9 +206,9 @@ export class VMInstance {
}

ed25519_batch_verify(
messages_ptr: number,
signatures_ptr: number,
public_keys_ptr: number
messages_ptr: number,
signatures_ptr: number,
public_keys_ptr: number
): number {
let messages = this.region(messages_ptr);
let signatures = this.region(signatures_ptr);
Expand Down Expand Up @@ -284,12 +284,12 @@ export class VMInstance {
}

return this.allocate_bytes(new Uint8Array(
[
...record.key,
...toByteArray(record.key.length, 4),
...record.value,
...toByteArray(record.value.length, 4)
]));
[
...record.key,
...toByteArray(record.key.length, 4),
...record.value,
...toByteArray(record.value.length, 4)
]));
}

do_addr_humanize(source: Region, destination: Region): Region {
Expand Down Expand Up @@ -329,7 +329,7 @@ export class VMInstance {
}

const canonical = this.bech32.fromWords(
this.bech32.decode(source.str).words
this.bech32.decode(source.str).words
);

if (canonical.length === 0) {
Expand All @@ -338,8 +338,8 @@ export class VMInstance {

// TODO: Change prefix to be configurable per environment
const human = this.bech32.encode(
this.PREFIX,
this.bech32.toWords(canonical)
this.PREFIX,
this.bech32.toWords(canonical)
);
if (human !== source.str) {
throw new Error('Invalid address.');
Expand All @@ -351,12 +351,12 @@ export class VMInstance {
// Returns 0 on verification success, 1 on verification failure
do_secp256k1_verify(hash: Region, signature: Region, pubkey: Region): number {
console.log(
`signature length: ${signature.str.length}, pubkey length: ${pubkey.str.length}, message length: ${hash.str.length}`
`signature length: ${signature.str.length}, pubkey length: ${pubkey.str.length}, message length: ${hash.str.length}`
);
const isValidSignature = ecdsaVerify(
signature.data,
hash.data,
pubkey.data
signature.data,
hash.data,
pubkey.data
);

if (isValidSignature) {
Expand All @@ -367,19 +367,20 @@ export class VMInstance {
}

do_secp256k1_recover_pubkey(
hash: Region,
signature: Region,
recover_param: number
): Uint8Array {
return ecdsaRecover(signature.data, recover_param, hash.data, false);
msgHash: Region,
signature: Region,
recover_param: number
): Region {
const pub = ecdsaRecover(signature.data, recover_param, msgHash.data, false);
return this.allocate_bytes(pub);
}

// Verifies a message against a signature with a public key, using the ed25519 EdDSA scheme.
// Returns 0 on verification success, 1 on verification failure
do_ed25519_verify(
message: Region,
signature: Region,
pubkey: Region
message: Region,
signature: Region,
pubkey: Region
): number {
const sig = Buffer.from(signature.data).toString('hex');
const pub = Buffer.from(pubkey.data).toString('hex');
Expand All @@ -400,9 +401,9 @@ export class VMInstance {
// using the ed25519 EdDSA scheme.
// Returns 0 on verification success (all batches verify correctly), 1 on verification failure
do_ed25519_batch_verify(
messages_ptr: Region,
signatures_ptr: Region,
public_keys_ptr: Region
messages_ptr: Region,
signatures_ptr: Region,
public_keys_ptr: Region
): number {
let messages = decodeSections(messages_ptr.data);
let signatures = decodeSections(signatures_ptr.data);
Expand Down
Loading