Skip to content

Commit

Permalink
Merge pull request #13 from rootstock/hsm2-sim-2.1.0
Browse files Browse the repository at this point in the history
HSM Simulator Version 2.1.0
  • Loading branch information
amendelzon authored May 28, 2021
2 parents 9dfaaae + 194b42c commit ec6b8c6
Show file tree
Hide file tree
Showing 10 changed files with 529 additions and 0 deletions.
16 changes: 16 additions & 0 deletions v2/sim/2.1.0/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changes

Changes from version 0.1.4:

## Features/enhancements

- Added support for Iris network upgrade (by default activated from block 3,000,000 for mainnet and 2,000,000 for testnet -- final values TBD).
- Merge mining merkle proof maximum size set to 960 bytes from Iris onwards.
- Added three new unauthorized signing paths (see [the protocol documentation](./protocol.md) for details). The corresponding old paths are now deprecated.
- Added network 'regtest' with activation block numbers set to zero for testing purposes (`-n regtest` command line option).
- The build is now a `.tgz` bundle archive that contains the binary (`sim.tgz`). The docker runner build takes care of the extraction. Manual extraction is required to run outside of the given docker image.

## Fixes

- BTC transactions are now unsigned before computing the sighash (this mimics the actual ledger signer behavior).
- The build is now compatible with older glibc versions (2.24+)
10 changes: 10 additions & 0 deletions v2/sim/2.1.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM debian:bullseye-slim

WORKDIR /hsm2bin

COPY sim.tgz /hsm2bin/sim.tgz
RUN tar xzf sim.tgz > /dev/null 2>&1
RUN rm -f sim.tgz



32 changes: 32 additions & 0 deletions v2/sim/2.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# HSM2 Simulator v2.1.0

## Usage


### On linux:

#### Installing

```
mkdir sim
tar xzf sim.tgz -C sim
```

#### Running

```
./sim/sim --help
```

### On other operating systems:

#### Prerequisites

- Docker

#### Running

```
./sim-docker.sh --help
```

22 changes: 22 additions & 0 deletions v2/sim/2.1.0/logging.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[loggers]
keys=root

[handlers]
keys=console

[formatters]
keys=user

[logger_root]
level=NOTSET
handlers=console

[handler_console]
class=StreamHandler
level=DEBUG
formatter=user
args=(sys.stdout,)

[formatter_user]
format=[%(levelname)s:%(name)s] %(message)s
class=logging.Formatter
118 changes: 118 additions & 0 deletions v2/sim/2.1.0/protocol-v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# FedHM protocol definition v1.x

## About

This document describes the legacy protocol used in version 1 of the HSM. The purpose is to provide a reference for the usage of the legacy mode both in the simulator and manager (with modifier `--version-one`).

## Definitions

- `xxxxx`: String
- `hhhh`: Hex string
- `i`: Integer
- `b`: Boolean

## Commands

### Get version

#### Request
```
{
"command": "version"
}
```

#### Response
```
{
"version": 1,
"errorcode": i
}
```

**Error codes:**
This operation can return `0` and generic errors. See the error codes section for details.

### Sign

#### Request

This command will only work with the authorized key ids (see corresponding section for details).

```
{
"command": "sign",
"keyId": "xxxxx", // (*)
"message": "hhhh", // (**)
"version": 1
}
// (*) the given string must be the
// BIP44 path of the key to use for signing.
// See valid BIP44 paths below.
// (**) the hash that needs to be signed.
```

#### Response
```
{
"signature": {
"r": "hhhh",
"s": "hhhh"
},
"errorcode": i
}
```

### Get public key

#### Request
```
{
"command": "getPubKey",
"keyId": "xxxxx", // (*)
"version": 1
}
// (*) the given string must be the
// BIP44 path of the key of which to retrieve
// the public key. See valid BIP44 paths below.
```

#### Response
```
{
"pubKey": "hhhh",
"errorcode": i
}
```

### Error and success codes

The following are all the possible error and success codes:

#### Success codes
- `0`: Ok

#### Error codes

These errors can be returned by all operations.

-`-2`: General error in operation
-`-666`: Invalid version

### Valid BIP44 paths

For any operation that requires a `keyId` parameter, the following are the
only accepted BIP44 paths:

- RSK key id - `m/44'/137'/0'/0/0` (\*)
- MST key id - `m/44'/137'/1'/0/0` (\*)
- MST key id - `m/44'/137'/0'/0/1` (\*) (\*\*)
- tRSK key id - `m/44'/1'/1'/0/0` (\*)
- tRSK key id - `m/44'/1'/0'/0/1` (\*) (\*\*)
- tMST key id - `m/44'/1'/2'/0/0` (\*)
- tMST key id - `m/44'/1'/0'/0/2` (\*) (\*\*)

(\*) Sign operations using these keys don't require authorization.
(\*\*) These keys are deprecated and will be removed in a future version.
Loading

0 comments on commit ec6b8c6

Please sign in to comment.