@injectivelabs/sdk-ts 1.16.13-alpha.1 → 1.16.13-alpha.2
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/dist/cjs/utils/crypto.d.ts +1 -1
- package/dist/cjs/utils/crypto.js +42 -12
- package/dist/esm/utils/crypto.d.ts +1 -1
- package/dist/esm/utils/crypto.js +42 -12
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TypedDataDefinition } from 'viem';
|
|
2
2
|
export declare const hashToHex: (data: string) => string;
|
|
3
3
|
export declare const sha256: (data: Uint8Array) => Uint8Array;
|
|
4
4
|
export declare const ripemd160: (data: Uint8Array) => Uint8Array;
|
package/dist/cjs/utils/crypto.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.decompressPubKey = decompressPubKey;
|
|
|
10
10
|
// import CryptoEs from 'crypto-es'
|
|
11
11
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
12
12
|
const viem_1 = require("viem");
|
|
13
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
14
13
|
const viem_2 = require("viem");
|
|
14
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
15
15
|
const hashToHex = (data) => {
|
|
16
16
|
return crypto_js_1.default.SHA256(crypto_js_1.default.enc.Base64.parse(data))
|
|
17
17
|
.toString()
|
|
@@ -49,14 +49,26 @@ const privateKeyHashToPublicKeyBase64 = (privateKeyHash) => {
|
|
|
49
49
|
return Buffer.from((0, exports.privateKeyHashToPublicKey)(privateKeyHash)).toString('base64');
|
|
50
50
|
};
|
|
51
51
|
exports.privateKeyHashToPublicKeyBase64 = privateKeyHashToPublicKeyBase64;
|
|
52
|
+
// Hash only the domain portion
|
|
52
53
|
const domainHash = (message) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const domainTypedData = {
|
|
55
|
+
domain: message.domain,
|
|
56
|
+
types: message.types,
|
|
57
|
+
primaryType: 'EIP712Domain',
|
|
58
|
+
message: {},
|
|
59
|
+
};
|
|
60
|
+
return (0, viem_2.hashTypedData)(domainTypedData);
|
|
56
61
|
};
|
|
57
62
|
exports.domainHash = domainHash;
|
|
63
|
+
// Hash only the message portion
|
|
58
64
|
const messageHash = (message) => {
|
|
59
|
-
|
|
65
|
+
const messageTypedData = {
|
|
66
|
+
domain: {},
|
|
67
|
+
types: message.types,
|
|
68
|
+
primaryType: message.primaryType,
|
|
69
|
+
message: message.message,
|
|
70
|
+
};
|
|
71
|
+
return (0, viem_2.hashTypedData)(messageTypedData);
|
|
60
72
|
};
|
|
61
73
|
exports.messageHash = messageHash;
|
|
62
74
|
function uint8ArrayToHex(arr) {
|
|
@@ -107,14 +119,32 @@ const sanitizeTypedData = (data) => {
|
|
|
107
119
|
exports.sanitizeTypedData = sanitizeTypedData;
|
|
108
120
|
// Create a hashStruct function that mimics the original behavior
|
|
109
121
|
function hashStruct(primaryType, data, types, _version) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
if (!data) {
|
|
123
|
+
throw new Error('Invalid data: data is empty');
|
|
124
|
+
}
|
|
125
|
+
// For EIP-712, we need to create a complete structure
|
|
126
|
+
// The original implementation would hash just the specific part
|
|
127
|
+
let typedData;
|
|
128
|
+
if (primaryType === 'EIP712Domain') {
|
|
129
|
+
// For domain hash, we only need the domain data
|
|
130
|
+
typedData = {
|
|
131
|
+
domain: data,
|
|
132
|
+
types: { EIP712Domain: types.EIP712Domain },
|
|
133
|
+
primaryType: 'EIP712Domain',
|
|
134
|
+
message: {},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// For message hash, we need the complete structure
|
|
139
|
+
// Use the domain data if it's available in types
|
|
140
|
+
typedData = {
|
|
141
|
+
domain: types.domain || {},
|
|
142
|
+
types,
|
|
143
|
+
primaryType,
|
|
144
|
+
message: data,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
116
147
|
const hash = (0, viem_2.hashTypedData)(typedData);
|
|
117
|
-
// Return an object that mimics a Buffer with toString method for compatibility
|
|
118
148
|
return {
|
|
119
149
|
toString: (encoding) => {
|
|
120
150
|
if (encoding === 'hex') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TypedDataDefinition } from 'viem';
|
|
2
2
|
export declare const hashToHex: (data: string) => string;
|
|
3
3
|
export declare const sha256: (data: Uint8Array) => Uint8Array;
|
|
4
4
|
export declare const ripemd160: (data: Uint8Array) => Uint8Array;
|
package/dist/esm/utils/crypto.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// import CryptoEs from 'crypto-es'
|
|
2
2
|
import CryptoEs from 'crypto-js';
|
|
3
3
|
import { keccak256 } from 'viem';
|
|
4
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
5
4
|
import { hashTypedData } from 'viem';
|
|
5
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
6
6
|
export const hashToHex = (data) => {
|
|
7
7
|
return CryptoEs.SHA256(CryptoEs.enc.Base64.parse(data))
|
|
8
8
|
.toString()
|
|
@@ -33,13 +33,25 @@ export const privateKeyToPublicKeyBase64 = (privateKey) => {
|
|
|
33
33
|
export const privateKeyHashToPublicKeyBase64 = (privateKeyHash) => {
|
|
34
34
|
return Buffer.from(privateKeyHashToPublicKey(privateKeyHash)).toString('base64');
|
|
35
35
|
};
|
|
36
|
+
// Hash only the domain portion
|
|
36
37
|
export const domainHash = (message) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const domainTypedData = {
|
|
39
|
+
domain: message.domain,
|
|
40
|
+
types: message.types,
|
|
41
|
+
primaryType: 'EIP712Domain',
|
|
42
|
+
message: {},
|
|
43
|
+
};
|
|
44
|
+
return hashTypedData(domainTypedData);
|
|
40
45
|
};
|
|
46
|
+
// Hash only the message portion
|
|
41
47
|
export const messageHash = (message) => {
|
|
42
|
-
|
|
48
|
+
const messageTypedData = {
|
|
49
|
+
domain: {},
|
|
50
|
+
types: message.types,
|
|
51
|
+
primaryType: message.primaryType,
|
|
52
|
+
message: message.message,
|
|
53
|
+
};
|
|
54
|
+
return hashTypedData(messageTypedData);
|
|
43
55
|
};
|
|
44
56
|
export function uint8ArrayToHex(arr) {
|
|
45
57
|
return Buffer.from(arr).toString('hex');
|
|
@@ -87,14 +99,32 @@ export const sanitizeTypedData = (data) => {
|
|
|
87
99
|
};
|
|
88
100
|
// Create a hashStruct function that mimics the original behavior
|
|
89
101
|
function hashStruct(primaryType, data, types, _version) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
if (!data) {
|
|
103
|
+
throw new Error('Invalid data: data is empty');
|
|
104
|
+
}
|
|
105
|
+
// For EIP-712, we need to create a complete structure
|
|
106
|
+
// The original implementation would hash just the specific part
|
|
107
|
+
let typedData;
|
|
108
|
+
if (primaryType === 'EIP712Domain') {
|
|
109
|
+
// For domain hash, we only need the domain data
|
|
110
|
+
typedData = {
|
|
111
|
+
domain: data,
|
|
112
|
+
types: { EIP712Domain: types.EIP712Domain },
|
|
113
|
+
primaryType: 'EIP712Domain',
|
|
114
|
+
message: {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// For message hash, we need the complete structure
|
|
119
|
+
// Use the domain data if it's available in types
|
|
120
|
+
typedData = {
|
|
121
|
+
domain: types.domain || {},
|
|
122
|
+
types,
|
|
123
|
+
primaryType,
|
|
124
|
+
message: data,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
96
127
|
const hash = hashTypedData(typedData);
|
|
97
|
-
// Return an object that mimics a Buffer with toString method for compatibility
|
|
98
128
|
return {
|
|
99
129
|
toString: (encoding) => {
|
|
100
130
|
if (encoding === 'hex') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/sdk-ts",
|
|
3
3
|
"description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
|
|
4
|
-
"version": "1.16.13-alpha.
|
|
4
|
+
"version": "1.16.13-alpha.2",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": {
|
|
@@ -124,16 +124,16 @@
|
|
|
124
124
|
"@cosmjs/stargate": "^0.33.0",
|
|
125
125
|
"@injectivelabs/abacus-proto-ts": "1.14.0",
|
|
126
126
|
"@injectivelabs/core-proto-ts": "1.16.5",
|
|
127
|
-
"@injectivelabs/exceptions": "1.16.13-alpha.
|
|
127
|
+
"@injectivelabs/exceptions": "1.16.13-alpha.2",
|
|
128
128
|
"@injectivelabs/grpc-web": "^0.0.1",
|
|
129
129
|
"@injectivelabs/grpc-web-node-http-transport": "^0.0.2",
|
|
130
130
|
"@injectivelabs/grpc-web-react-native-transport": "^0.0.2",
|
|
131
131
|
"@injectivelabs/indexer-proto-ts": "1.13.16-beta.1",
|
|
132
132
|
"@injectivelabs/mito-proto-ts": "1.13.2",
|
|
133
|
-
"@injectivelabs/networks": "1.16.13-alpha.
|
|
133
|
+
"@injectivelabs/networks": "1.16.13-alpha.2",
|
|
134
134
|
"@injectivelabs/olp-proto-ts": "1.13.4",
|
|
135
|
-
"@injectivelabs/ts-types": "1.16.13-alpha.
|
|
136
|
-
"@injectivelabs/utils": "1.16.13-alpha.
|
|
135
|
+
"@injectivelabs/ts-types": "1.16.13-alpha.2",
|
|
136
|
+
"@injectivelabs/utils": "1.16.13-alpha.2",
|
|
137
137
|
"@noble/curves": "^1.8.1",
|
|
138
138
|
"@noble/hashes": "^1.7.1",
|
|
139
139
|
"@scure/base": "^1.2.6",
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
"snakecase-keys": "^5.4.1",
|
|
152
152
|
"viem": "^2.33.2"
|
|
153
153
|
},
|
|
154
|
-
"gitHead": "
|
|
154
|
+
"gitHead": "c60f210698d2ee266855a6bb7342d0147964bad4",
|
|
155
155
|
"typedoc": {
|
|
156
156
|
"entryPoint": "./src/index.ts",
|
|
157
157
|
"readmeFile": "./README.md",
|