Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge #113
Browse files Browse the repository at this point in the history
113: SDK v1.0.21: Public Keys + getDeployHashWithRPC r=zie1ony a=zie1ony

## 1.0.21

### Added

- `CasperClient.getDeployByHashFromRPC` allows for getting `Deploy` instance from the Node's RPC.

### Fixed

- Secp keys generator returns `Uint8Array` instead of `Buffer`.

### Changed

- `CLValue.publicKey` accepts `PublicKey` object.

Co-authored-by: Maciej Zielinski <maciek.s.zielinski@gmail.com>
  • Loading branch information
bors[bot] and zie1ony authored Feb 12, 2021
2 parents e30e75d + bf72893 commit 1a1aa12
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
14 changes: 14 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to casper-client-sdk.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.21

### Added

- `CasperClient.getDeployByHashFromRPC` allows for getting `Deploy` instance from the Node's RPC.

### Fixed

- Secp keys generator returns `Uint8Array` instead of `Buffer`.

### Changed

- `CLValue.publicKey` accepts `PublicKey` object.

## 1.0.20

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casper-client-sdk",
"version": "1.0.20",
"version": "1.0.21",
"license": "Apache 2.0",
"description": "SDK to interact with the Casper blockchain",
"main": "dist/index.js",
Expand Down
12 changes: 10 additions & 2 deletions packages/sdk/src/lib/CLValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ export class PublicKey extends CLTypedAndToBytes {
return accountHash;
}

public isEd25519() {
return this.tag === ED25519_TAG
}

public isSecp256K1() {
return this.tag === SECP256K1_TAG
}

public toAccountHash(): Uint8Array {
const algorithmIdentifier = this.signatureAlgorithm();
const separator = Buffer.from([0]);
Expand Down Expand Up @@ -1629,8 +1637,8 @@ export class CLValue implements ToBytes {
return CLValue.fromT(new MapValue(mapEntries));
}

public static publicKey(publicKey: Uint8Array) {
return CLValue.fromT(PublicKey.fromEd25519(publicKey));
public static publicKey(publicKey: PublicKey) {
return CLValue.fromT(publicKey);
}

public static byteArray(bytes: Uint8Array) {
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk/src/lib/CasperClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CasperServiceByJsonRPC,
DeployResult,
EventService,
GetDeployResult,
TransferResult
} from '../services';
import { DeployUtil, Keys, PublicKey } from './index';
Expand Down Expand Up @@ -254,6 +255,17 @@ export class CasperClient {
return await this.eventStoreClient.getDeployByHash(deployHash);
}

/**
* Get deploy by hash from RPC.
* @param deployHash
* @returns Tuple of Deploy and raw RPC response.
*/
public async getDeployByHashFromRPC(deployHash: string): Promise<[Deploy, GetDeployResult]> {
return await this.nodeClient.getDeployInfo(deployHash).then((result: GetDeployResult) => {
return [DeployUtil.deployFromJson(result)!, result];
});
}

/**
* Get the main purse uref for the specified publicKey
* @param publicKey
Expand Down
5 changes: 4 additions & 1 deletion packages/sdk/src/lib/CasperHDKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class CasperHDKey {
*/
public derive(path: string): Secp256K1 {
const secpKeyPair = this.hdKey.derive(path);
return new Secp256K1(secpKeyPair.publicKey!, secpKeyPair.privateKey!);
return new Secp256K1(
new Uint8Array(secpKeyPair.publicKey!),
new Uint8Array(secpKeyPair.privateKey!)
);
}

/**
Expand Down
16 changes: 7 additions & 9 deletions packages/sdk/test/lib/DeployUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ describe('DeployUtil', () => {
});

it('should allow to extract additional args from Transfer.', function () {
const from = Keys.Ed25519.new();
// const from = Keys.Ed25519.new();
const from = Keys.Secp256K1.new();
const to = Keys.Ed25519.new();
const networkName = 'test-network';
const paymentAmount = 10000000000000;
Expand All @@ -189,28 +190,25 @@ describe('DeployUtil', () => {
);
let payment = DeployUtil.standardPayment(paymentAmount);
let deploy = DeployUtil.makeDeploy(deployParams, session, payment);
let fromRawPK = from.publicKey.rawPublicKey;

let transferDeploy = DeployUtil.addArgToDeploy(
deploy,
'fromPublicKey',
CLValue.publicKey(fromRawPK)
CLValue.publicKey(from.publicKey)
);

assert.deepEqual(
transferDeploy.session.getArgByName('fromPublicKey')?.asPublicKey()
.rawPublicKey,
fromRawPK
transferDeploy.session.getArgByName('fromPublicKey')?.asPublicKey(),
from.publicKey
);

let newTransferDeploy = DeployUtil.deployFromJson(
DeployUtil.deployToJson(transferDeploy)
);

assert.deepEqual(
newTransferDeploy?.session.getArgByName('fromPublicKey')?.asPublicKey()
.rawPublicKey,
fromRawPK
newTransferDeploy?.session.getArgByName('fromPublicKey')?.asPublicKey(),
from.publicKey
);
});
});
5 changes: 3 additions & 2 deletions packages/ui/src/lib/DeployArgumentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
KeyValue,
NamedArg,
MapEntry,
CLTypedAndToBytesHelper
CLTypedAndToBytesHelper,
PublicKey
} from 'casper-client-sdk';
import { FormState } from 'formstate';
import {
Expand Down Expand Up @@ -425,7 +426,7 @@ export class DeployArgumentParser {
);
break;
case SimpleType.PublicKey:
clValueInstance = CLValue.publicKey(decodeBase16(argValueInJson));
clValueInstance = CLValue.publicKey(PublicKey.fromEd25519(decodeBase16(argValueInJson)));
break;
}
return clValueInstance;
Expand Down

0 comments on commit 1a1aa12

Please sign in to comment.