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

Okapi 423 expose okapi metadata lang bindings #426

Merged
merged 24 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
working-directory: python
env:
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
LD_LIBRARY_PATH: "${{ github.workspace }}/libs/${{ matrix.os-artifact[1] }}"
- name: Upload Unit Test Results - Python
if: always()
uses: actions/upload-artifact@v2
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ jobs:
gem install rubocop
bundle install
python ../devops/build_sdks.py --language=ruby
bundle exec rake
bundle exec rake --trace
shell: pwsh
working-directory: ruby
env:
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
RUBY_DLL_PATH: "${{ github.workspace }}/libs/${{ matrix.os-artifact[1] }}"
- name: Run linters
uses: wearerequired/[email protected]
with:
Expand Down
16 changes: 8 additions & 8 deletions Initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from urllib.request import Request, urlopen
from zipfile import ZipFile

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

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

request = Request(asset['browser_download_url'])
read = urlopen(request).read()
bytes = BytesIO(read)
zip = ZipFile(bytes)
request = Request(asset["browser_download_url"])
read = urlopen(request).read()
bytes = BytesIO(read)
zip = ZipFile(bytes)

print(zip.namelist())

Expand Down
11 changes: 11 additions & 0 deletions dart/lib/okapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ffi';
import 'package:okapi_dart/okapi_native.dart';
import 'package:okapi_dart/proto/okapi/hashing/v1/hashing.pb.dart';
import 'package:okapi_dart/proto/okapi/keys/v1/keys.pb.dart';
import 'package:okapi_dart/proto/okapi/metadata/metadata.pb.dart';
import 'package:okapi_dart/proto/okapi/proofs/v1/proofs.pb.dart';
import 'package:okapi_dart/proto/okapi/security/v1/security.pb.dart';
import 'package:okapi_dart/proto/okapi/transport/v1/transport.pb.dart';
Expand Down Expand Up @@ -126,3 +127,13 @@ class Hashing {
static SHA256HashResponse sha256Hash(SHA256HashRequest request) =>
OkapiNative.nativeCall(_sha256Hash, request, SHA256HashResponse());
}

class Metadata {
static final _metadataGetMetadata = OkapiNative.library
.lookupFunction<OkapiFunctionNative, OkapiFunction>(
'okapi_metadata');

static MetadataResponse getMetadata() =>
OkapiNative.nativeCall(
_metadataGetMetadata, MetadataRequest(), MetadataResponse());
}
199 changes: 199 additions & 0 deletions dart/lib/proto/okapi/metadata/metadata.pb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
///
// Generated code. Do not modify.
// source: okapi/metadata/metadata.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields

import 'dart:core' as $core;

import 'package:protobuf/protobuf.dart' as $pb;

class MetadataRequest extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'MetadataRequest', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'okapi.metadata'), createEmptyInstance: create)
..hasRequiredFields = false
;

MetadataRequest._() : super();
factory MetadataRequest() => create();
factory MetadataRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MetadataRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MetadataRequest clone() => MetadataRequest()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MetadataRequest copyWith(void Function(MetadataRequest) updates) => super.copyWith((message) => updates(message as MetadataRequest)) as MetadataRequest; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MetadataRequest create() => MetadataRequest._();
MetadataRequest createEmptyInstance() => create();
static $pb.PbList<MetadataRequest> createRepeated() => $pb.PbList<MetadataRequest>();
@$core.pragma('dart2js:noInline')
static MetadataRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MetadataRequest>(create);
static MetadataRequest? _defaultInstance;
}

