Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validateTxProof and move to contract template #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Required
HIVE_ACCOUNT_ACTIVE_PRIVATE_KEY=
HIVE_ACCOUNT_USERNAME=

# Optional (defaults shown below)
IPFS_HOST=/ip4/127.0.0.1/tcp/5001 # if not set an IPFS node will be started for you using ports 4001 and 5001
HIVE_HOST=https://hive-api.web3telekom.xyz
VSC_NETWORK_ID=testnet/0bf2e474-6b9e-4165-ad4e-a0d78968d20c
VSC_NODE_HOST=https://api.vsc.eco
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
.yarn
.env
package-lock.json
docs
10 changes: 10 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"decoratorsBeforeExport": true
},
"target": "es2020"
}
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
9 changes: 7 additions & 2 deletions asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat",
"sourceMap": true,
"debug": true
"debug": true,
"importMemory": true,
"noExportMemory": true,
"exportRuntime": true,
"bindings": "raw",
"transform": ["@vsc.eco/contract-testing-utils/debugTransform"]
},
"release": {
"outFile": "build/release.wasm",
Expand All @@ -19,4 +24,4 @@
"options": {
"bindings": "esm"
}
}
}
19 changes: 0 additions & 19 deletions assembly/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { u128,u256 } from 'as-bignum/assembly'
import * as Arrays from './common/arrays'
import { BigInt } from "as-bigint/assembly";
import { calcKey, extractPrevBlockLE, getHeaders, extractMerkleRootLE, hash256, getStringFromJSON } from './btc-relay-utils';
import { JSON, JSONEncoder } from "assemblyscript-json/assembly";
import { SystemAPI, db } from '.';
import { Crypto } from './common/crypto';
Expand Down Expand Up @@ -276,24 +275,6 @@ function hash256(preImage: Uint8Array): Uint8Array {
return Crypto.sha256(Crypto.sha256(preImage));
}

// pla: the below implementation was the only one working for me, trying with the existing one first
// maybe the Crypto.sha256 function needs to be updated with the code below

// function sha256(param: Uint8Array): Uint8Array {
// const arg0Value: string = Arrays.Arrays.toHexString(param, false);

// const obj = new JSON.Obj()
// obj.set('arg0', arg0Value)

// const result = <JSON.Obj>JSON.parse(SystemAPI.call('crypto.sha256', obj.stringify()))
// if (result.getString('result')!.isString) {
// return Arrays.Arrays.fromHexString(result.getString('result')!.valueOf()!)
// } else {
// //Never should happen
// throw new Error('Crypto - incorrect binding response')
// }
// }

class FullProof {
confirming_header: ConfirmingHeader | null = null

Expand Down
9 changes: 6 additions & 3 deletions assembly/common/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import {Arrays, SystemAPI} from '..'

export namespace Crypto {
export function sha256(param: Uint8Array): Uint8Array {
const result = <JSON.Obj>JSON.parse(SystemAPI.call('crypto.sha256', JSON.from({
arg0: Arrays.toHexString(param, false)
}).stringify()))
const arg0Value: string = Arrays.toHexString(param, false);
const obj = new JSON.Obj()
obj.set('arg0', arg0Value)
const result = <JSON.Obj>JSON.parse(SystemAPI.call('crypto.sha256', obj.stringify()))
if(result.getString('result')!.isString) {
return Arrays.fromHexString(result.getString('result')!.valueOf()!)
} else {
//Never should happen
throw new Error('Crypto - incorrect binding response')
}
}

// pla: probably has had the same bug as sha256, check sha function's latest commit to see what changed
export function ripemd160(param: Uint8Array): Uint8Array {
const result = <JSON.Obj>JSON.parse(SystemAPI.call('crypto.ripemd160', JSON.from({
arg0: Arrays.toHexString(param, false)
Expand Down
5 changes: 5 additions & 0 deletions assembly/index.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{
"name": "vsc.eco/sdk",
"description": "Software Development Kit for VSC Smart Contracts"
}
3 changes: 3 additions & 0 deletions contract.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare namespace VscContractTestingUtils {
type Contract = typeof import("./build/debug");
}
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
</head>

<body>
<div id="mocha"></div>
<script type="module" src="tests/debug.ts"></script>
</body>

</html>
30 changes: 30 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
moduleFileExtensions: ["js", "json", "ts"],
testRegex: "tests/.*.ts$",
testPathIgnorePatterns: [
"/node_modules/",
"/tests/mocks.ts",
"/tests/debug.ts",
"/tests/vite-env.d.ts",
],
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
globals: {
"ts-jest": {
useESM: true,
},
},
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^@@(.*)$": "<rootDir>$1",
},
transform: {
"^.+\\.(t|j)s$": [
"@swc/jest",
{
root: "../..",
},
],
},
};
5 changes: 5 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["assembly"],
"ext": "ts",
"exec": "asc assembly/index.ts --target debug"
}
Loading
Loading