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

feat: rust key derivation #1063

Open
wants to merge 105 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
d872480
feat(cat-voice-package): add rust key derivation implementation
bkioshn Oct 29, 2024
939d4a2
refactor: move uikit_example into utilities dir
damian-molinski Oct 29, 2024
e387a27
fix: exclude example packages from melos bootstrap
damian-molinski Oct 29, 2024
8847b78
refactor: move poc_local_storage into catalyst_voices/utilities
damian-molinski Oct 29, 2024
c90d392
fix: key derivation implementation
bkioshn Oct 29, 2024
9be664a
fix: auto gen file
bkioshn Oct 29, 2024
7960858
refactor: move catalyst_voices_remote_widgets package to catalyst_voi…
damian-molinski Oct 29, 2024
376cfb3
refactor: move scripts into catalyst_voices dir
damian-molinski Oct 29, 2024
93c9d24
refactor: move catalyst_voices/packages into catalyst_voices/packages…
damian-molinski Oct 29, 2024
cdd42d2
refactor: move catalyst_voices_packages into catalyst_voices/packages…
damian-molinski Oct 29, 2024
9571bc5
refactor: move melos.yaml into catalyst_voices
damian-molinski Oct 29, 2024
021c13d
fix: add word to dict
bkioshn Oct 30, 2024
78eccc9
fix: key derivation implementation
bkioshn Oct 30, 2024
b971eb8
Merge branch 'main' into feat/rust-key-derivation
bkioshn Oct 30, 2024
6d58c65
fix: remove simple rs
bkioshn Oct 30, 2024
c7a3ab3
Merge branch 'main' into feat/rust-key-derivation
bkioshn Oct 30, 2024
31f1237
fix: flutter format
bkioshn Oct 30, 2024
557748b
refactor: move app into apps/voices dir
damian-molinski Oct 30, 2024
166cf2d
refactor: rename packages/external to packages/libs
damian-molinski Oct 30, 2024
f0d301f
docs: update README
damian-molinski Oct 30, 2024
f4dd7b2
style: dart lint issues
dtscalac Oct 30, 2024
e0cde31
fix: builder target
damian-molinski Oct 30, 2024
665a38c
fix: update paths in Earthfile
damian-molinski Oct 30, 2024
9057dab
fix: uikit_example pubspec + libs examples deps override
damian-molinski Oct 30, 2024
75266d2
chore: test
damian-molinski Oct 30, 2024
13aef88
Merge main into refactor/self-contained-frontend_899
damian-molinski Oct 30, 2024
5bcc56d
fix: update cspell and check markdown rules
damian-molinski Oct 30, 2024
b02550d
fix: README formatting
damian-molinski Oct 30, 2024
e45f1a5
fix: add description to module
bkioshn Oct 31, 2024
63ef11f
fix: add cspell dict
bkioshn Oct 31, 2024
c056496
feat: add sign data, verify sig, get pubkey
bkioshn Oct 31, 2024
b137655
fix: auto gen file
bkioshn Oct 31, 2024
d1f523a
feat: add rust project setup files
bkioshn Oct 31, 2024
2cd1435
fix: flutter example
bkioshn Oct 31, 2024
ce24ad6
fix: build-web target path
damian-molinski Oct 31, 2024
7bcf37e
fix: remove build-web target suffix separator
damian-molinski Oct 31, 2024
431fef3
fix: wallet-automation tests target path
damian-molinski Oct 31, 2024
e581615
fix: wallet-automation builder target
damian-molinski Oct 31, 2024
5948d84
fix: voices automation tests target
damian-molinski Oct 31, 2024
79ae37c
fix: code-generator target path
damian-molinski Oct 31, 2024
1e0be6a
fix: typo and comment
bkioshn Oct 31, 2024
b6f981f
fix: vscode launch.recommended paths
damian-molinski Oct 31, 2024
9009c0a
feat: catalyst_voices justfile
damian-molinski Oct 31, 2024
9497665
refactor: rename catalyst_voices_remote_widgets to remote_widgets
damian-molinski Oct 31, 2024
0e3d066
fix: remote_widget spelling and licence checks
damian-molinski Oct 31, 2024
7243017
fix: remote_widget analyzer
damian-molinski Oct 31, 2024
dfcb159
Merge branch 'main' into refactor/self-contained-frontend_899
damian-molinski Oct 31, 2024
6162c45
Merge branch 'main' into feat/rust-key-derivation
bkioshn Oct 31, 2024
13467fc
refactor: move repo-catalyst-voices from root Earthfile to catalyst_v…
damian-molinski Oct 31, 2024
1d0b9bb
fix: restructure rust key derivation and solve dispose value
bkioshn Nov 1, 2024
7c6224b
fix: auto gen file
bkioshn Nov 1, 2024
5eabfc5
fix: ignore auto gen file
bkioshn Nov 1, 2024
b830da7
Merge branch 'main' into feat/rust-key-derivation
bkioshn Nov 1, 2024
2d4c082
fix: remove auto gen file
bkioshn Nov 1, 2024
947d63c
fix: add justfile, fix readme, and remove run.sh
bkioshn Nov 1, 2024
d5f7706
fix: markdown
bkioshn Nov 1, 2024
15770e2
fix: update git ignore
bkioshn Nov 1, 2024
8d10bb9
fix: ignore spelling check for dart auto gen file
bkioshn Nov 1, 2024
0b7bfa8
fix: add ci check and build
bkioshn Nov 4, 2024
d397252
fix: add earthfile and fix justfile
bkioshn Nov 4, 2024
2c3a619
fix: deprecated api
dtscalac Nov 4, 2024
dcd9f6c
Merge branch 'main' into refactor/self-contained-frontend_899
damian-molinski Nov 4, 2024
e7e426c
fix: file drop
damian-molinski Nov 4, 2024
5590248
fix: force downgraded version of flutter_dropzone
damian-molinski Nov 4, 2024
3c8d52c
chore: update repository links + codeowners paths
damian-molinski Nov 4, 2024
16853de
fix: deploy uikit workflow
damian-molinski Nov 4, 2024
c28f127
fix: uikit_example earthly build target
damian-molinski Nov 4, 2024
84779f6
fix: uikit deploy workflow path
damian-molinski Nov 4, 2024
b0a790c
chore: integration tests docs readme paths
damian-molinski Nov 4, 2024
f8e3f68
chore: remote widget readme path
damian-molinski Nov 4, 2024
6572b54
chore: markdown ignore macos pods path fix
damian-molinski Nov 4, 2024
171e4f9
chore: integration test scripts
damian-molinski Nov 4, 2024
6041b2f
chore: build_runner assets
damian-molinski Nov 4, 2024
b9b8543
chore: document flutter_dropzone issue
dtscalac Nov 4, 2024
c9f7186
Merge branch 'refactor/self-contained-frontend_899' into feat/rust-ke…
dtscalac Nov 4, 2024
9fcde96
chore: revert dropzone fixes
dtscalac Nov 4, 2024
015d0e9
chore: regenerate code
dtscalac Nov 4, 2024
a20e18d
fix: remove frb generated rust file
bkioshn Nov 4, 2024
f627f07
fix: rename
bkioshn Nov 4, 2024
d62c7e7
fix: add word to dict
bkioshn Nov 4, 2024
f9a6de5
fix: cspell ignore auto gen flutter file
bkioshn Nov 4, 2024
fe549cc
fix: auto gen file
bkioshn Nov 4, 2024
1b2dfa6
fix: file path cspell
bkioshn Nov 4, 2024
75d5141
Merge branch 'main' into feat/rust-key-derivation
bkioshn Nov 4, 2024
abee76b
Merge branch 'main' into feat/rust-key-derivation
bkioshn Nov 4, 2024
b4fdb3b
test: check target
bkioshn Nov 4, 2024
6d22b27
fix: rust earthfile
bkioshn Nov 4, 2024
365528c
chore: add blueprint.cue along with new Earthfile
bkioshn Nov 4, 2024
2598895
chore: fix blueprint.cue
bkioshn Nov 4, 2024
757e30a
fix: linter and format
bkioshn Nov 5, 2024
664be71
fix: remove simple.rs
bkioshn Nov 5, 2024
0ebcea6
Merge branch 'main' into feat/rust-key-derivation
dtscalac Nov 5, 2024
6be7f7a
Merge branch 'main' into feat/rust-key-derivation
dtscalac Nov 5, 2024
be33804
fix: ci check create dummy
bkioshn Nov 5, 2024
1b21484
fix: ci check create dummy
bkioshn Nov 5, 2024
d84d86a
Merge branch 'main' into feat/rust-key-derivation
stevenj Nov 5, 2024
3aea8be
fix: rust ci
bkioshn Nov 5, 2024
d1a67e7
fix: rust format
bkioshn Nov 5, 2024
cbe61e4
feat: add to hex functions
bkioshn Nov 5, 2024
f22ddcf
fix: auto gen file
bkioshn Nov 5, 2024
348bd63
fix: add toHex example to dart
bkioshn Nov 5, 2024
cc8fc40
Merge branch 'main' into feat/rust-key-derivation
bkioshn Nov 6, 2024
131cd96
Merge branch 'main' into feat/rust-key-derivation
bkioshn Nov 6, 2024
df6b7e0
fix: code-generator
bkioshn Nov 6, 2024
990d029
Merge branch 'main' into feat/rust-key-derivation
dtscalac Nov 7, 2024
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
dtscalac marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:js_interop';

