antelopeql 2.0.0-rc.8 → 2.0.0-rc.9
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.
|
@@ -3,6 +3,76 @@ import sha256 from "universal-sha256-js/sha256.mjs";
|
|
|
3
3
|
|
|
4
4
|
import bytes_type from "../eosio_types/bytes_type.mjs";
|
|
5
5
|
import public_key_type from "../eosio_types/public_key_type.mjs";
|
|
6
|
+
|
|
7
|
+
export const packed_transaction_fields = {
|
|
8
|
+
chain_id: {
|
|
9
|
+
type: bytes_type,
|
|
10
|
+
description: "A unique ID that specifies which chain we are operating on."
|
|
11
|
+
},
|
|
12
|
+
transaction_header: {
|
|
13
|
+
type: bytes_type,
|
|
14
|
+
description: "Serialized transaction header."
|
|
15
|
+
},
|
|
16
|
+
transaction_body: {
|
|
17
|
+
type: bytes_type,
|
|
18
|
+
description: "Serialized transaction body _(bytecode instructions)_."
|
|
19
|
+
},
|
|
20
|
+
required_keys: {
|
|
21
|
+
type: new GraphQLList(public_key_type),
|
|
22
|
+
description: "List of public keys needed to authorize transaction",
|
|
23
|
+
async resolve({ available_keys, transaction }, args, { network }) {
|
|
24
|
+
if (available_keys?.length) {
|
|
25
|
+
const keys = await Promise.all(available_keys);
|
|
26
|
+
|
|
27
|
+
const req = await fetch(
|
|
28
|
+
network.rpc_url + "/v1/chain/get_required_keys",
|
|
29
|
+
{
|
|
30
|
+
method: "post",
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
transaction: {
|
|
33
|
+
...transaction,
|
|
34
|
+
// Transform the transaction.actions into appropriate form for get_required_keys.
|
|
35
|
+
actions: transaction.actions.map(({ hex_data, ...action }) => ({
|
|
36
|
+
...action,
|
|
37
|
+
data: hex_data
|
|
38
|
+
}))
|
|
39
|
+
},
|
|
40
|
+
available_keys: keys
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
).then((res) => res.json());
|
|
44
|
+
|
|
45
|
+
if (req.error)
|
|
46
|
+
throw new GraphQLError(req.message, { extensions: req.error });
|
|
47
|
+
return req.required_keys;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
hash: {
|
|
52
|
+
type: bytes_type,
|
|
53
|
+
description: "Transaction hash to sign to authorize transaction",
|
|
54
|
+
async resolve({ chain_id, transaction_header, transaction_body }) {
|
|
55
|
+
const transaction_bytes =
|
|
56
|
+
chain_id +
|
|
57
|
+
transaction_header +
|
|
58
|
+
transaction_body +
|
|
59
|
+
"0000000000000000000000000000000000000000000000000000000000000000";
|
|
60
|
+
|
|
61
|
+
const hash_to_sign = await sha256(
|
|
62
|
+
Uint8Array.from(
|
|
63
|
+
transaction_bytes
|
|
64
|
+
.match(/[a-fA-F0-9]{2}/gmu)
|
|
65
|
+
.map((i) => Number(`0x${i}`))
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return [...hash_to_sign]
|
|
70
|
+
.map((x) => Number(x).toString(16).padStart(2, "0"))
|
|
71
|
+
.join("");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
6
76
|
/**
|
|
7
77
|
* The packed transaction type.
|
|
8
78
|
* @kind typedef
|
|
@@ -16,73 +86,7 @@ import public_key_type from "../eosio_types/public_key_type.mjs";
|
|
|
16
86
|
const packed_transaction_type = new GraphQLObjectType({
|
|
17
87
|
name: "packed_transaction",
|
|
18
88
|
description: "Packed transaction, chain ID and transaction header",
|
|
19
|
-
fields:
|
|
20
|
-
chain_id: {
|
|
21
|
-
type: bytes_type,
|
|
22
|
-
description: "A unique ID that specifies which chain we are operating on."
|
|
23
|
-
},
|
|
24
|
-
transaction_header: {
|
|
25
|
-
type: bytes_type,
|
|
26
|
-
description: "Serialized transaction header."
|
|
27
|
-
},
|
|
28
|
-
transaction_body: {
|
|
29
|
-
type: bytes_type,
|
|
30
|
-
description: "Serialized transaction body _(bytecode instructions)_."
|
|
31
|
-
},
|
|
32
|
-
required_keys: {
|
|
33
|
-
type: new GraphQLList(public_key_type),
|
|
34
|
-
description: "List of public keys needed to authorize transaction",
|
|
35
|
-
async resolve({ available_keys, transaction }, args, { network }) {
|
|
36
|
-
if (available_keys?.length) {
|
|
37
|
-
const keys = await Promise.all(available_keys);
|
|
38
|
-
|
|
39
|
-
const req = await fetch(
|
|
40
|
-
network.rpc_url + "/v1/chain/get_required_keys",
|
|
41
|
-
{
|
|
42
|
-
method: "post",
|
|
43
|
-
body: JSON.stringify({
|
|
44
|
-
transaction: {
|
|
45
|
-
...transaction,
|
|
46
|
-
// Transform the transaction.actions into appropriate form for get_required_keys.
|
|
47
|
-
actions: transaction.actions.map(
|
|
48
|
-
({ hex_data, ...action }) => ({ ...action, data: hex_data })
|
|
49
|
-
)
|
|
50
|
-
},
|
|
51
|
-
available_keys: keys
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
).then((res) => res.json());
|
|
55
|
-
|
|
56
|
-
if (req.error)
|
|
57
|
-
throw new GraphQLError(req.message, { extensions: req.error });
|
|
58
|
-
return req.required_keys;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
hash: {
|
|
63
|
-
type: bytes_type,
|
|
64
|
-
description: "Transaction hash to sign to authorize transaction",
|
|
65
|
-
async resolve({ chain_id, transaction_header, transaction_body }) {
|
|
66
|
-
const transaction_bytes =
|
|
67
|
-
chain_id +
|
|
68
|
-
transaction_header +
|
|
69
|
-
transaction_body +
|
|
70
|
-
"0000000000000000000000000000000000000000000000000000000000000000";
|
|
71
|
-
|
|
72
|
-
const hash_to_sign = await sha256(
|
|
73
|
-
Uint8Array.from(
|
|
74
|
-
transaction_bytes
|
|
75
|
-
.match(/[a-fA-F0-9]{2}/gmu)
|
|
76
|
-
.map((i) => Number(`0x${i}`))
|
|
77
|
-
)
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
return [...hash_to_sign]
|
|
81
|
-
.map((x) => Number(x).toString(16).padStart(2, "0"))
|
|
82
|
-
.join("");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
89
|
+
fields: packed_transaction_fields
|
|
86
90
|
});
|
|
87
91
|
|
|
88
92
|
export default packed_transaction_type;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antelopeql",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.9",
|
|
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",
|