Skip to content

Commit

Permalink
runtime-sdk: solo -> signature
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed May 17, 2021
1 parent 88af89c commit 0f3d93a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 37 deletions.
4 changes: 2 additions & 2 deletions client-sdk/go/modules/consensusaccounts/consensus_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *v1) Deposit(ctx context.Context, signer signature.Signer, nonce uint64,
}

tx := types.NewTransaction(nil, methodDeposit, deposit)
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
if err = stx.AppendSign(info.ChainContext, signer); err != nil {
return err
Expand All @@ -63,7 +63,7 @@ func (a *v1) Withdraw(ctx context.Context, signer signature.Signer, nonce uint64
}

tx := types.NewTransaction(nil, methodWithdraw, withdraw)
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
if err = stx.AppendSign(info.ChainContext, signer); err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions client-sdk/go/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var SignatureContextBase = []byte("oasis-runtime-sdk/tx: v0")
const LatestTransactionVersion = 1

type AuthProof struct {
Solo []byte `json:"solo,omitempty"`
Multisig [][]byte `json:"multisig,omitempty"`
Signature []byte `json:"signature,omitempty"`
Multisig [][]byte `json:"multisig,omitempty"`
}

// UnverifiedTransaction is an unverified transaction.
Expand Down Expand Up @@ -83,8 +83,8 @@ func (ts *TransactionSigner) AppendSign(ctx signature.Context, signer signature.
any := false
for i, si := range ts.tx.AuthInfo.SignerInfo {
switch {
case si.AddressSpec.Solo != nil:
if !si.AddressSpec.Solo.Equal(pk) {
case si.AddressSpec.Signature != nil:
if !si.AddressSpec.Signature.Equal(pk) {
continue
}

Expand All @@ -96,7 +96,7 @@ func (ts *TransactionSigner) AppendSign(ctx signature.Context, signer signature.
if err != nil {
return fmt.Errorf("signer info %d: failed to sign transaction: %w", i, err)
}
ts.ut.AuthProofs[i].Solo = sig
ts.ut.AuthProofs[i].Signature = sig
case si.AddressSpec.Multisig != nil:
for j, mss := range si.AddressSpec.Multisig.Signers {
if !mss.PublicKey.Equal(pk) {
Expand Down Expand Up @@ -204,14 +204,14 @@ type Fee struct {
}

type AddressSpec struct {
Solo *PublicKey `json:"solo,omitempty"`
Multisig *MultisigConfig `json:"multisig,omitempty"`
Signature *PublicKey `json:"signature,omitempty"`
Multisig *MultisigConfig `json:"multisig,omitempty"`
}

func (as *AddressSpec) Address() (Address, error) {
switch {
case as.Solo != nil:
return NewAddress(as.Solo), nil
case as.Signature != nil:
return NewAddress(as.Signature), nil
case as.Multisig != nil:
return NewAddressFromMultisig(as.Multisig), nil
default:
Expand All @@ -221,8 +221,8 @@ func (as *AddressSpec) Address() (Address, error) {

func (as *AddressSpec) Batch(ap AuthProof) ([]PublicKey, [][]byte, error) {
switch {
case as.Solo != nil && ap.Solo != nil:
return []PublicKey{*as.Solo}, [][]byte{ap.Solo}, nil
case as.Signature != nil && ap.Signature != nil:
return []PublicKey{*as.Signature}, [][]byte{ap.Signature}, nil
case as.Multisig != nil && ap.Multisig != nil:
return as.Multisig.Batch(ap.Multisig)
default:
Expand Down
4 changes: 2 additions & 2 deletions client-sdk/go/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestTransactionSigning(t *testing.T) {
signer2 := ed25519.WrapSigner(memorySigner.NewTestSigner("oasis-runtime-sdk/test-keys: tx signing 2"))

tx := NewTransaction(nil, "hello.World", nil)
tx.AppendSignerInfo(AddressSpec{Solo: &PublicKey{PublicKey: signer.Public()}}, 42)
tx.AppendSignerInfo(AddressSpec{Solo: &PublicKey{PublicKey: signer2.Public()}}, 43)
tx.AppendSignerInfo(AddressSpec{Signature: &PublicKey{PublicKey: signer.Public()}}, 42)
tx.AppendSignerInfo(AddressSpec{Signature: &PublicKey{PublicKey: signer2.Public()}}, 43)
tx.AppendSignerInfo(AddressSpec{Multisig: &MultisigConfig{
Signers: []MultisigSigner{
{PublicKey: PublicKey{PublicKey: signer.Public()}, Weight: 1},
Expand Down
4 changes: 2 additions & 2 deletions client-sdk/ts-web/rt/playground/src/consensus.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const playground = (async function () {
})
.query(nic);
const siAlice1 = /** @type {oasisRT.types.SignerInfo} */ ({
address_spec: {solo: {ed25519: csAlice.public()}},
address_spec: {signature: {ed25519: csAlice.public()}},
nonce: nonce1,
});

Expand Down Expand Up @@ -93,7 +93,7 @@ export const playground = (async function () {
})
.query(nic);
const siAlice2 = /** @type {oasisRT.types.SignerInfo} */ ({
address_spec: {solo: {ed25519: csAlice.public()}},
address_spec: {signature: {ed25519: csAlice.public()}},
nonce: nonce2,
});
const WITHDRAW_AMNT = /** @type {oasisRT.types.BaseUnits} */ ([
Expand Down
4 changes: 2 additions & 2 deletions client-sdk/ts-web/rt/playground/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const playground = (async function () {
})
.query(nic);
const siAlice1 = /** @type {oasisRT.types.SignerInfo} */ ({
address_spec: {solo: {ed25519: csAlice.public()}},
address_spec: {signature: {ed25519: csAlice.public()}},
nonce: nonce1,
});

Expand Down Expand Up @@ -204,7 +204,7 @@ export const playground = (async function () {
})
.query(nic);
const siAlice2 = /** @type {oasisRT.types.SignerInfo} */ ({
address_spec: {solo: {ed25519: csAlice.public()}},
address_spec: {signature: {ed25519: csAlice.public()}},
nonce: nonce2,
});

Expand Down
13 changes: 9 additions & 4 deletions client-sdk/ts-web/rt/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export async function signAny(
}
}

export async function proveSolo(
export async function proveSignature(
pk: types.PublicKey,
signer: AnySigner,
context: string,
body: Uint8Array,
) {
return {solo: await signAny(pk, signer, context, body)};
return {signature: await signAny(pk, signer, context, body)};
}

export async function proveMultisig(
Expand Down Expand Up @@ -77,8 +77,13 @@ export async function proveAny(
context: string,
body: Uint8Array,
) {
if ('solo' in addressSpec) {
return await proveSolo(addressSpec.solo, proofProvider as AnySigner, context, body);
if ('signature' in addressSpec) {
return await proveSignature(
addressSpec.signature,
proofProvider as AnySigner,
context,
body,
);
} else if ('multisig' in addressSpec) {
return await proveMultisig(
addressSpec.multisig,
Expand Down
4 changes: 2 additions & 2 deletions client-sdk/ts-web/rt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface RewardsRewardStep {
* Common information that specifies an address as well as how to authenticate.
*/
export interface AddressSpec {
solo?: PublicKey;
signature?: PublicKey;
multisig?: MultisigConfig;
}

Expand All @@ -87,7 +87,7 @@ export interface AuthInfo {
}

export interface AuthProof {
solo?: Uint8Array;
signature?: Uint8Array;
multisig?: Uint8Array[];
}

Expand Down
2 changes: 1 addition & 1 deletion runtime-sdk/src/modules/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl API for Module {
.signer_info[0]
.address_spec
{
AddressSpec::Solo(PublicKey::Ed25519(_)) => Ok(()),
AddressSpec::Signature(PublicKey::Ed25519(_)) => Ok(()),
_ => Err(Error::ConsensusIncompatibleSigner),
}
}
Expand Down
14 changes: 7 additions & 7 deletions runtime-sdk/src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum Error {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AuthProof {
#[serde(rename = "solo")]
Solo(Signature),
#[serde(rename = "signature")]
Signature(Signature),
#[serde(rename = "multisig")]
Multisig(multisig::SignatureSetOwned),
}
Expand Down Expand Up @@ -131,23 +131,23 @@ pub struct Fee {
/// Common information that specifies an address as well as how to authenticate.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum AddressSpec {
#[serde(rename = "solo")]
Solo(PublicKey),
#[serde(rename = "signature")]
Signature(PublicKey),
#[serde(rename = "multisig")]
Multisig(multisig::Config),
}

impl AddressSpec {
pub fn address(&self) -> Address {
match self {
AddressSpec::Solo(public_key) => Address::from_pk(public_key),
AddressSpec::Signature(public_key) => Address::from_pk(public_key),
AddressSpec::Multisig(config) => Address::from_multisig(config),
}
}

pub fn batch(&self, auth_proof: &AuthProof) -> Result<(Vec<PublicKey>, Vec<Signature>), Error> {
Ok(match (self, auth_proof) {
(AddressSpec::Solo(public_key), AuthProof::Solo(signature)) => {
(AddressSpec::Signature(public_key), AuthProof::Signature(signature)) => {
(vec![public_key.clone()], vec![signature.clone()])
}
(AddressSpec::Multisig(config), AuthProof::Multisig(signature_set)) => config
Expand All @@ -173,7 +173,7 @@ impl SignerInfo {
/// Create a new signer info from public key and nonce.
pub fn new(public_key: PublicKey, nonce: u64) -> Self {
Self {
address_spec: AddressSpec::Solo(public_key),
address_spec: AddressSpec::Signature(public_key),
nonce,
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/simplekvtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func kvInsert(rtc client.RuntimeClient, signer signature.Signer, key []byte, val
Key: key,
Value: value,
})
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
stx.AppendSign(chainCtx, signer)

Expand Down Expand Up @@ -109,7 +109,7 @@ func kvRemove(rtc client.RuntimeClient, signer signature.Signer, key []byte) err
}, "keyvalue.Remove", kvKey{
Key: key,
})
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
stx.AppendSign(chainCtx, signer)

Expand Down Expand Up @@ -370,7 +370,7 @@ func KVTransferTest(log *logging.Logger, conn *grpc.ClientConn, rtc client.Runti
To: testing.Bob.Address,
Amount: types.NewBaseUnits(*quantity.NewFromUint64(100), types.NativeDenomination),
})
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: testing.Alice.Signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: testing.Alice.Signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
stx.AppendSign(chainCtx, testing.Alice.Signer)

Expand Down Expand Up @@ -431,7 +431,7 @@ func KVDaveTest(log *logging.Logger, conn *grpc.ClientConn, rtc client.RuntimeCl
To: testing.Alice.Address,
Amount: types.NewBaseUnits(*quantity.NewFromUint64(10), types.NativeDenomination),
})
tx.AppendSignerInfo(types.AddressSpec{Solo: &types.PublicKey{PublicKey: testing.Dave.Signer.Public()}}, nonce)
tx.AppendSignerInfo(types.AddressSpec{Signature: &types.PublicKey{PublicKey: testing.Dave.Signer.Public()}}, nonce)
stx := tx.PrepareForSigning()
stx.AppendSign(chainCtx, testing.Dave.Signer)

Expand Down

0 comments on commit 0f3d93a

Please sign in to comment.