antelopeql 1.1.2 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/antelopeql.mjs CHANGED
@@ -24,7 +24,7 @@ import serialize_transaction from "./serialize_transaction.mjs";
24
24
  * @property {String} [operationName] GraphQL operation name (query resolution).
25
25
  * @property {Function} [fetch] Custom fetch implementation.
26
26
  * @property {Array<String>} [contracts] List of Antelope smart contracts.
27
- * @property {Array<String>} [private_keys] List of private keys used to sign transactions.
27
+ * @property {async Function} [signTransaction] A function to sign the Antelope transaction.
28
28
  * @property {Headers} [headers] Headers to pass to the network request.
29
29
  * @property {AbortSignal} [signal] Abort controller signal.
30
30
  */
@@ -61,9 +61,9 @@ export default async function AntelopeQL({
61
61
  query,
62
62
  variableValues,
63
63
  operationName,
64
+ signTransaction,
64
65
  fetch,
65
66
  contracts = [],
66
- private_keys = [],
67
67
  ABIs = [],
68
68
  rpc_url,
69
69
  headers,
@@ -127,7 +127,7 @@ export default async function AntelopeQL({
127
127
  rootValue: "",
128
128
  contextValue: {
129
129
  network: { rpc_url, fetch, ...fetchOptions },
130
- private_keys
130
+ signTransaction
131
131
  },
132
132
  variableValues,
133
133
  operationName,
@@ -0,0 +1,11 @@
1
+ // const { required_keys, ...errors } = await fetch(
2
+ // `${rpc_url}/v1/chain/get_required_keys`,
3
+ // {
4
+ // method: "POST",
5
+ // ...fetchOptions,
6
+ // body: JSON.stringify({
7
+ // available_keys,
8
+ // transaction
9
+ // })
10
+ // }
11
+ // ).then((res) => res.json());
@@ -1,5 +1,3 @@
1
- import legacy_to_public_key from "antelope-ecc/legacy_to_public_key.mjs";
2
- import validate_public_key from "antelope-ecc/validate_public_key.mjs";
3
1
  import { GraphQLScalarType } from "graphql";
4
2
 
5
3
  const public_key_type = new GraphQLScalarType({
@@ -9,19 +7,18 @@ const public_key_type = new GraphQLScalarType({
9
7
  Public keys should begin with PUB_K1 (or EOS for legacy keys) and include base58 characters only.
10
8
  `,
11
9
  name: "public_key",
12
- async serialize(legacy_key) {
13
- if (!legacy_key.startsWith("EOS")) return legacy_key;
14
-
15
- return legacy_to_public_key(legacy_key);
16
- },
17
10
  async parseValue(public_key) {
18
11
  if (public_key == "") return "";
19
12
 
20
- try {
21
- await validate_public_key(public_key);
22
- } catch (err) {
23
- throw new RangeError(err.message);
24
- }
13
+ if (
14
+ !public_key.startsWith("PUB_K1_") &&
15
+ !public_key.startsWith("PUB_R1_") &&
16
+ !public_key.startsWith("PUB_WA_") &&
17
+ !public_key.startsWith("EOS")
18
+ )
19
+ throw new RangeError(
20
+ "Public keys must be either K1, R1, WA or legacy keys."
21
+ );
25
22
 
26
23
  return public_key;
27
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antelopeql",
3
- "version": "1.1.2",
3
+ "version": "2.0.0-rc.0",
4
4
  "description": "A GraphQL implementation for interacting with Antelope based blockchains.",
5
5
  "repository": "github:pur3miish/antelopeql",
6
6
  "bugs": "https://github.com/pur3miish/antelopeql/issues",
@@ -91,9 +91,9 @@
91
91
  "graphql": "^16.6.0"
92
92
  },
93
93
  "dependencies": {
94
- "antelope-ecc": "^1.0.0",
95
94
  "base58-js": "^2.0.0",
96
- "eosio-wasm-js": "^4.0.1",
97
- "ripemd160-js": "*"
95
+ "eosio-wasm-js": "^4.1.0",
96
+ "ripemd160-js": "*",
97
+ "universal-sha256-js": "^2.0.0"
98
98
  }
99
99
  }
@@ -1,7 +1,5 @@
1
- import private_key_to_legacy from "antelope-ecc/private_key_to_legacy.mjs";
2
- import get_public_key from "antelope-ecc/public_key_from_private.mjs";
3
- import sign_packed_txn from "antelope-ecc/sign_packed_txn.mjs";
4
- import { GraphQLError, GraphQLNonNull } from "graphql";
1
+ import { GraphQLNonNull } from "graphql";
2
+ import sha256 from "universal-sha256-js/sha256.mjs";
5
3
 
6
4
  import configuration_type from "./graphql_input_types/configuration.mjs";
7
5
  import transaction_receipt from "./graphql_object_types/transaction_receipt.mjs";
@@ -20,51 +18,29 @@ const push_transaction = (actions, ast_list) => ({
20
18
  type: configuration_type
21
19
  }
22
20
  },
23
- async resolve(_, args, { network, private_keys }) {
21
+ async resolve(_, args, { network, signTransaction }) {
24
22
  const { chain_id, transaction_header, transaction_body, transaction } =
25
23
  await mutation_resolver(args, network, ast_list);
26
24
 
27
- const key_pairs = {};
28
- for await (const key of private_keys) {
29
- const PVT = await private_key_to_legacy(key);
30
- const PUB = await get_public_key(PVT);
31
- key_pairs[PUB] = PVT;
32
- }
33
- const available_keys = Object.keys(key_pairs);
34
-
35
- const { fetch, rpc_url, ...fetchOptions } = network;
36
-
37
- if (!available_keys.length)
38
- throw new GraphQLError("No private keys found.");
25
+ const transaction_bytes = chain_id + transaction_header + transaction_body;
39
26
 
40
- const { required_keys, ...errors } = await fetch(
41
- `${rpc_url}/v1/chain/get_required_keys`,
42
- {
43
- method: "POST",
44
- ...fetchOptions,
45
- body: JSON.stringify({
46
- available_keys,
47
- transaction
48
- })
49
- }
50
- ).then((res) => res.json());
51
-
52
- if (errors.message)
53
- throw new GraphQLError("No transaction sent", {
54
- extensions: errors
55
- });
56
-
57
- const signatures = await Promise.all(
58
- required_keys.map((pub) =>
59
- sign_packed_txn({
60
- chain_id,
61
- transaction_body,
62
- transaction_header,
63
- wif_private_key: key_pairs[pub]
64
- })
27
+ const hash_to_sign = await sha256(
28
+ Uint8Array.from(
29
+ transaction_bytes
30
+ .match(/[a-fA-F0-9]{2}/gmu)
31
+ .map((i) => Number(`0x${i}`))
65
32
  )
66
33
  );
67
34
 
35
+ const signatures = await signTransaction(hash_to_sign, {
36
+ serilaised_txn: {
37
+ chain_id,
38
+ transaction_header,
39
+ transaction_body
40
+ },
41
+ transaction
42
+ });
43
+
68
44
  return push_transaction_rpc(
69
45
  { transaction_body, transaction_header, signatures },
70
46
  network
@@ -17,6 +17,9 @@ export default async function push_transaction_rpc(
17
17
  network
18
18
  ) {
19
19
  const { fetch, rpc_url, ...fetchOptions } = network;
20
+
21
+ console.log(transaction_body);
22
+
20
23
  const pushed_txn_req = await fetch(`${rpc_url}/v1/chain/push_transaction`, {
21
24
  method: "POST",
22
25
  ...fetchOptions,
@@ -27,6 +30,7 @@ export default async function push_transaction_rpc(
27
30
  packed_trx: transaction_header + transaction_body
28
31
  })
29
32
  });
33
+
30
34
  const pushed_transaction = await pushed_txn_req.json();
31
35
  if (pushed_transaction.error)
32
36
  throw new GraphQLError(pushed_transaction.message, {
package/readme.md CHANGED
@@ -24,24 +24,6 @@ For [Node.js](https://nodejs.org), to install [`AntelopeQL`](https://npm.im/ante
24
24
  npm install antelopeql graphql
25
25
  ```
26
26
 
27
- For [Deno.js](https://deno.land), to install [`AntelopeQL`](https://deno.land/x/antelopeql) add to your `deno.json` configuration file these imports:
28
-
29
- ```json
30
- {
31
- "imports": {
32
- "universal-sha256-js/": "https://deno.land/x/sha256js/",
33
- "universal-hmac-sha256-js/": "https://deno.land/x/hmacsha256/",
34
- "universal-hmac-sha256-js/hmac-sha256-node.mjs": "https://deno.land/x/hmacsha256/hmac-sha256-deno.mjs",
35
- "base58-js/": "https://deno.land/x/base58/",
36
- "isomorphic-secp256k1-js/": "https://deno.land/x/secp256k1js/",
37
- "ripemd160-js/": "https://deno.land/x/ripemd160js@v2.0.3/",
38
- "eosio-wasm-js/": "https://deno.land/x/eosio_wasm_js/",
39
- "antelope-ecc/": "https://deno.land/x/eosio_ecc/",
40
- "graphql": "https://cdn.skypack.dev/graphql"
41
- }
42
- }
43
- ```
44
-
45
27
  ## Examples
46
28
 
47
29
  See the examples folder on how to run AntelopeQL as a [Node.js](https://nodejs.org) endpoint.
@@ -98,7 +80,8 @@ import fetch from "node-fetch";
98
80
  import AntelopeQL from "antelopeql/antelopeql.mjs";
99
81
 
100
82
  const { data } = await AntelopeQL({
101
- query: /*GraphQL*/ `mutation{
83
+ query: /*GraphQL*/ `
84
+ mutation{
102
85
  push_transaction(actions: [{
103
86
  eosio_token:{
104
87
  transfer: {
@@ -117,7 +100,11 @@ const { data } = await AntelopeQL({
117
100
  }
118
101
  }`,
119
102
  contracts: ["eosio.token"],
120
- private_keys: ["PVT_K1_…"], // legacy keys support.
103
+ signTransaction: async () => {
104
+ const private_keys = [...] // your private keys
105
+ const signatures = generate_signature_function(...privatekeys) // your antelope digital signature provider
106
+ return signatures // signaures must return array
107
+ }
121
108
  fetch,
122
109
  rpc_url: "https://eos.relocke.io", // eos blockchain.
123
110
  headers: {