import 'package:catalyst_key_derivation/catalyst_key_derivation.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -35,6 +37,10 @@ class MyApp extends StatelessWidget {

Future<void> _doMagic() async {
// ignore: avoid_print
print(await greet(name: 'Tom'));
U8Array96 xprv = await mnemonicToXprv(
mnemonic: "prevent company field green slot measure chief hero apple task eagle sunset endorse dress seed");
print(xprv);
U8Array96 derive_xprv = await deriveXprivateKey(xprivateKeyBytes: xprv, path: "m/1852'/1815'/0'/2/0");
print(derive_xprv);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library catalyst_key_derivation;

export 'src/rust/api/key_derivation.dart';
export 'src/rust/api/simple.dart';
export 'src/rust/frb_generated.dart' show RustLib;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.5.1.

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../frb_generated.dart';
import 'package:collection/collection.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These functions are ignored because they are not marked as `pub`: `derive_xprivate_key_helper`, `mnemonic_to_xprv_helper`

/// Generate a new extended private key (`XPrv`) from a mnemonic and passphrase.
/// This function works with BIP-0039 mnemonics.
/// For more information: Cardano Icarus master node derivation
/// https://github.com/satoshilabs/slips/blob/master/slip-0023.md
///
/// # Arguments
///
/// - `mnemonic`: A string representing the mnemonic.
/// - `passphrase`: An optional string representing the passphrase.
///
/// # Returns
///
/// Returns the `XPrv` extended private key as a `Result`.
/// If the conversion is successful, it returns `Ok` with the extended private key
/// (`XPrv`).
Future<U8Array96> mnemonicToXprv(
{required String mnemonic, String? passphrase}) =>
RustLib.instance.api.crateApiKeyDerivationMnemonicToXprv(
mnemonic: mnemonic, passphrase: passphrase);

/// Derive a new extended private key from the given extended private key.
/// - V2 derivation scheme is used as it is mention in [SLIP-0023](https://github.com/satoshilabs/slips/blob/master/slip-0023.md).
/// - More information about child key derivation can be found in [BIP32-Ed25519](https://input-output-hk.github.io/adrestia/static/Ed25519_BIP.pdf).
///
/// # Arguments
///
/// - `xprivate_key_bytes`: An extended private key of type `XPrvBytes`.
/// - `path`: Derivation path. eg. m/0/2'/3 where ' represents hardened derivation.
///
/// # Returns
///
/// Returns the `XPrv` extended private key as a `Result`.
/// If the derivation path is successful, it returns `Ok` with the extended private key
/// (`XPrv`).
Future<U8Array96> deriveXprivateKey(
{required U8Array96 xprivateKeyBytes, required String path}) =>
RustLib.instance.api.crateApiKeyDerivationDeriveXprivateKey(
xprivateKeyBytes: xprivateKeyBytes, path: path);

class U8Array96 extends NonGrowableListView<int> {
static const arraySize = 96;

@internal
Uint8List get inner => _inner;
final Uint8List _inner;

U8Array96(this._inner)
: assert(_inner.length == arraySize),
super(_inner);

U8Array96.init() : this(Uint8List(arraySize));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field

import 'api/key_derivation.dart';
import 'api/simple.dart';
import 'dart:async';
import 'dart:convert';
Expand Down Expand Up @@ -68,7 +69,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.5.1';

@override
int get rustContentHash => -1918914929;
int get rustContentHash => 424624821;

static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
Expand All @@ -79,6 +80,12 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
}

abstract class RustLibApi extends BaseApi {
Future<U8Array96> crateApiKeyDerivationDeriveXprivateKey(
{required U8Array96 xprivateKeyBytes, required String path});

Future<U8Array96> crateApiKeyDerivationMnemonicToXprv(
{required String mnemonic, String? passphrase});

Future<String> crateApiSimpleGreet({required String name});

Future<void> crateApiSimpleInitApp();
Expand All @@ -92,14 +99,68 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
required super.portManager,
});

