Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
b984dd1
move Instruction(s) and Elem to own module (execution no longer depen…
michaeljklein Jan 27, 2022
8a22e13
implement restacking primitive (backend)
michaeljklein Feb 1, 2022
7d96a34
add restack append, executor, and instruction
michaeljklein Feb 1, 2022
7d3b847
add serde json (de)serializer
michaeljklein Feb 1, 2022
6c284b9
add first restack test (failing)
michaeljklein Feb 7, 2022
d1465eb
add granular stack manipulations, add tests, fix tests (passing)
michaeljklein Feb 7, 2022
e64ac66
fix unused import, document stack primitives, add tests for each (pas…
michaeljklein Feb 8, 2022
9c27595
remove Bytes32: combine with Bytes(N)
michaeljklein Feb 8, 2022
3b93180
add le/lt primitives, use arbitrary_precision numbers for manually de…
michaeljklein Feb 8, 2022
970f65d
prototype (concat, slice, index, lookup) and implement concat
michaeljklein Feb 8, 2022
6a7c49d
implement concat for bytes, string, array, object; prototype slice an…
michaeljklein Feb 9, 2022
ac770e9
add to/from json for object/string/array, add instruction symbols, fi…
michaeljklein Feb 11, 2022
eea7876
add debug method for stack, verbose execution, fix push/pop, extend demo
michaeljklein Feb 11, 2022
eff41f9
fixed eq bug, kick out restack, cleanup example
michaeljklein Feb 11, 2022
7fd559b
tests now passing: deriving clone, eq, ord on instruction
michaeljklein Feb 11, 2022
92e27bc
rename s/Fn//
michaeljklein Feb 14, 2022
32aab54
add string_to_bytes primitive
michaeljklein Feb 14, 2022
988a056
extend example with concat/hash of two fields
michaeljklein Feb 14, 2022
ea9c3ea
replace *FromJson with UnpackJson, use ElemSymbol to replace simple_type
michaeljklein Feb 14, 2022
f089faa
use pop_pushN to simplify executor
michaeljklein Feb 14, 2022
83ab03d
WIP preparing to type instructions
michaeljklein Feb 16, 2022
8e88d03
implement arbitrary for ElemSymbol, Number
michaeljklein Feb 16, 2022
26638dd
add arbitrary instances for Value, Map, Number, ElemSymbol
michaeljklein Feb 17, 2022
c7543ed
migrate Arbitrary instances and Elem to own files, cleanup
michaeljklein Feb 17, 2022
f5fc69b
add typing for each instruction besides Restack
michaeljklein Feb 17, 2022
3af5eab
added zip_then to compare typed stacks and got tests passing
michaeljklein Feb 18, 2022
3ee0763
unification up and running for stack types
michaeljklein Feb 18, 2022
186edc3
typing Instructions, made Instructions a struct, make type errors mor…
michaeljklein Feb 21, 2022
a2dbfbb
types work for three instruction example with new unification algorithm
michaeljklein Feb 22, 2022
a2293f8
now typing [push(json), unpack_to(object), dup] with silent eq error
michaeljklein Feb 22, 2022
35505c5
type-level lists prototype
michaeljklein Feb 23, 2022
f825b0d
add dyn-clone, use type equality
michaeljklein Feb 24, 2022
48d6d19
use Arc
michaeljklein Feb 24, 2022
ade811b
WIP: debugging IsInstruction for concat
michaeljklein Mar 1, 2022
4ccf649
cleanup and get working with return types
michaeljklein Mar 1, 2022
fd6822d
implemented IsInstructionT for concat
michaeljklein Mar 1, 2022
b980727
add type-level sets
michaeljklein Mar 1, 2022
575909e
merge IsElem and AnElem
michaeljklein Mar 2, 2022
b14af3c
debugging and applying AnElem
michaeljklein Mar 2, 2022
d112edc
iterator impls, debugging return type API
michaeljklein Mar 3, 2022
bdb83b1
fix returning too many values
michaeljklein Mar 3, 2022
0e645c2
WIP: checkpoint broken mutable references
michaeljklein Mar 7, 2022
d5981bf
fixed mutex and got concat IsInstructionT up to parity w/ IsInstruction
michaeljklein Mar 7, 2022
f44126b
IsInstructionT up to parity with InstructionT
michaeljklein Mar 7, 2022
3e9c174
add alias/handler for untyped inputs, use for le/lt/eq
michaeljklein Mar 8, 2022
1869268
added InstructionT impl for all but Restack
michaeljklein Mar 8, 2022
39af1ac
WIP: cleanup
michaeljklein Mar 10, 2022
4a41781
implement typed popping from stack for instructions
michaeljklein Mar 10, 2022
fd63fcb
make Elems and IsList Iterable, dynamic instruction dispatch
michaeljklein Mar 14, 2022
e59508b
example program working with new instruction types
michaeljklein Mar 14, 2022
7b018e9
cleanup unused versions of instructions/executor
michaeljklein Mar 14, 2022
18e2513
debugging type errors: added AJsonElem for rest of types, recreating …
michaeljklein Mar 16, 2022
244ecef
added debug info to stack type and popping from stack
michaeljklein Mar 16, 2022
c155477
WIP: replacing EnumSet's with ElemType's
michaeljklein Mar 16, 2022
cccbb1b
WIP: include debug info w/ elem sets and propagate
michaeljklein Mar 17, 2022
757902d
calculate type at each instruction evaluation and include w/ debug info
michaeljklein Mar 18, 2022
9a7cb9e
prettier-printed errors -> found and fixed off-by-one error
michaeljklein Mar 18, 2022
0eaae81
use clap for cli parsing, pretty print elem/stack, get running and pa…
michaeljklein Mar 21, 2022
9fe5fb8
cleanup and get largest example working again
michaeljklein Mar 21, 2022
cd65240
add basic template for schema w/ test
michaeljklein Mar 23, 2022
6c4729b
debugging tokio version error, add query/template handling to cli, de…
michaeljklein Mar 23, 2022
aa4140b
adding test server: post expected (to, from) get or get as posted
michaeljklein Mar 23, 2022
f1c58c4
support rate limiting, extra debug info, for test api and begin imple…
michaeljklein Mar 25, 2022
f1a9f1d
wrapping up test server: post and get api works
michaeljklein Mar 28, 2022
947f420
support multiple queries and debug/fail-fast for queries
michaeljklein Mar 28, 2022
d72070d
json to template, support put in schemas, caching works, token gating…
michaeljklein Mar 28, 2022
b162cbd
add support for monomorphic typing, split out Query into own module
michaeljklein Mar 28, 2022
72bb43c
split out into more modules, remove executor, fix query caching, cleanup
michaeljklein Mar 29, 2022
3fa18d4
adding missing docs
michaeljklein Apr 13, 2022
e5b6721
implement Error for IsInstruction errors
michaeljklein Apr 13, 2022
fbfab00
continuing to add docs, replace empty enums with Empty
michaeljklein Apr 13, 2022
4ff47a8
document queries and json_template, cleanup queries
michaeljklein Apr 13, 2022
0b5f2a6
add docs for an_elem, arbitrary, elem[_type], json_template, [re]stac…
michaeljklein Apr 13, 2022
b4dbdf8
linting and adding docs
michaeljklein Apr 14, 2022
5c3fca6
splitting out Elems into more modules
michaeljklein Apr 20, 2022
edcb391
split out modules per major type and add missing docs
michaeljklein Apr 29, 2022
74be22f
add demo to readme with JSON examples of code, input, queries
michaeljklein May 24, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/target
Cargo.lock
*.profraw
/*.json
/examples/cache.json
/examples/local_cache.json
29 changes: 25 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@ name = "cryptoscript"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "cryptoscript"
path = "src/main.rs"

[[bin]]
name = "rest-api"
path = "src/rest_api.rs"

[dependencies]
sha2 = "0.9"
sha3 = "0.9"
hex-literal = "0.3"
actix-web = { version = "4.0.1", default-features = false, features = ["macros"] }

clap = { version = "3.1.6", features = ["derive"] }
enumset = { version = "1.0.8", features = ["serde"] }
futures = { version = "0.3.21", features = ["executor", "thread-pool"] }
generic-array = "0.14"
hex = "0.4"
hex-literal = "0.3"
indexmap = "1.5"
k256 = { version = "0.10.2", features = ["std", "ecdsa", "serde"] }
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
reqwest = { version = "0.11.10", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.79", features = ["arbitrary_precision", "preserve_order"] }
sha2 = "0.9"
sha3 = "0.9"
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = "0.1.8"
thiserror = "1.0"
typenum = "1.15.0"
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,65 @@ the presenter "clears" a puzzle to get authorized. cryptoscript is extensible
with modules to support all blockchain networks and off-chain data. This
policy-as-code primitive can create infinite matching representations.

## Demo

There are two demos:
- Local: this demo is self-contained to not require any API keys
- Etherscan: this demo requires a free Etherscan API key, which you can get
[here](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics)

### Local Demo

The local demo requires running a tiny test server, which can be started with the following command:

```bash
cargo run --bin rest-api
```

Note: this API accepts PUT's of new GET "API's" for testing: each requires a
fixed `application/json` request body and returns a fixed `application/json`
response.

To run the demo itself, run:

```bash
cargo r --bin cryptoscript -- \
--code examples/local_demo_code.json \
--cache-location examples/local_cache.json \
--input examples/input.json \
--queries examples/local_query.json \
--variables '{
"contractaddress": "0x57d90b64a1a57749b0f932f1a3395792e12e7055",
"address": "0xe04f27eb70e025b78871a2ad7eabe85e61212761",
"apikey": "DUMMY_ETHERSCAN_API_KEY" }'
```

You'll see `successful!` if it completes without any errors.

### Etherscan Demo

*NOTE: this demo currently ignores any errors from Etherscan.*

This demo requires a free Etherscan API key, which you can get
[here](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics)

Once you have an API key, replace `YOUR_ETHERSCAN_API_KEY` below with your API
key from Etherscan to run the demo:

```bash
cargo r --bin cryptoscript -- \
--code examples/demo_code.json \
--cache-location examples/cache.json \
--input examples/input.json \
--queries examples/query.json \
--variables '{
"contractaddress": "0x57d90b64a1a57749b0f932f1a3395792e12e7055",
"address": "0xe04f27eb70e025b78871a2ad7eabe85e61212761",
"apikey": "YOUR_ETHERSCAN_API_KEY" }'
```

### Troubleshooting Demo's

If you have any issues, make sure to clear any `cache.json` files to ensure
you're receiving fresh query responses.

93 changes: 93 additions & 0 deletions examples/demo_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"instructions": [
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
},
{
"UnpackJson": "Object"
},
{
"Push": {
"String": "queries"
}
},
"Lookup",
{
"UnpackJson": "Array"
},
{
"Push": {
"Number": 0
}
},
"Index",
{
"UnpackJson": "Object"
},
{
"Restack": {
"restack_depth": 1,
"restack_vec": [
0,
0
]
}
},
{
"Push": {
"String": "action"
}
},
"Lookup",
{
"UnpackJson": "String"
},
{
"Push": {
"String": "tokenbalance"
}
},
"StringEq",
"AssertTrue",
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
},
{
"Restack": {
"restack_depth": 1,
"restack_vec": [
0,
0
]
}
},
{
"Push": {
"String": "contractaddress"
}
},
"Lookup",
{
"UnpackJson": "String"
},
{
"Push": {
"String": "0x57d90b64a1a57749b0f932f1a3395792e12e7055"
}
},
"StringEq",
"AssertTrue",
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
}
]
}
40 changes: 40 additions & 0 deletions examples/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"queries": [
{
"uri": "https://api.etherscan.io/api",
"module": "account",
"action": "tokenbalance",
"contractaddress": "0x57d90b64a1a57749b0f932f1a3395792e12e7055",
"address": "0xe04f27eb70e025b78871a2ad7eabe85e61212761",
"tag": "latest",
"blockno": "8000000",
"apikey": "YourApiKeyToken",
"response":
{
"status": "1",
"message": "OK",
"result": "135499"
}
}
],
"prompts": [
{
"action": "siwe",
"version": "1.1.0",
"data": {
"message": "service.org wants you to sign in with your Ethereum account:\n0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\n\nI accept the ServiceOrg Terms of Service: https://service.org/tos\n\nURI: https://service.org/login\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z\nResources:\n- ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu\n- https://example.com/my-web2-claim.json",
"fields": {
"domain": "service.org",
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"statement": "I accept the ServiceOrg Terms of Service: https://service.org/tos",
"uri": "https://service.org/login",
"version": "1",
"chainId": 1,
"nonce": "32891757",
"issuedAt": "2021-09-30T16:25:24.000Z",
"resources": ["ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu", "https://example.com/my-web2-claim.json"]
}
}
}
]
}
99 changes: 99 additions & 0 deletions examples/local_demo_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"instructions": [
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
},
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
},
{
"UnpackJson": "Object"
},
{
"Push": {
"String": "queries"
}
},
"Lookup",
{
"UnpackJson": "Array"
},
{
"Push": {
"Number": 0
}
},
"Index",
{
"UnpackJson": "Object"
},
{
"Restack": {
"restack_depth": 1,
"restack_vec": [
0,
0
]
}
},
{
"Push": {
"String": "action"
}
},
"Lookup",
{
"UnpackJson": "String"
},
{
"Push": {
"String": "tokenbalance"
}
},
"StringEq",
"AssertTrue",
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
},
{
"Restack": {
"restack_depth": 1,
"restack_vec": [
0,
0
]
}
},
{
"Push": {
"String": "contractaddress"
}
},
"Lookup",
{
"UnpackJson": "String"
},
{
"Push": {
"String": "0x57d90b64a1a57749b0f932f1a3395792e12e7055"
}
},
"StringEq",
"AssertTrue",
{
"Restack": {
"restack_depth": 1,
"restack_vec": []
}
}
]
}
Loading