Skip to content

Commit d529c98

Browse files
authored
Merge pull request #35 from codenotary/feat/proofV1.2
Feat/proof v1.2
2 parents 0b3ff60 + ee9f6cf commit d529c98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3974
-5287
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
make dev
2222
- name: Start immudb container
2323
run: |
24-
docker run -d --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -v ${{ github.workspace }}/tests/certs/my.key.pem:/key.pem -p 3322:3322 codenotary/immudb:latest --signingKey=/key.pem
24+
docker run -d --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -v ${{ github.workspace }}/tests/certs/my.key.pem:/key.pem -p 3322:3322 codenotary/immudb:1.2.2 --signingKey=/key.pem
25+
docker run -d --health-cmd "immuadmin status" --health-interval 10s --health-timeout 5s --health-retries 5 -v ${{ github.workspace }}/tests/certs/my.key.pem:/key.pem -p 3333:3322 codenotary/immudb:1.1.0 --signingKey=/key.pem
2526
- name: Run tests
2627
run: |
2728
make test

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := /bin/bash
22

3-
3+
PYTHON ?= python3
44
PYTEST ?= python3 -m pytest
55
PIP ?= pip3
66
COVERAGE ?= $(shell which coverage)
@@ -28,10 +28,10 @@ coverage:
2828
$(COVERAGE) run -m pytest tests
2929

3030
install:
31-
python setup.py install
31+
$(PYTHON) setup.py install
3232

