Skip to content

Commit 924db1d

Browse files
Okapi 423 expose okapi metadata lang bindings (#426)
1 parent dd44bfa commit 924db1d

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

+4022
-155
lines changed

.github/workflows/build-python.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
working-directory: python
6767
env:
6868
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
69+
LD_LIBRARY_PATH: "${{ github.workspace }}/libs/${{ matrix.os-artifact[1] }}"
6970
- name: Upload Unit Test Results - Python
7071
if: always()
7172
uses: actions/upload-artifact@v2

.github/workflows/build-ruby.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ jobs:
5555
gem install rubocop
5656
bundle install
5757
python ../devops/build_sdks.py --language=ruby
58-
bundle exec rake
58+
bundle exec rake --trace
5959
shell: pwsh
6060
working-directory: ruby
6161
env:
6262
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
63+
RUBY_DLL_PATH: "${{ github.workspace }}/libs/${{ matrix.os-artifact[1] }}"
6364
- name: Run linters
6465
uses: wearerequired/[email protected]
6566
with:

Initialize.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
from urllib.request import Request, urlopen
99
from zipfile import ZipFile
1010

11-
request = Request('https://api.github.com/repos/trinsic-id/okapi/releases/latest')
12-
decoded = urlopen(request).read().decode('utf-8')
13-
assets = loads(decoded)['assets']
14-
asset = [e for e in assets if e['name'] == 'libs.zip'][0]
11+
request = Request("https://api.github.com/repos/trinsic-id/okapi/releases/latest")
12+
decoded = urlopen(request).read().decode("utf-8")
13+
assets = loads(decoded)["assets"]
14+
asset = [e for e in assets if e["name"] == "libs.zip"][0]
1515

1616
print(dumps(asset, indent=2, sort_keys=True))
1717

18-
request = Request(asset['browser_download_url'])
19-
read = urlopen(request).read()
20-
bytes = BytesIO(read)
21-
zip = ZipFile(bytes)
18+
request = Request(asset["browser_download_url"])
19+
read = urlopen(request).read()
20+
bytes = BytesIO(read)
21+
zip = ZipFile(bytes)
2222

2323
print(zip.namelist())
2424

dart/lib/okapi.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:ffi';
33
import 'package:okapi_dart/okapi_native.dart';
44
import 'package:okapi_dart/proto/okapi/hashing/v1/hashing.pb.dart';
55
import 'package:okapi_dart/proto/okapi/keys/v1/keys.pb.dart';
6+
import 'package:okapi_dart/proto/okapi/metadata/metadata.pb.dart';
67
import 'package:okapi_dart/proto/okapi/proofs/v1/proofs.pb.dart';
78
import 'package:okapi_dart/proto/okapi/security/v1/security.pb.dart';
89
import 'package:okapi_dart/proto/okapi/transport/v1/transport.pb.dart';
@@ -126,3 +127,13 @@ class Hashing {
126127
static SHA256HashResponse sha256Hash(SHA256HashRequest request) =>
127128
OkapiNative.nativeCall(_sha256Hash, request, SHA256HashResponse());
128129
}
130+
131+
class Metadata {
132+
static final _metadataGetMetadata = OkapiNative.library
133+
.lookupFunction<OkapiFunctionNative, OkapiFunction>(
134+
'okapi_metadata');
135+
136+
static MetadataResponse getMetadata() =>
137+
OkapiNative.nativeCall(
138+
_metadataGetMetadata, MetadataRequest(), MetadataResponse());
139+
}

dart/lib/proto/okapi/metadata/metadata.pb.dart

Lines changed: 199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/proto/okapi/metadata/metadata.pbenum.dart

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/proto/okapi/metadata/metadata.pbjson.dart

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/proto/okapi/metadata/metadata.pbserver.dart

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dart/lib/test/test-okapi.dart

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,35 @@ import '../okapi.dart';
1515

1616
void main() {
1717
test('Dart bitness', () {
18-
var size = sizeOf<IntPtr>()*8;
18+
var size = sizeOf<IntPtr>() * 8;
1919
print('Dart bitness=$size');
2020
});
21+
test('Get Metadata', () {
22+
var metadataResponse = Metadata.getMetadata();
23+
assert(metadataResponse.version.isNotEmpty);
24+
// Default local build version is 0.1.0, we just need to ensure SOMETHING isn't 0
25+
assert(metadataResponse.versionMajor != 0 ||
26+
metadataResponse.versionMinor != 0 ||
27+
metadataResponse.versionPatch != 0);
28+
});
2129
testDidKey();
2230
testHashing();
2331
testLdProofs();
32+
testOberon();
33+
}
34+
35+
void testOberon() {
2436
group('Oberon:', () {
2537
test('Demo', () {
26-
var key = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1,2,3]));
38+
var key = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1, 2, 3]));
2739
var data = Uint8List.fromList(utf8.encode('alice'));
2840
var nonce = Uint8List.fromList(utf8.encode('1234'));
2941

3042
var createTokenRequest = CreateOberonTokenRequest(sk: key.sk, data: data);
3143
var token = Oberon.CreateToken(createTokenRequest);
3244

33-
var createProofRequest = CreateOberonProofRequest(data: data, nonce: nonce, token: token.token);
45+
var createProofRequest = CreateOberonProofRequest(
46+
data: data, nonce: nonce, token: token.token);
3447
var proof = Oberon.CreateProof(createProofRequest);
3548

3649
var verifyProofRequest = VerifyOberonProofRequest();
@@ -42,14 +55,17 @@ void main() {
4255
assert(result.valid);
4356
});
4457
test('VerifyToken', () {
45-
var rightKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1,2,3]));
46-
var wrongKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [0,1,2]));
58+
var rightKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1, 2, 3]));
59+
var wrongKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [0, 1, 2]));
4760
var data = Uint8List.fromList(utf8.encode('4113'));
4861

49-
var token = Oberon.CreateToken(CreateOberonTokenRequest(sk: rightKey.sk, data: data));
62+
var token = Oberon.CreateToken(
63+
CreateOberonTokenRequest(sk: rightKey.sk, data: data));
5064

51-
var verifyRight = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: rightKey.pk, data: data));
52-
var verifyWrong = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: wrongKey.pk, data: data));
65+
var verifyRight = Oberon.VerifyToken(VerifyOberonTokenRequest(
66+
token: token.token, pk: rightKey.pk, data: data));
67+
var verifyWrong = Oberon.VerifyToken(VerifyOberonTokenRequest(
68+
token: token.token, pk: wrongKey.pk, data: data));
5369

5470
assert(verifyRight.valid);
5571
assert(!verifyWrong.valid);
@@ -101,7 +117,7 @@ void main() {
101117
proofRequest.token = userBlindedToken.token;
102118
proofRequest.blinding.add(userPin);
103119
proof = Oberon.CreateProof(proofRequest);
104-
120+
105121
// Verifier verifies the proof
106122
verifyProof = VerifyOberonProofRequest();
107123
verifyProof.data = data;

0 commit comments

Comments
 (0)