Skip to content

Commit

Permalink
fix: abi methods (#241)
Browse files Browse the repository at this point in the history
* fix: added abiVersion, fixed serialize_into_boc_with_hash

* fix: abi methods
  • Loading branch information
Alex-A4 authored Nov 17, 2023
1 parent 191604b commit d3f908a
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 108 deletions.
11 changes: 7 additions & 4 deletions packages/flutter_nekoton_bridge/ios/Classes/frb.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ intptr_t init_frb_dart_api_dl(void *obj);

void wire_verify_signature(int64_t port_,
struct wire_uint_8_list *public_key,
struct wire_uint_8_list *data_hash,
struct wire_uint_8_list *signature);
struct wire_uint_8_list *data,
struct wire_uint_8_list *signature,
int32_t *signature_id);

void wire_nt_generate_key(int64_t port_, struct wire_MnemonicType *account_type);

Expand Down Expand Up @@ -372,12 +373,14 @@ void wire_get_boc_hash(int64_t port_, struct wire_uint_8_list *boc);

void wire_pack_into_cell(int64_t port_,
struct wire_uint_8_list *params,
struct wire_uint_8_list *tokens);
struct wire_uint_8_list *tokens,
struct wire_uint_8_list *version);

void wire_unpack_from_cell(int64_t port_,
struct wire_uint_8_list *params,
struct wire_uint_8_list *boc,
bool allow_partial);
bool allow_partial,
struct wire_uint_8_list *version);