@override
Future<U8Array96> crateApiKeyDerivationDeriveXprivateKey(
{required U8Array96 xprivateKeyBytes, required String path}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_u_8_array_96(xprivateKeyBytes, serializer);
sse_encode_String(path, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 1, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_u_8_array_96,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiKeyDerivationDeriveXprivateKeyConstMeta,
argValues: [xprivateKeyBytes, path],
apiImpl: this,
));
}

TaskConstMeta get kCrateApiKeyDerivationDeriveXprivateKeyConstMeta =>
const TaskConstMeta(
debugName: "derive_xprivate_key",
argNames: ["xprivateKeyBytes", "path"],
);

@override
Future<U8Array96> crateApiKeyDerivationMnemonicToXprv(
{required String mnemonic, String? passphrase}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(mnemonic, serializer);
sse_encode_opt_String(passphrase, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 2, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_u_8_array_96,
decodeErrorData: sse_decode_AnyhowException,
),
constMeta: kCrateApiKeyDerivationMnemonicToXprvConstMeta,
argValues: [mnemonic, passphrase],
apiImpl: this,
));
}

TaskConstMeta get kCrateApiKeyDerivationMnemonicToXprvConstMeta =>
const TaskConstMeta(
debugName: "mnemonic_to_xprv",
argNames: ["mnemonic", "passphrase"],
);