class MetadataResponse extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'MetadataResponse', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'okapi.metadata'), createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'version')
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'versionMajor', $pb.PbFieldType.O3)
..a<$core.int>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'versionMinor', $pb.PbFieldType.O3)
..a<$core.int>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'versionPatch', $pb.PbFieldType.O3)
..aOS(10, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targetFamily')
..aOS(11, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targetOs')
..aOS(12, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targetArch')
..aOS(13, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targetVendor')
..aOS(14, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'targetEnv')
..hasRequiredFields = false
;

MetadataResponse._() : super();
factory MetadataResponse({
$core.String? version,
$core.int? versionMajor,
$core.int? versionMinor,
$core.int? versionPatch,
$core.String? targetFamily,
$core.String? targetOs,
$core.String? targetArch,
$core.String? targetVendor,
$core.String? targetEnv,
}) {
final _result = create();
if (version != null) {
_result.version = version;
}
if (versionMajor != null) {
_result.versionMajor = versionMajor;
}
if (versionMinor != null) {
_result.versionMinor = versionMinor;
}
if (versionPatch != null) {
_result.versionPatch = versionPatch;
}
if (targetFamily != null) {
_result.targetFamily = targetFamily;
}
if (targetOs != null) {
_result.targetOs = targetOs;
}
if (targetArch != null) {
_result.targetArch = targetArch;
}
if (targetVendor != null) {
_result.targetVendor = targetVendor;
}
if (targetEnv != null) {
_result.targetEnv = targetEnv;
}
return _result;
}
factory MetadataResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory MetadataResponse.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
MetadataResponse clone() => MetadataResponse()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
MetadataResponse copyWith(void Function(MetadataResponse) updates) => super.copyWith((message) => updates(message as MetadataResponse)) as MetadataResponse; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static MetadataResponse create() => MetadataResponse._();
MetadataResponse createEmptyInstance() => create();
static $pb.PbList<MetadataResponse> createRepeated() => $pb.PbList<MetadataResponse>();
@$core.pragma('dart2js:noInline')
static MetadataResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<MetadataResponse>(create);
static MetadataResponse? _defaultInstance;

@$pb.TagNumber(1)
$core.String get version => $_getSZ(0);
@$pb.TagNumber(1)
set version($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasVersion() => $_has(0);
@$pb.TagNumber(1)
void clearVersion() => clearField(1);

@$pb.TagNumber(2)
$core.int get versionMajor => $_getIZ(1);
@$pb.TagNumber(2)
set versionMajor($core.int v) { $_setSignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasVersionMajor() => $_has(1);
@$pb.TagNumber(2)
void clearVersionMajor() => clearField(2);

@$pb.TagNumber(3)
$core.int get versionMinor => $_getIZ(2);
@$pb.TagNumber(3)
set versionMinor($core.int v) { $_setSignedInt32(2, v); }
@$pb.TagNumber(3)
$core.bool hasVersionMinor() => $_has(2);
@$pb.TagNumber(3)
void clearVersionMinor() => clearField(3);

@$pb.TagNumber(4)
$core.int get versionPatch => $_getIZ(3);
@$pb.TagNumber(4)
set versionPatch($core.int v) { $_setSignedInt32(3, v); }
@$pb.TagNumber(4)
$core.bool hasVersionPatch() => $_has(3);
@$pb.TagNumber(4)
void clearVersionPatch() => clearField(4);

@$pb.TagNumber(10)
$core.String get targetFamily => $_getSZ(4);
@$pb.TagNumber(10)
set targetFamily($core.String v) { $_setString(4, v); }
@$pb.TagNumber(10)
$core.bool hasTargetFamily() => $_has(4);
@$pb.TagNumber(10)
void clearTargetFamily() => clearField(10);

@$pb.TagNumber(11)
$core.String get targetOs => $_getSZ(5);
@$pb.TagNumber(11)
set targetOs($core.String v) { $_setString(5, v); }
@$pb.TagNumber(11)
$core.bool hasTargetOs() => $_has(5);
@$pb.TagNumber(11)
void clearTargetOs() => clearField(11);

@$pb.TagNumber(12)
$core.String get targetArch => $_getSZ(6);
@$pb.TagNumber(12)
set targetArch($core.String v) { $_setString(6, v); }
@$pb.TagNumber(12)
$core.bool hasTargetArch() => $_has(6);
@$pb.TagNumber(12)
void clearTargetArch() => clearField(12);

@$pb.TagNumber(13)
$core.String get targetVendor => $_getSZ(7);
@$pb.TagNumber(13)
set targetVendor($core.String v) { $_setString(7, v); }
@$pb.TagNumber(13)
$core.bool hasTargetVendor() => $_has(7);
@$pb.TagNumber(13)
void clearTargetVendor() => clearField(13);

@$pb.TagNumber(14)
$core.String get targetEnv => $_getSZ(8);
@$pb.TagNumber(14)
set targetEnv($core.String v) { $_setString(8, v); }
@$pb.TagNumber(14)
$core.bool hasTargetEnv() => $_has(8);
@$pb.TagNumber(14)
void clearTargetEnv() => clearField(14);
}

7 changes: 7 additions & 0 deletions dart/lib/proto/okapi/metadata/metadata.pbenum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///
// Generated code. Do not modify.
// source: okapi/metadata/metadata.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields

35 changes: 35 additions & 0 deletions dart/lib/proto/okapi/metadata/metadata.pbjson.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
///
// Generated code. Do not modify.
// source: okapi/metadata/metadata.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package

import 'dart:core' as $core;
import 'dart:convert' as $convert;
import 'dart:typed_data' as $typed_data;
@$core.Deprecated('Use metadataRequestDescriptor instead')
const MetadataRequest$json = const {
'1': 'MetadataRequest',
};

/// Descriptor for `MetadataRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List metadataRequestDescriptor = $convert.base64Decode('Cg9NZXRhZGF0YVJlcXVlc3Q=');
@$core.Deprecated('Use metadataResponseDescriptor instead')
const MetadataResponse$json = const {
'1': 'MetadataResponse',
'2': const [
const {'1': 'version', '3': 1, '4': 1, '5': 9, '10': 'version'},
const {'1': 'version_major', '3': 2, '4': 1, '5': 5, '10': 'versionMajor'},
const {'1': 'version_minor', '3': 3, '4': 1, '5': 5, '10': 'versionMinor'},
const {'1': 'version_patch', '3': 4, '4': 1, '5': 5, '10': 'versionPatch'},
const {'1': 'target_family', '3': 10, '4': 1, '5': 9, '10': 'targetFamily'},
const {'1': 'target_os', '3': 11, '4': 1, '5': 9, '10': 'targetOs'},
const {'1': 'target_arch', '3': 12, '4': 1, '5': 9, '10': 'targetArch'},
const {'1': 'target_vendor', '3': 13, '4': 1, '5': 9, '10': 'targetVendor'},
const {'1': 'target_env', '3': 14, '4': 1, '5': 9, '10': 'targetEnv'},
],
};

/// Descriptor for `MetadataResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List metadataResponseDescriptor = $convert.base64Decode('ChBNZXRhZGF0YVJlc3BvbnNlEhgKB3ZlcnNpb24YASABKAlSB3ZlcnNpb24SIwoNdmVyc2lvbl9tYWpvchgCIAEoBVIMdmVyc2lvbk1ham9yEiMKDXZlcnNpb25fbWlub3IYAyABKAVSDHZlcnNpb25NaW5vchIjCg12ZXJzaW9uX3BhdGNoGAQgASgFUgx2ZXJzaW9uUGF0Y2gSIwoNdGFyZ2V0X2ZhbWlseRgKIAEoCVIMdGFyZ2V0RmFtaWx5EhsKCXRhcmdldF9vcxgLIAEoCVIIdGFyZ2V0T3MSHwoLdGFyZ2V0X2FyY2gYDCABKAlSCnRhcmdldEFyY2gSIwoNdGFyZ2V0X3ZlbmRvchgNIAEoCVIMdGFyZ2V0VmVuZG9yEh0KCnRhcmdldF9lbnYYDiABKAlSCXRhcmdldEVudg==');
9 changes: 9 additions & 0 deletions dart/lib/proto/okapi/metadata/metadata.pbserver.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
///
// Generated code. Do not modify.
// source: okapi/metadata/metadata.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package

export 'metadata.pb.dart';

34 changes: 25 additions & 9 deletions dart/lib/test/test-okapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,35 @@ import '../okapi.dart';

void main() {
test('Dart bitness', () {
var size = sizeOf<IntPtr>()*8;
var size = sizeOf<IntPtr>() * 8;
print('Dart bitness=$size');
});
test('Get Metadata', () {
var metadataResponse = Metadata.getMetadata();
assert(metadataResponse.version.isNotEmpty);
// Default local build version is 0.1.0, we just need to ensure SOMETHING isn't 0
assert(metadataResponse.versionMajor != 0 ||
metadataResponse.versionMinor != 0 ||
metadataResponse.versionPatch != 0);
});
testDidKey();
testHashing();
testLdProofs();
testOberon();
}

void testOberon() {
group('Oberon:', () {
test('Demo', () {
var key = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1,2,3]));
var key = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1, 2, 3]));
var data = Uint8List.fromList(utf8.encode('alice'));
var nonce = Uint8List.fromList(utf8.encode('1234'));

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

var createProofRequest = CreateOberonProofRequest(data: data, nonce: nonce, token: token.token);
var createProofRequest = CreateOberonProofRequest(
data: data, nonce: nonce, token: token.token);
var proof = Oberon.CreateProof(createProofRequest);

var verifyProofRequest = VerifyOberonProofRequest();
Expand All @@ -42,14 +55,17 @@ void main() {
assert(result.valid);
});
test('VerifyToken', () {
var rightKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1,2,3]));
var wrongKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [0,1,2]));
var rightKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [1, 2, 3]));
var wrongKey = Oberon.CreateKey(CreateOberonKeyRequest(seed: [0, 1, 2]));
var data = Uint8List.fromList(utf8.encode('4113'));

var token = Oberon.CreateToken(CreateOberonTokenRequest(sk: rightKey.sk, data: data));
var token = Oberon.CreateToken(
CreateOberonTokenRequest(sk: rightKey.sk, data: data));

var verifyRight = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: rightKey.pk, data: data));
var verifyWrong = Oberon.VerifyToken(VerifyOberonTokenRequest(token: token.token, pk: wrongKey.pk, data: data));
var verifyRight = Oberon.VerifyToken(VerifyOberonTokenRequest(
token: token.token, pk: rightKey.pk, data: data));
var verifyWrong = Oberon.VerifyToken(VerifyOberonTokenRequest(
token: token.token, pk: wrongKey.pk, data: data));

assert(verifyRight.valid);
assert(!verifyWrong.valid);
Expand Down Expand Up @@ -101,7 +117,7 @@ void main() {
proofRequest.token = userBlindedToken.token;
proofRequest.blinding.add(userPin);
proof = Oberon.CreateProof(proofRequest);

// Verifier verifies the proof
verifyProof = VerifyOberonProofRequest();
verifyProof.data = data;
Expand Down
Loading