void wire_pack_std_smc_addr(int64_t port_,
struct wire_uint_8_list *addr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export 'password_cache/password_cache_lib.dart';
/// Check signature by publicKey and data hash
Future<bool> verifySignature({
required PublicKey publicKey,
required String dataHash,
required String data,
required String signature,
required int? signatureId,
}) {
return createLib().verifySignature(
publicKey: publicKey.publicKey,
dataHash: dataHash,
data: data,
signature: signature,
signatureId: signatureId,
);
}
4 changes: 4 additions & 0 deletions packages/flutter_nekoton_bridge/lib/nekoton/helpers/abi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ Future<String> getBocHash(String boc) {
Future<(String, String)> packIntoCell({
required List<AbiParam> params,
required TokensObject tokens,
required String? abiVersion,
}) async {
final data = await createLib().packIntoCell(
params: jsonEncode(params),
tokens: jsonEncode(tokens),
version: abiVersion,
);

return (data[0], data[1]);
Expand All @@ -220,11 +222,13 @@ Future<TokensObject> unpackFromCell({
required List<AbiParam> params,
required String boc,
required bool allowPartial,
required String? abiVersion,
}) async {
return jsonDecode(await createLib().unpackFromCell(
params: jsonEncode(params),
boc: boc,
allowPartial: allowPartial,
version: abiVersion,
));
}

Expand Down
45 changes: 29 additions & 16 deletions packages/nekoton_bridge/lib/src/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ abstract class NekotonBridge {
///----------------------------
/// CONTENT OF src/nekoton_wrapper/crypto/crypto_api.rs
///----------------------------
/// Check signature by publicKey and data hash
/// Check signature by publicKey and data
Future<bool> verifySignature(
{required String publicKey,
required String dataHash,
required String data,
required String signature,
int? signatureId,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kVerifySignatureConstMeta;
Expand Down Expand Up @@ -82,7 +83,7 @@ abstract class NekotonBridge {
FlutterRustBridgeTaskConstMeta get kRunLocalConstMeta;

/// Get address of tvc and contract_abi.
/// Returns list of [address, state_init, hash] or throws error
/// Returns list of [address, boc of state_init, hash] or throws error
Future<List<String>> getExpectedAddress(
{required String tvc,
required String contractAbi,
Expand Down Expand Up @@ -186,7 +187,10 @@ abstract class NekotonBridge {
/// Return base64 encoded bytes of tokens or throws error
/// returns [tvc, hash]
Future<List<String>> packIntoCell(
{required String params, required String tokens, dynamic hint});
{required String params,
required String tokens,
String? version,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kPackIntoCellConstMeta;

Expand All @@ -195,6 +199,7 @@ abstract class NekotonBridge {
{required String params,
required String boc,
required bool allowPartial,
String? version,
dynamic hint});

FlutterRustBridgeTaskConstMeta get kUnpackFromCellConstMeta;
Expand Down Expand Up @@ -3681,26 +3686,28 @@ class NekotonBridgeImpl implements NekotonBridge {
NekotonBridgeImpl.raw(this._platform);
Future<bool> verifySignature(
{required String publicKey,
required String dataHash,
required String data,
required String signature,
int? signatureId,
dynamic hint}) {
var arg0 = _platform.api2wire_String(publicKey);
var arg1 = _platform.api2wire_String(dataHash);
var arg1 = _platform.api2wire_String(data);
var arg2 = _platform.api2wire_String(signature);
var arg3 = _platform.api2wire_opt_box_autoadd_i32(signatureId);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) =>
_platform.inner.wire_verify_signature(port_, arg0, arg1, arg2),
_platform.inner.wire_verify_signature(port_, arg0, arg1, arg2, arg3),
parseSuccessData: _wire2api_bool,
constMeta: kVerifySignatureConstMeta,
argValues: [publicKey, dataHash, signature],
argValues: [publicKey, data, signature, signatureId],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kVerifySignatureConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "verify_signature",
argNames: ["publicKey", "dataHash", "signature"],
argNames: ["publicKey", "data", "signature", "signatureId"],
);

Future<GeneratedKeyG> ntGenerateKey(
Expand Down Expand Up @@ -4111,47 +4118,53 @@ class NekotonBridgeImpl implements NekotonBridge {
);

Future<List<String>> packIntoCell(
{required String params, required String tokens, dynamic hint}) {
{required String params,
required String tokens,
String? version,
dynamic hint}) {
var arg0 = _platform.api2wire_String(params);
var arg1 = _platform.api2wire_String(tokens);
var arg2 = _platform.api2wire_opt_String(version);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) =>
_platform.inner.wire_pack_into_cell(port_, arg0, arg1),
_platform.inner.wire_pack_into_cell(port_, arg0, arg1, arg2),
parseSuccessData: _wire2api_StringList,
constMeta: kPackIntoCellConstMeta,
argValues: [params, tokens],
argValues: [params, tokens, version],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kPackIntoCellConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "pack_into_cell",
argNames: ["params", "tokens"],
argNames: ["params", "tokens", "version"],
);

Future<String> unpackFromCell(
{required String params,
required String boc,
required bool allowPartial,
String? version,
dynamic hint}) {
var arg0 = _platform.api2wire_String(params);
var arg1 = _platform.api2wire_String(boc);
var arg2 = allowPartial;
var arg3 = _platform.api2wire_opt_String(version);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) =>
_platform.inner.wire_unpack_from_cell(port_, arg0, arg1, arg2),
_platform.inner.wire_unpack_from_cell(port_, arg0, arg1, arg2, arg3),
parseSuccessData: _wire2api_String,
constMeta: kUnpackFromCellConstMeta,
argValues: [params, boc, allowPartial],
argValues: [params, boc, allowPartial, version],
hint: hint,
));
}

FlutterRustBridgeTaskConstMeta get kUnpackFromCellConstMeta =>
const FlutterRustBridgeTaskConstMeta(
debugName: "unpack_from_cell",
argNames: ["params", "boc", "allowPartial"],
argNames: ["params", "boc", "allowPartial", "version"],
);

Future<String> packStdSmcAddr(
Expand Down
41 changes: 30 additions & 11 deletions packages/nekoton_bridge/lib/src/bridge_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -984,14 +984,16 @@ class NekotonBridgeWire implements FlutterRustBridgeWireBase {
void wire_verify_signature(
int port_,
ffi.Pointer<wire_uint_8_list> public_key,
ffi.Pointer<wire_uint_8_list> data_hash,
ffi.Pointer<wire_uint_8_list> data,
ffi.Pointer<wire_uint_8_list> signature,
ffi.Pointer<ffi.Int32> signature_id,
) {
return _wire_verify_signature(
port_,
public_key,
data_hash,
data,
signature,
signature_id,
);
}

Expand All @@ -1001,10 +1003,15 @@ class NekotonBridgeWire implements FlutterRustBridgeWireBase {
ffi.Int64,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>)>>('wire_verify_signature');
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<ffi.Int32>)>>('wire_verify_signature');
late final _wire_verify_signature = _wire_verify_signaturePtr.asFunction<
void Function(int, ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>, ffi.Pointer<wire_uint_8_list>)>();
void Function(
int,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<ffi.Int32>)>();

void wire_nt_generate_key(
int port_,
Expand Down Expand Up @@ -1430,33 +1437,40 @@ class NekotonBridgeWire implements FlutterRustBridgeWireBase {
int port_,
ffi.Pointer<wire_uint_8_list> params,
ffi.Pointer<wire_uint_8_list> tokens,
ffi.Pointer<wire_uint_8_list> version,
) {
return _wire_pack_into_cell(
port_,
params,
tokens,
version,
);
}

late final _wire_pack_into_cellPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(ffi.Int64, ffi.Pointer<wire_uint_8_list>,
ffi.Void Function(
ffi.Int64,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>)>>('wire_pack_into_cell');
late final _wire_pack_into_cell = _wire_pack_into_cellPtr.asFunction<
void Function(
int, ffi.Pointer<wire_uint_8_list>, ffi.Pointer<wire_uint_8_list>)>();
void Function(int, ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>, ffi.Pointer<wire_uint_8_list>)>();

void wire_unpack_from_cell(
int port_,
ffi.Pointer<wire_uint_8_list> params,
ffi.Pointer<wire_uint_8_list> boc,
bool allow_partial,
ffi.Pointer<wire_uint_8_list> version,
) {
return _wire_unpack_from_cell(
port_,
params,
boc,
allow_partial,
version,
);
}

Expand All @@ -1466,10 +1480,15 @@ class NekotonBridgeWire implements FlutterRustBridgeWireBase {
ffi.Int64,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
ffi.Bool)>>('wire_unpack_from_cell');
ffi.Bool,
ffi.Pointer<wire_uint_8_list>)>>('wire_unpack_from_cell');
late final _wire_unpack_from_cell = _wire_unpack_from_cellPtr.asFunction<
void Function(int, ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>, bool)>();
void Function(
int,
ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>,
bool,
ffi.Pointer<wire_uint_8_list>)>();

void wire_pack_std_smc_addr(
int port_,
Expand Down
24 changes: 13 additions & 11 deletions packages/nekoton_bridge/lib/src/bridge_generated.web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class NekotonBridgeWasmModule implements WasmModule {
external Object /* Promise */ call([String? moduleName]);
external NekotonBridgeWasmModule bind(dynamic thisArg, String moduleName);
external dynamic /* void */ wire_verify_signature(NativePortType port_,
String public_key, String data_hash, String signature);
String public_key, String data, String signature, int? signature_id);

external dynamic /* void */ wire_nt_generate_key(
NativePortType port_, List<dynamic> account_type);
Expand Down Expand Up @@ -607,10 +607,10 @@ class NekotonBridgeWasmModule implements WasmModule {
NativePortType port_, String boc);

external dynamic /* void */ wire_pack_into_cell(
NativePortType port_, String params, String tokens);
NativePortType port_, String params, String tokens, String? version);

external dynamic /* void */ wire_unpack_from_cell(
NativePortType port_, String params, String boc, bool allow_partial);
external dynamic /* void */ wire_unpack_from_cell(NativePortType port_,
String params, String boc, bool allow_partial, String? version);

external dynamic /* void */ wire_pack_std_smc_addr(
NativePortType port_, String addr, bool base64_url, bool bounceable);
Expand Down Expand Up @@ -1386,8 +1386,9 @@ class NekotonBridgeWire
: super(WasmModule.cast<NekotonBridgeWasmModule>(module));

void wire_verify_signature(NativePortType port_, String public_key,
String data_hash, String signature) =>
wasmModule.wire_verify_signature(port_, public_key, data_hash, signature);
String data, String signature, int? signature_id) =>
wasmModule.wire_verify_signature(
port_, public_key, data, signature, signature_id);

void wire_nt_generate_key(NativePortType port_, List<dynamic> account_type) =>
wasmModule.wire_nt_generate_key(port_, account_type);
Expand Down Expand Up @@ -1473,13 +1474,14 @@ class NekotonBridgeWire
void wire_get_boc_hash(NativePortType port_, String boc) =>
wasmModule.wire_get_boc_hash(port_, boc);

void wire_pack_into_cell(
NativePortType port_, String params, String tokens) =>
wasmModule.wire_pack_into_cell(port_, params, tokens);
void wire_pack_into_cell(NativePortType port_, String params, String tokens,
String? version) =>
wasmModule.wire_pack_into_cell(port_, params, tokens, version);

void wire_unpack_from_cell(NativePortType port_, String params, String boc,
bool allow_partial) =>
wasmModule.wire_unpack_from_cell(port_, params, boc, allow_partial);
bool allow_partial, String? version) =>
wasmModule.wire_unpack_from_cell(
port_, params, boc, allow_partial, version);

void wire_pack_std_smc_addr(NativePortType port_, String addr,
bool base64_url, bool bounceable) =>
Expand Down
Loading

0 comments on commit d3f908a

Please sign in to comment.