@override
Future<String> crateApiSimpleGreet({required String name}) {
return handler.executeNormal(NormalTask(
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
sse_encode_String(name, serializer);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 1, port: port_);
funcId: 3, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_String,
Expand All @@ -122,7 +183,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
callFfi: (port_) {
final serializer = SseSerializer(generalizedFrbRustBinding);
pdeCallFfi(generalizedFrbRustBinding, serializer,
funcId: 2, port: port_);
funcId: 4, port: port_);
},
codec: SseCodec(
decodeSuccessData: sse_decode_unit,
Expand All @@ -139,6 +200,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: [],
);

@protected
AnyhowException dco_decode_AnyhowException(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return AnyhowException(raw as String);
}

@protected
String dco_decode_String(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
Expand All @@ -151,18 +218,37 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw as Uint8List;
}

@protected
String? dco_decode_opt_String(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return raw == null ? null : dco_decode_String(raw);
}

@protected
int dco_decode_u_8(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return raw as int;
}

@protected
U8Array96 dco_decode_u_8_array_96(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return U8Array96(dco_decode_list_prim_u_8_strict(raw));
}

@protected
void dco_decode_unit(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return;
}

@protected
AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var inner = sse_decode_String(deserializer);
return AnyhowException(inner);
}

@protected
String sse_decode_String(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand All @@ -177,12 +263,30 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return deserializer.buffer.getUint8List(len_);
}

@protected
String? sse_decode_opt_String(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs

if (sse_decode_bool(deserializer)) {
return (sse_decode_String(deserializer));
} else {
return null;
}
}

@protected
int sse_decode_u_8(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
return deserializer.buffer.getUint8();
}

@protected
U8Array96 sse_decode_u_8_array_96(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var inner = sse_decode_list_prim_u_8_strict(deserializer);
return U8Array96(inner);
}

@protected
void sse_decode_unit(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand All @@ -200,6 +304,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return deserializer.buffer.getUint8() != 0;
}

@protected
void sse_encode_AnyhowException(
AnyhowException self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_String(self.message, serializer);
}

@protected
void sse_encode_String(String self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand All @@ -214,12 +325,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
serializer.buffer.putUint8List(self);
}

@protected
void sse_encode_opt_String(String? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs

sse_encode_bool(self != null, serializer);
if (self != null) {
sse_encode_String(self, serializer);
}
}

@protected
void sse_encode_u_8(int self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
serializer.buffer.putUint8(self);
}

@protected
void sse_encode_u_8_array_96(U8Array96 self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_list_prim_u_8_strict(self.inner, serializer);
}

@protected
void sse_encode_unit(void self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
Expand Down
Loading
Loading