Skip to content

Commit

Permalink
Merge a599924 into 08bbd9d
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymoussprocket committed Jul 3, 2020
2 parents 08bbd9d + a599924 commit 733718b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ npm i conseiljs-softsigner
import fetch from 'node-fetch';
import * as log from 'loglevel';

import { registerFetch, registerLogger } from 'conseiljs';
import { registerFetch, registerLogger, Signer, TezosMessageUtils } from 'conseiljs';
import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner';

const logger = log.getLogger('conseiljs');
Expand All @@ -40,8 +40,8 @@ registerLogger(logger);
registerFetch(fetch);

let signer: Signer;
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey ('edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH');
signer = new SoftSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'));
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH');
signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1);
```

## Use with React
Expand All @@ -56,7 +56,7 @@ TBD

```html
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs/dist-web/conseiljs.min.js"
integrity="sha384-zf1JnFgeBkUovmAPQjLAJl81QYeEwY3HcMv626FdnOq1cS9pnxSbuBi4tZPfhGjd"
integrity="sha384-CDpCW4rM4qw7oEyOr5wSQNqnPmQw9vtCoqWyKSDIys50jRONU+j+uxk/aEy0QzRJ"
crossorigin="anonymous"></script>
```

Expand Down
2 changes: 1 addition & 1 deletion dist-web/conseiljs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ We have a complete [React application example](https://github.com/Cryptonomic/Co

```html
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs/dist-web/conseiljs.min.js"
integrity="sha384-zf1JnFgeBkUovmAPQjLAJl81QYeEwY3HcMv626FdnOq1cS9pnxSbuBi4tZPfhGjd"
integrity="sha384-CDpCW4rM4qw7oEyOr5wSQNqnPmQw9vtCoqWyKSDIys50jRONU+j+uxk/aEy0QzRJ"
crossorigin="anonymous"></script>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('TezosContractIntrospector integration test suite', () => {
contractQuery = ConseilQueryBuilder.addPredicate(contractQuery, 'account_id', ConseilOperator.STARTSWITH, ['KT1']);
contractQuery = ConseilQueryBuilder.addPredicate(contractQuery, 'script', ConseilOperator.ISNULL, [], true);
contractQuery = ConseilQueryBuilder.addAggregationFunction(contractQuery, 'account_id', ConseilFunction.count);
contractQuery = ConseilQueryBuilder.addOrdering(contractQuery, 'count_account_id', ConseilSortDirection.DESC)
contractQuery = ConseilQueryBuilder.addOrdering(contractQuery, 'count_account_id', ConseilSortDirection.DESC);
contractQuery = ConseilQueryBuilder.setLimit(contractQuery, cap);

const contractList = await ConseilDataClient.executeEntityQuery(conseilServer, 'tezos', conseilServer.network, 'accounts', contractQuery);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "conseiljs",
"version": "5.0.2-beta.2",
"version": "5.0.2-beta.3",
"description": "Client-side library for dApp development.",
"browser": "dist/index-web.js",
"main": "dist/index.js",
Expand Down
3 changes: 3 additions & 0 deletions src/chain/tezos/TezosMessageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ export namespace TezosMessageUtils {

/**
* Computes a BLAKE2b message hash of the requested length.
*
* @param {Buffer} payload Buffer to hash
* @param {number} length Length of hash to produce
*/
export function simpleHash(payload: Buffer, length: number) : Buffer {
return Buffer.from(blakejs.blake2b(payload, null, length)); // Same as libsodium.crypto_generichash
Expand Down
50 changes: 44 additions & 6 deletions src/reporting/tezos/TezosConseilClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ export namespace TezosConseilClient {
/**
* Returns big_map data for a given contract if any is available.
*
* @param serverInfo Conseil server connection definition.
* @param accountID Account hash to query for.
* @param serverInfo Conseil server connection definition.
* @param contract Contract address to query for.
*/
export async function getBigMapData(serverInfo: ConseilServerInfo, accountID: string): Promise<ContractMapDetails | undefined> {
if (!accountID.startsWith('KT1')) { throw new Error('Invalid address'); }
export async function getBigMapData(serverInfo: ConseilServerInfo, contract: string): Promise<ContractMapDetails | undefined> {
if (!contract.startsWith('KT1')) { throw new Error('Invalid address'); }

const ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.addFields(ConseilQueryBuilder.addPredicate(ConseilQueryBuilder.blankQuery(), 'account_id', ConseilOperator.EQ, [accountID], false), 'big_map_id'), 100);
const ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.addFields(ConseilQueryBuilder.addPredicate(ConseilQueryBuilder.blankQuery(), 'account_id', ConseilOperator.EQ, [contract], false), 'big_map_id'), 100);
const ownerResult = await getTezosEntityData(serverInfo, serverInfo.network, 'originated_account_maps', ownerQuery);

if (ownerResult.length < 1) { return undefined; }
Expand All @@ -296,7 +296,45 @@ export namespace TezosConseilClient {
maps.push({definition, content});
}

return { contract: accountID, maps };
return { contract, maps };
}

/**
* Returns a value for a given plain-text key. The big map id is either provided as a paramter or the smallest of the possibly multiple big maps associated with the given contract address is used. Note that sometimes key values must be wrapped in quotes for key types that are non-numeric and not byte type.
*
* Under normal circumstances these keys are hashed and TezosNodeReader.getValueForBigMapKey() expects such an encoded key. However, with the Conseil indexer it's possible to query for plain-text keys.
*
* @param serverInfo Conseil server connection definition.
* @param key Key to query for.
* @param contract Optional contract address to be used to identify an associated big map.
* @param mapIndex Optional big map index to query, but one of contract or mapIndex must be provided.
*/
export async function getBigMapValueForKey(serverInfo: ConseilServerInfo, key: string, contract: string = '', mapIndex: number = -1): Promise<string> {
if (!contract.startsWith('KT1')) { throw new Error('Invalid address'); }
if (key.length < 1) { throw new Error('Invalid key'); }
if (mapIndex < 0 && contract.length === 0) { throw new Error('One of contract or mapIndex must be specified'); }

if (mapIndex < 0 && contract.length > 0) {
let ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.blankQuery(), 1);
ownerQuery = ConseilQueryBuilder.addFields(ownerQuery, 'big_map_id');
ownerQuery = ConseilQueryBuilder.addPredicate(ownerQuery, 'account_id', ConseilOperator.EQ, [contract], false);
ownerQuery = ConseilQueryBuilder.addOrdering(ownerQuery, 'big_map_id', ConseilSortDirection.DESC);

const ownerResult = await getTezosEntityData(serverInfo, serverInfo.network, 'originated_account_maps', ownerQuery);

if (ownerResult.length < 1) { throw new Error(`Could not find any maps for ${contract}`); }
mapIndex = ownerResult[0];
}

let contentQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.blankQuery(), 1);
contentQuery = ConseilQueryBuilder.addFields(contentQuery, 'value');
contentQuery = ConseilQueryBuilder.addPredicate(contentQuery, 'key', ConseilOperator.EQ, [key], false);
contentQuery = ConseilQueryBuilder.addPredicate(contentQuery, 'big_map_id', ConseilOperator.EQ, [mapIndex], false);
const contentResult = await getTezosEntityData(serverInfo, serverInfo.network, 'big_map_contents', contentQuery);

if (contentResult.length < 1) { throw new Error(`Could not a value for key ${key} in map ${mapIndex}`); }

return contentResult[0];
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/types/ExternalInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Signer {
signOperation: (bytes: Buffer) => Promise<Buffer>;
signText: (message: string) => Promise<string>;
signTextHash: (message: string) => Promise<string>;
}

export interface KeyStore {
Expand Down

0 comments on commit 733718b

Please sign in to comment.