3333
.PHONY: dist
3434
dist:
3535
mkdir -p ./dist
3636
rm -fr ./dist/* ./build/*
37-
python setup.py sdist bdist_wheel
37+
$(PYTHON) setup.py sdist bdist_wheel

devtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
from immudb.client import ImmudbClient
33

44
a = ImmudbClient()

immudb/client.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
from immudb import header_manipulator_client_interceptor
1717
from immudb.handler import (batchGet, batchSet, changePassword, changePermission, createUser,
18-
currentRoot, databaseCreate, databaseList, databaseUse,
18+
currentRoot, createDatabase, databaseList, useDatabase,
1919
get, listUsers, sqldescribe, verifiedGet, verifiedSet, setValue, history,
2020
scan, reference, verifiedreference, zadd, verifiedzadd,
21-
zscan, healthcheck, txbyid, verifiedtxbyid, sqlexec, sqlquery,
21+
zscan, healthcheck, health, txbyid, verifiedtxbyid, sqlexec, sqlquery,
2222
listtables, execAll)
2323
from immudb.rootService import *
2424
from immudb.grpc import schema_pb2_grpc
@@ -101,6 +101,9 @@ def stub(self):
101101
def healthCheck(self):
102102
return healthcheck.call(self.__stub, self.__rs)
103103

104+
def health(self):
105+
return health.call(self.__stub, self.__rs)
106+
104107
def get(self, key: bytes):
105108
return get.call(self.__stub, self.__rs, key)
106109

@@ -175,16 +178,30 @@ def databaseList(self):
175178
return [x.databaseName for x in dbs.dblist.databases]
176179

177180
def databaseUse(self, dbName: bytes):
181+
warnings.warn("Call to deprecated databaseUse. Use useDatabase instead",
182+
category=DeprecationWarning,
183+
stacklevel=2
184+
)
185+
return self.useDatabase(dbName)
186+
187+
def useDatabase(self, dbName: bytes):
178188
request = schema_pb2_grpc.schema__pb2.Database(databaseName=dbName)
179-
resp = databaseUse.call(self.__stub, self.__rs, request)
189+
resp = useDatabase.call(self.__stub, self.__rs, request)
180190
# modify header token accordingly
181191
self.__stub = self.set_token_header_interceptor(resp)
182192
self.__rs.init(dbName, self.__stub)
183193
return resp
184194

185-
def databaseCreate(self, dbName: bytes):
195+
def createDatabase(self, dbName: bytes):
186196
request = schema_pb2_grpc.schema__pb2.Database(databaseName=dbName)
187-
return databaseCreate.call(self.__stub, self.__rs, request)
197+
return createDatabase.call(self.__stub, self.__rs, request)
198+
199+
def databaseCreate(self, dbName: bytes):
200+
warnings.warn("Call to deprecated databaseCreate. Use createDatabase instead",
201+
category=DeprecationWarning,
202+
stacklevel=2
203+
)
204+
return self.createDatabase(dbName)
188205

189206
def currentState(self):
190207
return currentRoot.call(self.__stub, self.__rs, None)

immudb/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 CodeNotary, Inc. All rights reserved.
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
22

33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

immudb/database/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from immudb.database.meta import *

immudb/database/meta.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from immudb.constants import *
14+
import immudb.embedded.store as store
15+
import struct
16+
17+
18+
def WrapWithPrefix(b: bytes, prefix: bytes) -> bytes:
19+
return prefix+b
20+
21+
22+
def EncodeKey(key: bytes):
23+
return WrapWithPrefix(key, SET_KEY_PREFIX)
24+
25+
26+
def EncodeEntrySpec(key: bytes, md: store.KVMetadata, value: bytes):
27+
es = store.EntrySpec(
28+
key=WrapWithPrefix(key, SET_KEY_PREFIX),
29+
md=md,
30+
value=WrapWithPrefix(value, PLAIN_VALUE_PREFIX)
31+
)
32+
return es
33+
34+
35+
def EncodeReference(key: bytes, md: store.KVMetadata, referencedKey: bytes, atTx: int):
36+
es = store.EntrySpec(key=WrapWithPrefix(key, SET_KEY_PREFIX),
37+
md=md,
38+
value=WrapReferenceValueAt(
39+
WrapWithPrefix(referencedKey, SET_KEY_PREFIX), atTx)
40+
)
41+
return es
42+
43+
44+
def WrapReferenceValueAt(key: bytes, atTx: int) -> bytes:
45+
refVal = REFERENCE_VALUE_PREFIX+atTx.to_bytes(8, 'big')+key
46+
return refVal
47+
48+
49+
def EncodeZAdd(zset: bytes, score: float, key: bytes, attx: int):
50+
es = store.EntrySpec(key=WrapZAddReferenceAt(zset, score, key, attx),
51+
md=None,
52+
value=b''
53+
)
54+
return es
55+
56+
57+
def WrapZAddReferenceAt(zset: bytes, score: float, key: bytes, attx: int) -> bytes:
58+
ekey = SET_KEY_PREFIX+key
59+
zkey = SORTED_KEY_PREFIX
60+
zkey += struct.pack(">Q", len(zset))+zset
61+
zkey += struct.pack(">d", score)
62+
zkey += struct.pack(">Q", len(ekey))+ekey
63+
zkey += struct.pack(">Q", attx)
64+
return zkey

immudb/embedded/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.

immudb/embedded/ahtree/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from immudb.embedded.ahtree.verification import *
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2022 CodeNotary, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from immudb.constants import *
14+
import hashlib
15+
16+
17+
def VerifyInclusion(iproof: list, i: int, j: int, iLeaf: bytes, jRoot: bytes) -> bool:
18+
if i > j or i == 0 or i < j and len(iproof) == 0:
19+
return False
20+
ciRoot = EvalInclusion(iproof, i, j, iLeaf)
21+
return jRoot == ciRoot
22+
23+
24+
def EvalInclusion(iproof: list, i: int, j: int, iLeaf: bytes) -> bool:
25+
i1 = i - 1
26+
j1 = j - 1
27+
ciRoot = iLeaf
28+
for h in iproof:
29+
if i1 % 2 == 0 and i1 != j1:
30+
b = NODE_PREFIX+ciRoot+h
31+
else:
32+
b = NODE_PREFIX+h+ciRoot
33+
ciRoot = hashlib.sha256(b).digest()
34+
i1 = i1 >> 1
35+
j1 = j1 >> 1
36+
return ciRoot
37+
38+
39+
def VerifyConsistency(cproof: list, i: int, j: int, iRoot: bytes, jRoot: bytes) -> bool:
40+
if i > j or i == 0 or (i < j and len(cproof) == 0):
41+
return False
42+
if i == j and len(cproof) == 0:
43+
return iRoot == jRoot
44+
ciRoot, cjRoot = EvalConsistency(cproof, i, j)
45+
return iRoot == ciRoot and jRoot == cjRoot
46+
47+
48+
def EvalConsistency(cproof: list, i: int, j: int):
49+
fn = i - 1
50+
sn = j - 1
51+
while fn % 2 == 1:
52+
fn = fn >> 1
53+
sn = sn >> 1
54+
ciRoot, cjRoot = cproof[0], cproof[0]
55+
for h in cproof[1:]:
56+
if fn % 2 == 1 or fn == sn:
57+
b = NODE_PREFIX+h+ciRoot
58+
ciRoot = hashlib.sha256(b).digest()
59+
b = NODE_PREFIX+h+cjRoot
60+
cjRoot = hashlib.sha256(b).digest()
61+
while fn % 2 == 0 and fn != 0:
62+
fn = fn >> 1
63+
sn = sn >> 1
64+
else:
65+
b = NODE_PREFIX+cjRoot+h
66+
cjRoot = hashlib.sha256(b).digest()
67+
fn = fn >> 1
68+
sn = sn >> 1
69+
return ciRoot, cjRoot
70+
71+
72+
def VerifyLastInclusion(iproof: list, i: int, leaf: bytes, root: bytes) -> bool:
73+
if i == 0:
74+
return False
75+
return root == EvalLastInclusion(iproof, i, leaf)
76+
77+
78+
def EvalLastInclusion(iproof: list, i: int, leaf: bytes) -> bytes:
79+
i1 = i - 1
80+
root = leaf
81+
for h in iproof:
82+
b = NODE_PREFIX+h+root
83+
root = hashlib.sha256(b).digest()
84+
i1 >>= 1
85+
return root

0 commit comments

Comments
 (0)