-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support for Zcash unified addresses
- Loading branch information
Showing
29 changed files
with
605 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto2"; | ||
package hw.trezor.messages.zcash; | ||
|
||
// Sugar for easier handling in Java | ||
option java_package = "com.satoshilabs.trezor.lib.protobuf"; | ||
option java_outer_classname = "TrezorMessageZcash"; | ||
|
||
/** | ||
* Receiver typecodes for unified addresses. | ||
* see: https://zips.z.cash/zip-0316#encoding-of-unified-addresses | ||
*/ | ||
enum ZcashReceiverTypecode { | ||
P2PKH = 0; | ||
P2SH = 1; | ||
SAPLING = 2; | ||
ORCHARD = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for Zcash unified addresses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* This file is part of the Trezor project, https://trezor.io/ | ||
* | ||
* Copyright (c) SatoshiLabs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "py/runtime.h" | ||
|
||
#if USE_ZCASH | ||
|
||
#include "librust.h" | ||
|
||
/// def f4jumble(message: bytearray) -> None: | ||
/// """Mutates a message by F4Jumble permutation.""" | ||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_orchardlib_f4jumble, orchardlib_f4jumble); | ||
|
||
/// def f4jumble_inv(message: bytearray) -> None: | ||
/// """Mutates a message by F4Jumble inverse permutation.""" | ||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_orchardlib_f4jumble_inv, | ||
orchardlib_f4jumble_inv); | ||
|
||
STATIC const mp_rom_map_elem_t mp_module_trezororchardlib_globals_table[] = { | ||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezororchardlib)}, | ||
{MP_ROM_QSTR(MP_QSTR_f4jumble), MP_ROM_PTR(&mod_orchardlib_f4jumble)}, | ||
{MP_ROM_QSTR(MP_QSTR_f4jumble_inv), | ||
MP_ROM_PTR(&mod_orchardlib_f4jumble_inv)}, | ||
|
||
}; | ||
|
||
STATIC MP_DEFINE_CONST_DICT(mp_module_trezororchardlib_globals, | ||
mp_module_trezororchardlib_globals_table); | ||
|
||
const mp_obj_module_t mp_module_trezororchardlib = { | ||
.base = {&mp_type_module}, | ||
.globals = (mp_obj_dict_t *)&mp_module_trezororchardlib_globals, | ||
}; | ||
|
||
MP_REGISTER_MODULE(MP_QSTR_trezororchardlib, mp_module_trezororchardlib, | ||
USE_ZCASH); | ||
|
||
#endif // USE_ZCASH |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! This module is a python FFI bridge for f4jumble crate. | ||
|
||
use core::ops::DerefMut; | ||
use f4jumble; | ||
|
||
use crate::error::Error; | ||
use crate::micropython::{buffer::BufferMut, obj::Obj, util}; | ||
|
||
// Length of F4jumbled message must be in range 48..=4194368. | ||
impl From<f4jumble::Error> for Error { | ||
fn from(_e: f4jumble::Error) -> Error { | ||
Error::OutOfRange | ||
} | ||
} | ||
|
||
/// Apply the F4jumble permutation to a message. | ||
#[no_mangle] | ||
pub extern "C" fn orchardlib_f4jumble(message: Obj) -> Obj { | ||
let block = || { | ||
let mut message: BufferMut = message.try_into()?; | ||
f4jumble::f4jumble_mut(message.deref_mut())?; | ||
Ok(Obj::const_none()) | ||
}; | ||
unsafe { util::try_or_raise(block) } | ||
} | ||
|
||
/// Apply the F4jumble inverse permutation to a message. | ||
#[no_mangle] | ||
pub extern "C" fn orchardlib_f4jumble_inv(message: Obj) -> Obj { | ||
let block = || { | ||
let mut message: BufferMut = message.try_into()?; | ||
f4jumble::f4jumble_inv_mut(message.deref_mut())?; | ||
Ok(Obj::const_none()) | ||
}; | ||
unsafe { util::try_or_raise(block) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod f4jumble_bridge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import * | ||
|
||
|
||
# extmod/rustmods/modtrezororchardlib.c | ||
def f4jumble(message: bytearray) -> None: | ||
"""Mutates a message by F4Jumble permutation.""" | ||
|
||
|
||
# extmod/rustmods/modtrezororchardlib.c | ||
def f4jumble_inv(message: bytearray) -> None: | ||
"""Mutates a message by F4Jumble inverse permutation.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,5 @@ VERSION_PATCH: int | |
MODEL: str | ||
EMULATOR: bool | ||
BITCOIN_ONLY: bool | ||
USE_ZCASH: bool | ||
FIRMWARE_SECTORS_COUNT: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.