Skip to content

Commit d33d457

Browse files
author
Gil Amran
committed
Merge branch 'master' of github.com:orbs-network/orbs-client-sdk-javascript
2 parents f6e60ab + 03a9f1d commit d33d457

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orbs-client-sdk",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "orbs-client-sdk",
55
"main": "dist/orbs-client-sdk.js",
66
"browser": "dist/orbs-client-sdk-web.js",

src/crypto/Digest.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2019 the orbs-client-sdk-javascript authors
3+
* This file is part of the orbs-client-sdk-javascript library in the Orbs project.
4+
*
5+
* This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
6+
* The above notice should be included in all copies or substantial portions of the software.
7+
*/
8+
9+
import * as Digest from "./Digest";
10+
import { encodeHex } from "./Encoding";
11+
12+
test("HexEncodeWithChecksum", () => {
13+
expect(() => { Digest.contractNameToAddressAsBytes(""); }).toThrowError("invalid contract name");
14+
15+
// This value was generated by orbs-contract-sdk-go which was tested with an e2e test against gamma
16+
expect(encodeHex(Digest.contractNameToAddressAsBytes("ERC721Receiver1567581564581813000"))).toEqual("0x63D2fE13c426Fe78E3C92E0B22d04508c54aA4BF");
17+
});

src/crypto/Digest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ export function extractTxId(txId: Uint8Array): [Uint8Array, bigint] {
4747
export function calcQueryHash(queryBuf: Uint8Array): Uint8Array {
4848
return Hash.calcSha256(queryBuf);
4949
}
50+
51+
export function contractNameToAddressAsBytes(contractName: string): Uint8Array {
52+
if (!contractName || contractName === "") {
53+
throw new Error("invalid contract name");
54+
}
55+
56+
return calcSha256(new TextEncoder().encode(contractName)).slice(CLIENT_ADDRESS_SHA256_OFFSET);
57+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export { createAccount, addressToBytes, bytesToAddress, Account } from "./orbs/A
1010
export { ExecutionResult } from "./codec/ExecutionResult";
1111
export { RequestStatus } from "./codec/RequestStatus";
1212
export { Client, PROCESSOR_TYPE_NATIVE, PROCESSOR_TYPE_JAVASCRIPT } from "./orbs/Client";
13-
export { calcClientAddressOfEd25519PublicKey } from "./crypto/Digest";
13+
export { calcClientAddressOfEd25519PublicKey, contractNameToAddressAsBytes } from "./crypto/Digest";
1414
export { encodeHex, decodeHex } from "./crypto/Encoding";
1515
export { argUint32, argUint64, argString, argBytes, argAddress } from "./codec/Arguments";
1616
export { NetworkType } from "./codec/NetworkType";

0 commit comments

Comments
 (0)