@coinbase/cdp-sdk 1.21.0 → 1.22.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/CHANGELOG.md +12 -0
- package/_cjs/auth/utils/hash.js +17 -0
- package/_cjs/auth/utils/hash.js.map +1 -0
- package/_cjs/auth/utils/jwt.js +20 -55
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/client/cdp.js +6 -0
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/auth/utils/hash.js +13 -0
- package/_esm/auth/utils/hash.js.map +1 -0
- package/_esm/auth/utils/jwt.js +20 -22
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/client/cdp.js +6 -0
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/actions/evm/fund/fund.d.ts +1 -1
- package/_types/actions/evm/fund/fund.d.ts.map +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -1
- package/_types/auth/utils/hash.d.ts +9 -0
- package/_types/auth/utils/hash.d.ts.map +1 -0
- package/_types/auth/utils/jwt.d.ts.map +1 -1
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +24 -24
- package/_types/version.d.ts +1 -1
- package/actions/evm/fund/fund.ts +1 -1
- package/actions/evm/fund/quoteFund.ts +1 -1
- package/auth/utils/hash.ts +13 -0
- package/auth/utils/jwt.ts +21 -24
- package/client/cdp.ts +9 -0
- package/package.json +2 -1
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# CDP SDK Changelog
|
|
2
2
|
|
|
3
|
+
## 1.22.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#250](https://github.com/coinbase/cdp-sdk/pull/250) [`a11ecd2`](https://github.com/coinbase/cdp-sdk/commit/a11ecd2ebb59a4a9d475323322cb40d9c40911f1) Thanks [@0xRAG](https://github.com/0xRAG)! - Swapped built-in crypto library for uncrypto in auth subpackage to allow it to work in Next.js Edge runtime
|
|
8
|
+
|
|
9
|
+
- [#251](https://github.com/coinbase/cdp-sdk/pull/251) [`57aa371`](https://github.com/coinbase/cdp-sdk/commit/57aa3717a9356f89031c1cf20c83f8b0f310dad7) Thanks [@suryatejamandadi-cb](https://github.com/suryatejamandadi-cb)! - Added ethereum mainnet support for the wallet fund and quoteFund operations for server/smart accounts
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#194](https://github.com/coinbase/cdp-sdk/pull/194) [`b65c416`](https://github.com/coinbase/cdp-sdk/commit/b65c41678f717c1d25162cb8e2f1fb1f205b8051) Thanks [@0xRAG](https://github.com/0xRAG)! - Added check to ensure minimum required Node.js version
|
|
14
|
+
|
|
3
15
|
## 1.21.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authHash = void 0;
|
|
4
|
+
const uncrypto_1 = require("uncrypto");
|
|
5
|
+
/**
|
|
6
|
+
* Auth-specific hash function using uncrypto for Edge runtime compatibility.
|
|
7
|
+
* Computes SHA-256 hash of the given data.
|
|
8
|
+
*
|
|
9
|
+
* @param data - The data to hash
|
|
10
|
+
* @returns Promise that resolves to the hex-encoded hash
|
|
11
|
+
*/
|
|
12
|
+
const authHash = async (data) => {
|
|
13
|
+
const hashBuffer = await uncrypto_1.subtle.digest("SHA-256", data);
|
|
14
|
+
return Buffer.from(hashBuffer).toString("hex");
|
|
15
|
+
};
|
|
16
|
+
exports.authHash = authHash;
|
|
17
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../auth/utils/hash.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAElC;;;;;;GAMG;AACI,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAmB,EAAE;IAC9D,MAAM,UAAU,GAAG,MAAM,iBAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC;AAHW,QAAA,QAAQ,YAGnB"}
|
package/_cjs/auth/utils/jwt.js
CHANGED
|
@@ -1,44 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateJwt = generateJwt;
|
|
37
4
|
exports.generateWalletJwt = generateWalletJwt;
|
|
38
|
-
const crypto = __importStar(require("crypto"));
|
|
39
|
-
const crypto_1 = require("crypto");
|
|
40
5
|
const jose_1 = require("jose");
|
|
41
|
-
const
|
|
6
|
+
const uncrypto_1 = require("uncrypto");
|
|
7
|
+
const hash_js_1 = require("./hash.js");
|
|
42
8
|
const sortKeys_js_1 = require("../../utils/sortKeys.js");
|
|
43
9
|
const errors_js_1 = require("../errors.js");
|
|
44
10
|
/**
|
|
@@ -83,7 +49,7 @@ async function generateJwt(options) {
|
|
|
83
49
|
// Generate random nonce for the header
|
|
84
50
|
const randomNonce = nonce();
|
|
85
51
|
// Determine if we're using EC or Edwards key based on the key format
|
|
86
|
-
if (isValidECKey(options.apiKeySecret)) {
|
|
52
|
+
if (await isValidECKey(options.apiKeySecret)) {
|
|
87
53
|
return await buildECJWT(options.apiKeySecret, options.apiKeyId, claims, now, expiresIn, randomNonce);
|
|
88
54
|
}
|
|
89
55
|
else if (isValidEd25519Key(options.apiKeySecret)) {
|
|
@@ -113,15 +79,16 @@ async function generateWalletJwt(options) {
|
|
|
113
79
|
};
|
|
114
80
|
if (Object.keys(options.requestData).length > 0) {
|
|
115
81
|
const sortedData = (0, sortKeys_js_1.sortKeys)(options.requestData);
|
|
116
|
-
claims.reqHash = (0, hash_js_1.
|
|
82
|
+
claims.reqHash = await (0, hash_js_1.authHash)(Buffer.from(JSON.stringify(sortedData)));
|
|
117
83
|
}
|
|
118
84
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
85
|
+
// Convert base64 DER to PEM format for jose
|
|
86
|
+
const derBuffer = Buffer.from(options.walletSecret, "base64");
|
|
87
|
+
const pemKey = `-----BEGIN PRIVATE KEY-----\n${derBuffer
|
|
88
|
+
.toString("base64")
|
|
89
|
+
.match(/.{1,64}/g)
|
|
90
|
+
?.join("\n")}\n-----END PRIVATE KEY-----`;
|
|
91
|
+
const ecKey = await (0, jose_1.importPKCS8)(pemKey, "ES256");
|
|
125
92
|
return await new jose_1.SignJWT(claims)
|
|
126
93
|
.setProtectedHeader({ alg: "ES256", typ: "JWT" })
|
|
127
94
|
.setIssuedAt(now)
|
|
@@ -154,12 +121,11 @@ function isValidEd25519Key(str) {
|
|
|
154
121
|
* @param str - The string to test
|
|
155
122
|
* @returns True if the string is a valid EC private key in PEM format
|
|
156
123
|
*/
|
|
157
|
-
function isValidECKey(str) {
|
|
124
|
+
async function isValidECKey(str) {
|
|
158
125
|
try {
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return key.asymmetricKeyType === "ec";
|
|
126
|
+
// Try to import the key with jose - if it works, it's a valid EC key
|
|
127
|
+
await (0, jose_1.importPKCS8)(str, "ES256");
|
|
128
|
+
return true;
|
|
163
129
|
}
|
|
164
130
|
catch {
|
|
165
131
|
return false;
|
|
@@ -179,11 +145,8 @@ function isValidECKey(str) {
|
|
|
179
145
|
*/
|
|
180
146
|
async function buildECJWT(privateKey, keyName, claims, now, expiresIn, nonce) {
|
|
181
147
|
try {
|
|
182
|
-
//
|
|
183
|
-
const
|
|
184
|
-
const pkcs8Key = keyObj.export({ type: "pkcs8", format: "pem" }).toString();
|
|
185
|
-
// Import the key for signing
|
|
186
|
-
const ecKey = await (0, jose_1.importPKCS8)(pkcs8Key, "ES256");
|
|
148
|
+
// Import the key directly with jose
|
|
149
|
+
const ecKey = await (0, jose_1.importPKCS8)(privateKey, "ES256");
|
|
187
150
|
// Sign and return the JWT
|
|
188
151
|
return await new jose_1.SignJWT(claims)
|
|
189
152
|
.setProtectedHeader({ alg: "ES256", kid: keyName, typ: "JWT", nonce })
|
|
@@ -244,6 +207,8 @@ async function buildEdwardsJWT(privateKey, keyName, claims, now, expiresIn, nonc
|
|
|
244
207
|
* @returns {string} The generated nonce.
|
|
245
208
|
*/
|
|
246
209
|
function nonce() {
|
|
247
|
-
|
|
210
|
+
const bytes = new Uint8Array(16);
|
|
211
|
+
(0, uncrypto_1.getRandomValues)(bytes);
|
|
212
|
+
return Buffer.from(bytes).toString("hex");
|
|
248
213
|
}
|
|
249
214
|
//# sourceMappingURL=jwt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":";;AAuGA,kCAiEC;AAWD,8CAoCC;AAvND,+BAAmE;AACnE,uCAA2C;AAE3C,uCAAqC;AACrC,yDAAmD;AACnD,4CAA0F;AAwF1F;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,OAAmB;IACnD,+BAA+B;IAC/B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,gEAAgE;IAChE,MAAM,mBAAmB,GAAG,OAAO,CACjC,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CACpE,CAAC;IACF,MAAM,kBAAkB,GACtB,CAAC,OAAO,CAAC,aAAa,KAAK,SAAS,IAAI,OAAO,CAAC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,WAAW,CAAC;SACnC,CAAC;QAEF,6BAA6B;QAC7B,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAS,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE1C,0BAA0B;QAC1B,OAAO,MAAM,IAAI,cAAO,CAAC,MAAM,CAAC;aAC7B,kBAAkB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;aACrE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC5B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAC7B,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;aAC9C,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,mCAAoC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,IAAA,0BAAe,EAAC,KAAK,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC"}
|
package/_cjs/client/cdp.js
CHANGED
|
@@ -53,6 +53,12 @@ class CdpClient {
|
|
|
53
53
|
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
54
54
|
*/
|
|
55
55
|
constructor(options = {}) {
|
|
56
|
+
if (Number(process.versions.node.split(".")[0]) < 19) {
|
|
57
|
+
throw new Error(`
|
|
58
|
+
Node.js version ${process.versions.node} is not supported. CDP SDK requires Node.js version 19 or higher. Please upgrade your Node.js version to use the CDP SDK.
|
|
59
|
+
We recommend using https://github.com/Schniz/fnm for managing your Node.js version.
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
56
62
|
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_ID ?? process.env.CDP_API_KEY_NAME;
|
|
57
63
|
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
58
64
|
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
package/_cjs/client/cdp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAC5C,yDAA8D;AAC9D,8CAAwC;AACxC,yCAAyC;AACzC,wDAAwD;AACxD,kDAAkD;AAelD;;GAEG;AACH,MAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,CAAY;IAEtB,+CAA+C;IACxC,MAAM,CAAe;IAE5B,iDAAiD;IAC1C,QAAQ,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,YAAY,UAA4B,EAAE;QACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAChG,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC5E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAE3E,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BrB,CAAC,CAAC;QACC,CAAC;QAED,2BAAgB,CAAC,SAAS,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,MAAM,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|
4
|
+
* Computes SHA-256 hash of the given data.
|
|
5
|
+
*
|
|
6
|
+
* @param data - The data to hash
|
|
7
|
+
* @returns Promise that resolves to the hex-encoded hash
|
|
8
|
+
*/
|
|
9
|
+
export const authHash = async (data) => {
|
|
10
|
+
const hashBuffer = await subtle.digest("SHA-256", data);
|
|
11
|
+
return Buffer.from(hashBuffer).toString("hex");
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../auth/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAmB,EAAE;IAC9D,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC"}
|
package/_esm/auth/utils/jwt.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as crypto from "crypto";
|
|
2
|
-
import { createPrivateKey } from "crypto";
|
|
3
1
|
import { SignJWT, importPKCS8, importJWK } from "jose";
|
|
4
|
-
import {
|
|
2
|
+
import { getRandomValues } from "uncrypto";
|
|
3
|
+
import { authHash } from "./hash.js";
|
|
5
4
|
import { sortKeys } from "../../utils/sortKeys.js";
|
|
6
5
|
import { InvalidWalletSecretFormatError, UndefinedWalletSecretError } from "../errors.js";
|
|
7
6
|
/**
|
|
@@ -46,7 +45,7 @@ export async function generateJwt(options) {
|
|
|
46
45
|
// Generate random nonce for the header
|
|
47
46
|
const randomNonce = nonce();
|
|
48
47
|
// Determine if we're using EC or Edwards key based on the key format
|
|
49
|
-
if (isValidECKey(options.apiKeySecret)) {
|
|
48
|
+
if (await isValidECKey(options.apiKeySecret)) {
|
|
50
49
|
return await buildECJWT(options.apiKeySecret, options.apiKeyId, claims, now, expiresIn, randomNonce);
|
|
51
50
|
}
|
|
52
51
|
else if (isValidEd25519Key(options.apiKeySecret)) {
|
|
@@ -76,15 +75,16 @@ export async function generateWalletJwt(options) {
|
|
|
76
75
|
};
|
|
77
76
|
if (Object.keys(options.requestData).length > 0) {
|
|
78
77
|
const sortedData = sortKeys(options.requestData);
|
|
79
|
-
claims.reqHash =
|
|
78
|
+
claims.reqHash = await authHash(Buffer.from(JSON.stringify(sortedData)));
|
|
80
79
|
}
|
|
81
80
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
// Convert base64 DER to PEM format for jose
|
|
82
|
+
const derBuffer = Buffer.from(options.walletSecret, "base64");
|
|
83
|
+
const pemKey = `-----BEGIN PRIVATE KEY-----\n${derBuffer
|
|
84
|
+
.toString("base64")
|
|
85
|
+
.match(/.{1,64}/g)
|
|
86
|
+
?.join("\n")}\n-----END PRIVATE KEY-----`;
|
|
87
|
+
const ecKey = await importPKCS8(pemKey, "ES256");
|
|
88
88
|
return await new SignJWT(claims)
|
|
89
89
|
.setProtectedHeader({ alg: "ES256", typ: "JWT" })
|
|
90
90
|
.setIssuedAt(now)
|
|
@@ -117,12 +117,11 @@ function isValidEd25519Key(str) {
|
|
|
117
117
|
* @param str - The string to test
|
|
118
118
|
* @returns True if the string is a valid EC private key in PEM format
|
|
119
119
|
*/
|
|
120
|
-
function isValidECKey(str) {
|
|
120
|
+
async function isValidECKey(str) {
|
|
121
121
|
try {
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return key.asymmetricKeyType === "ec";
|
|
122
|
+
// Try to import the key with jose - if it works, it's a valid EC key
|
|
123
|
+
await importPKCS8(str, "ES256");
|
|
124
|
+
return true;
|
|
126
125
|
}
|
|
127
126
|
catch {
|
|
128
127
|
return false;
|
|
@@ -142,11 +141,8 @@ function isValidECKey(str) {
|
|
|
142
141
|
*/
|
|
143
142
|
async function buildECJWT(privateKey, keyName, claims, now, expiresIn, nonce) {
|
|
144
143
|
try {
|
|
145
|
-
//
|
|
146
|
-
const
|
|
147
|
-
const pkcs8Key = keyObj.export({ type: "pkcs8", format: "pem" }).toString();
|
|
148
|
-
// Import the key for signing
|
|
149
|
-
const ecKey = await importPKCS8(pkcs8Key, "ES256");
|
|
144
|
+
// Import the key directly with jose
|
|
145
|
+
const ecKey = await importPKCS8(privateKey, "ES256");
|
|
150
146
|
// Sign and return the JWT
|
|
151
147
|
return await new SignJWT(claims)
|
|
152
148
|
.setProtectedHeader({ alg: "ES256", kid: keyName, typ: "JWT", nonce })
|
|
@@ -207,6 +203,8 @@ async function buildEdwardsJWT(privateKey, keyName, claims, now, expiresIn, nonc
|
|
|
207
203
|
* @returns {string} The generated nonce.
|
|
208
204
|
*/
|
|
209
205
|
function nonce() {
|
|
210
|
-
|
|
206
|
+
const bytes = new Uint8Array(16);
|
|
207
|
+
getRandomValues(bytes);
|
|
208
|
+
return Buffer.from(bytes).toString("hex");
|
|
211
209
|
}
|
|
212
210
|
//# sourceMappingURL=jwt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAc,MAAM,MAAM,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,0BAA0B,EA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K,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,eAAe,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC"}
|
package/_esm/client/cdp.js
CHANGED
|
@@ -50,6 +50,12 @@ export class CdpClient {
|
|
|
50
50
|
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
51
51
|
*/
|
|
52
52
|
constructor(options = {}) {
|
|
53
|
+
if (Number(process.versions.node.split(".")[0]) < 19) {
|
|
54
|
+
throw new Error(`
|
|
55
|
+
Node.js version ${process.versions.node} is not supported. CDP SDK requires Node.js version 19 or higher. Please upgrade your Node.js version to use the CDP SDK.
|
|
56
|
+
We recommend using https://github.com/Schniz/fnm for managing your Node.js version.
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
53
59
|
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_ID ?? process.env.CDP_API_KEY_NAME;
|
|
54
60
|
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
55
61
|
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
package/_esm/client/cdp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAelD;;GAEG;AACH,MAAM,OAAO,SAAS;IACpB,4CA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AC/B,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BrB,CAAC,CAAC;QACC,CAAC;QAED,gBAAgB,CAAC,SAAS,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,MAAM,EAAE,KAAK;YACb,aAAa,EAAE,OAAO;SACvB,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,EAAE,CAAC;YACvD,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC;YAChC,SAAS,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC;YAChD,SAAS,CAAC,0BAA0B,CAAC,SAAS,CAAC,CAAC;YAChD,SAAS,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAC;YACnD,SAAS,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;IACvC,CAAC;CACF"}
|
package/_esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.22.0";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -7,7 +7,7 @@ export interface FundOptions {
|
|
|
7
7
|
/** The address of the account. */
|
|
8
8
|
address: string;
|
|
9
9
|
/** The network to request funds from. */
|
|
10
|
-
network: "base";
|
|
10
|
+
network: "base" | "ethereum";
|
|
11
11
|
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
12
12
|
amount: bigint;
|
|
13
13
|
/** The token to request funds for. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fund.d.ts","sourceRoot":"","sources":["../../../../actions/evm/fund/fund.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"fund.d.ts","sourceRoot":"","sources":["../../../../actions/evm/fund/fund.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,mBAAmB,CAAC,CAyC9B"}
|
|
@@ -7,7 +7,7 @@ export interface QuoteFundOptions {
|
|
|
7
7
|
/** The address of the account. */
|
|
8
8
|
address: string;
|
|
9
9
|
/** The network to request funds from. */
|
|
10
|
-
network: "base";
|
|
10
|
+
network: "base" | "ethereum";
|
|
11
11
|
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
12
12
|
amount: bigint;
|
|
13
13
|
/** The token to request funds for. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quoteFund.d.ts","sourceRoot":"","sources":["../../../../actions/evm/fund/quoteFund.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"quoteFund.d.ts","sourceRoot":"","sources":["../../../../actions/evm/fund/quoteFund.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,KAAK,CAAC,CA8ChB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-specific hash function using uncrypto for Edge runtime compatibility.
|
|
3
|
+
* Computes SHA-256 hash of the given data.
|
|
4
|
+
*
|
|
5
|
+
* @param data - The data to hash
|
|
6
|
+
* @returns Promise that resolves to the hex-encoded hash
|
|
7
|
+
*/
|
|
8
|
+
export declare const authHash: (data: Buffer) => Promise<string>;
|
|
9
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../auth/utils/hash.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,CAG3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../../auth/utils/jwt.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IAEH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAiEtE;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoClF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,EAAE,SAAS,CAAC;IAEtB,+CAA+C;IACxC,MAAM,EAAE,YAAY,CAAC;IAE5B,iDAAiD;IAC1C,QAAQ,EAAE,cAAc,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;gBACS,OAAO,GAAE,gBAAqB;
|
|
1
|
+
{"version":3,"file":"cdp.d.ts","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,EAAE,SAAS,CAAC;IAEtB,+CAA+C;IACxC,MAAM,EAAE,YAAY,CAAC;IAE5B,iDAAiD;IAC1C,QAAQ,EAAE,cAAc,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;gBACS,OAAO,GAAE,gBAAqB;CAmE3C"}
|
|
@@ -133,11 +133,11 @@ export declare const EvmMessageCriterionSchema: z.ZodObject<{
|
|
|
133
133
|
*/
|
|
134
134
|
match: z.ZodString;
|
|
135
135
|
}, "strip", z.ZodTypeAny, {
|
|
136
|
-
type: "evmMessage";
|
|
137
136
|
match: string;
|
|
138
|
-
}, {
|
|
139
137
|
type: "evmMessage";
|
|
138
|
+
}, {
|
|
140
139
|
match: string;
|
|
140
|
+
type: "evmMessage";
|
|
141
141
|
}>;
|
|
142
142
|
export type EvmMessageCriterion = z.infer<typeof EvmMessageCriterionSchema>;
|
|
143
143
|
/**
|
|
@@ -910,11 +910,11 @@ export declare const SignEvmMessageCriteriaSchema: z.ZodArray<z.ZodDiscriminated
|
|
|
910
910
|
*/
|
|
911
911
|
match: z.ZodString;
|
|
912
912
|
}, "strip", z.ZodTypeAny, {
|
|
913
|
-
type: "evmMessage";
|
|
914
913
|
match: string;
|
|
915
|
-
}, {
|
|
916
914
|
type: "evmMessage";
|
|
915
|
+
}, {
|
|
917
916
|
match: string;
|
|
917
|
+
type: "evmMessage";
|
|
918
918
|
}>]>, "many">;
|
|
919
919
|
/**
|
|
920
920
|
* Type representing a set of criteria for the signEvmMessage operation.
|
|
@@ -1773,25 +1773,25 @@ export declare const SignEvmMessageRuleSchema: z.ZodObject<{
|
|
|
1773
1773
|
*/
|
|
1774
1774
|
match: z.ZodString;
|
|
1775
1775
|
}, "strip", z.ZodTypeAny, {
|
|
1776
|
-
type: "evmMessage";
|
|
1777
1776
|
match: string;
|
|
1778
|
-
}, {
|
|
1779
1777
|
type: "evmMessage";
|
|
1778
|
+
}, {
|
|
1780
1779
|
match: string;
|
|
1780
|
+
type: "evmMessage";
|
|
1781
1781
|
}>]>, "many">;
|
|
1782
1782
|
}, "strip", z.ZodTypeAny, {
|
|
1783
1783
|
action: "reject" | "accept";
|
|
1784
1784
|
operation: "signEvmMessage";
|
|
1785
1785
|
criteria: {
|
|
1786
|
-
type: "evmMessage";
|
|
1787
1786
|
match: string;
|
|
1787
|
+
type: "evmMessage";
|
|
1788
1788
|
}[];
|
|
1789
1789
|
}, {
|
|
1790
1790
|
action: "reject" | "accept";
|
|
1791
1791
|
operation: "signEvmMessage";
|
|
1792
1792
|
criteria: {
|
|
1793
|
-
type: "evmMessage";
|
|
1794
1793
|
match: string;
|
|
1794
|
+
type: "evmMessage";
|
|
1795
1795
|
}[];
|
|
1796
1796
|
}>;
|
|
1797
1797
|
export type SignEvmMessageRule = z.infer<typeof SignEvmMessageRuleSchema>;
|
|
@@ -2745,25 +2745,25 @@ export declare const RuleSchema: z.ZodDiscriminatedUnion<"operation", [z.ZodObje
|
|
|
2745
2745
|
*/
|
|
2746
2746
|
match: z.ZodString;
|
|
2747
2747
|
}, "strip", z.ZodTypeAny, {
|
|
2748
|
-
type: "evmMessage";
|
|
2749
2748
|
match: string;
|
|
2750
|
-
}, {
|
|
2751
2749
|
type: "evmMessage";
|
|
2750
|
+
}, {
|
|
2752
2751
|
match: string;
|
|
2752
|
+
type: "evmMessage";
|
|
2753
2753
|
}>]>, "many">;
|
|
2754
2754
|
}, "strip", z.ZodTypeAny, {
|
|
2755
2755
|
action: "reject" | "accept";
|
|
2756
2756
|
operation: "signEvmMessage";
|
|
2757
2757
|
criteria: {
|
|
2758
|
-
type: "evmMessage";
|
|
2759
2758
|
match: string;
|
|
2759
|
+
type: "evmMessage";
|
|
2760
2760
|
}[];
|
|
2761
2761
|
}, {
|
|
2762
2762
|
action: "reject" | "accept";
|
|
2763
2763
|
operation: "signEvmMessage";
|
|
2764
2764
|
criteria: {
|
|
2765
|
-
type: "evmMessage";
|
|
2766
2765
|
match: string;
|
|
2766
|
+
type: "evmMessage";
|
|
2767
2767
|
}[];
|
|
2768
2768
|
}>, z.ZodObject<{
|
|
2769
2769
|
/**
|
|
@@ -3733,25 +3733,25 @@ export declare const CreatePolicyBodySchema: z.ZodObject<{
|
|
|
3733
3733
|
*/
|
|
3734
3734
|
match: z.ZodString;
|
|
3735
3735
|
}, "strip", z.ZodTypeAny, {
|
|
3736
|
-
type: "evmMessage";
|
|
3737
3736
|
match: string;
|
|
3738
|
-
}, {
|
|
3739
3737
|
type: "evmMessage";
|
|
3738
|
+
}, {
|
|
3740
3739
|
match: string;
|
|
3740
|
+
type: "evmMessage";
|
|
3741
3741
|
}>]>, "many">;
|
|
3742
3742
|
}, "strip", z.ZodTypeAny, {
|
|
3743
3743
|
action: "reject" | "accept";
|
|
3744
3744
|
operation: "signEvmMessage";
|
|
3745
3745
|
criteria: {
|
|
3746
|
-
type: "evmMessage";
|
|
3747
3746
|
match: string;
|
|
3747
|
+
type: "evmMessage";
|
|
3748
3748
|
}[];
|
|
3749
3749
|
}, {
|
|
3750
3750
|
action: "reject" | "accept";
|
|
3751
3751
|
operation: "signEvmMessage";
|
|
3752
3752
|
criteria: {
|
|
3753
|
-
type: "evmMessage";
|
|
3754
3753
|
match: string;
|
|
3754
|
+
type: "evmMessage";
|
|
3755
3755
|
}[];
|
|
3756
3756
|
}>, z.ZodObject<{
|
|
3757
3757
|
/**
|
|
@@ -4309,8 +4309,8 @@ export declare const CreatePolicyBodySchema: z.ZodObject<{
|
|
|
4309
4309
|
action: "reject" | "accept";
|
|
4310
4310
|
operation: "signEvmMessage";
|
|
4311
4311
|
criteria: {
|
|
4312
|
-
type: "evmMessage";
|
|
4313
4312
|
match: string;
|
|
4313
|
+
type: "evmMessage";
|
|
4314
4314
|
}[];
|
|
4315
4315
|
} | {
|
|
4316
4316
|
action: "reject" | "accept";
|
|
@@ -4419,8 +4419,8 @@ export declare const CreatePolicyBodySchema: z.ZodObject<{
|
|
|
4419
4419
|
action: "reject" | "accept";
|
|
4420
4420
|
operation: "signEvmMessage";
|
|
4421
4421
|
criteria: {
|
|
4422
|
-
type: "evmMessage";
|
|
4423
4422
|
match: string;
|
|
4423
|
+
type: "evmMessage";
|
|
4424
4424
|
}[];
|
|
4425
4425
|
} | {
|
|
4426
4426
|
action: "reject" | "accept";
|
|
@@ -4925,25 +4925,25 @@ export declare const UpdatePolicyBodySchema: z.ZodObject<{
|
|
|
4925
4925
|
*/
|
|
4926
4926
|
match: z.ZodString;
|
|
4927
4927
|
}, "strip", z.ZodTypeAny, {
|
|
4928
|
-
type: "evmMessage";
|
|
4929
4928
|
match: string;
|
|
4930
|
-
}, {
|
|
4931
4929
|
type: "evmMessage";
|
|
4930
|
+
}, {
|
|
4932
4931
|
match: string;
|
|
4932
|
+
type: "evmMessage";
|
|
4933
4933
|
}>]>, "many">;
|
|
4934
4934
|
}, "strip", z.ZodTypeAny, {
|
|
4935
4935
|
action: "reject" | "accept";
|
|
4936
4936
|
operation: "signEvmMessage";
|
|
4937
4937
|
criteria: {
|
|
4938
|
-
type: "evmMessage";
|
|
4939
4938
|
match: string;
|
|
4939
|
+
type: "evmMessage";
|
|
4940
4940
|
}[];
|
|
4941
4941
|
}, {
|
|
4942
4942
|
action: "reject" | "accept";
|
|
4943
4943
|
operation: "signEvmMessage";
|
|
4944
4944
|
criteria: {
|
|
4945
|
-
type: "evmMessage";
|
|
4946
4945
|
match: string;
|
|
4946
|
+
type: "evmMessage";
|
|
4947
4947
|
}[];
|
|
4948
4948
|
}>, z.ZodObject<{
|
|
4949
4949
|
/**
|
|
@@ -5500,8 +5500,8 @@ export declare const UpdatePolicyBodySchema: z.ZodObject<{
|
|
|
5500
5500
|
action: "reject" | "accept";
|
|
5501
5501
|
operation: "signEvmMessage";
|
|
5502
5502
|
criteria: {
|
|
5503
|
-
type: "evmMessage";
|
|
5504
5503
|
match: string;
|
|
5504
|
+
type: "evmMessage";
|
|
5505
5505
|
}[];
|
|
5506
5506
|
} | {
|
|
5507
5507
|
action: "reject" | "accept";
|
|
@@ -5609,8 +5609,8 @@ export declare const UpdatePolicyBodySchema: z.ZodObject<{
|
|
|
5609
5609
|
action: "reject" | "accept";
|
|
5610
5610
|
operation: "signEvmMessage";
|
|
5611
5611
|
criteria: {
|
|
5612
|
-
type: "evmMessage";
|
|
5613
5612
|
match: string;
|
|
5613
|
+
type: "evmMessage";
|
|
5614
5614
|
}[];
|
|
5615
5615
|
} | {
|
|
5616
5616
|
action: "reject" | "accept";
|
package/_types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.22.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/actions/evm/fund/fund.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface FundOptions {
|
|
|
14
14
|
/** The address of the account. */
|
|
15
15
|
address: string;
|
|
16
16
|
/** The network to request funds from. */
|
|
17
|
-
network: "base";
|
|
17
|
+
network: "base" | "ethereum";
|
|
18
18
|
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
19
19
|
amount: bigint;
|
|
20
20
|
/** The token to request funds for. */
|
|
@@ -14,7 +14,7 @@ export interface QuoteFundOptions {
|
|
|
14
14
|
/** The address of the account. */
|
|
15
15
|
address: string;
|
|
16
16
|
/** The network to request funds from. */
|
|
17
|
-
network: "base";
|
|
17
|
+
network: "base" | "ethereum";
|
|
18
18
|
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
19
19
|
amount: bigint;
|
|
20
20
|
/** The token to request funds for. */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { subtle } from "uncrypto";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auth-specific hash function using uncrypto for Edge runtime compatibility.
|
|
5
|
+
* Computes SHA-256 hash of the given data.
|
|
6
|
+
*
|
|
7
|
+
* @param data - The data to hash
|
|
8
|
+
* @returns Promise that resolves to the hex-encoded hash
|
|
9
|
+
*/
|
|
10
|
+
export const authHash = async (data: Buffer): Promise<string> => {
|
|
11
|
+
const hashBuffer = await subtle.digest("SHA-256", data);
|
|
12
|
+
return Buffer.from(hashBuffer).toString("hex");
|
|
13
|
+
};
|
package/auth/utils/jwt.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as crypto from "crypto";
|
|
2
|
-
import { createPrivateKey } from "crypto";
|
|
3
|
-
|
|
4
1
|
import { SignJWT, importPKCS8, importJWK, JWTPayload } from "jose";
|
|
2
|
+
import { getRandomValues } from "uncrypto";
|
|
5
3
|
|
|
6
|
-
import {
|
|
4
|
+
import { authHash } from "./hash.js";
|
|
7
5
|
import { sortKeys } from "../../utils/sortKeys.js";
|
|
8
6
|
import { InvalidWalletSecretFormatError, UndefinedWalletSecretError } from "../errors.js";
|
|
9
7
|
|
|
@@ -147,7 +145,7 @@ export async function generateJwt(options: JwtOptions): Promise<string> {
|
|
|
147
145
|
const randomNonce = nonce();
|
|
148
146
|
|
|
149
147
|
// Determine if we're using EC or Edwards key based on the key format
|
|
150
|
-
if (isValidECKey(options.apiKeySecret)) {
|
|
148
|
+
if (await isValidECKey(options.apiKeySecret)) {
|
|
151
149
|
return await buildECJWT(
|
|
152
150
|
options.apiKeySecret,
|
|
153
151
|
options.apiKeyId,
|
|
@@ -193,16 +191,18 @@ export async function generateWalletJwt(options: WalletJwtOptions): Promise<stri
|
|
|
193
191
|
|
|
194
192
|
if (Object.keys(options.requestData).length > 0) {
|
|
195
193
|
const sortedData = sortKeys(options.requestData);
|
|
196
|
-
claims.reqHash =
|
|
194
|
+
claims.reqHash = await authHash(Buffer.from(JSON.stringify(sortedData)));
|
|
197
195
|
}
|
|
198
196
|
|
|
199
197
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
198
|
+
// Convert base64 DER to PEM format for jose
|
|
199
|
+
const derBuffer = Buffer.from(options.walletSecret, "base64");
|
|
200
|
+
const pemKey = `-----BEGIN PRIVATE KEY-----\n${derBuffer
|
|
201
|
+
.toString("base64")
|
|
202
|
+
.match(/.{1,64}/g)
|
|
203
|
+
?.join("\n")}\n-----END PRIVATE KEY-----`;
|
|
204
|
+
|
|
205
|
+
const ecKey = await importPKCS8(pemKey, "ES256");
|
|
206
206
|
|
|
207
207
|
return await new SignJWT(claims)
|
|
208
208
|
.setProtectedHeader({ alg: "ES256", typ: "JWT" })
|
|
@@ -236,12 +236,11 @@ function isValidEd25519Key(str: string): boolean {
|
|
|
236
236
|
* @param str - The string to test
|
|
237
237
|
* @returns True if the string is a valid EC private key in PEM format
|
|
238
238
|
*/
|
|
239
|
-
function isValidECKey(str: string): boolean {
|
|
239
|
+
async function isValidECKey(str: string): Promise<boolean> {
|
|
240
240
|
try {
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return key.asymmetricKeyType === "ec";
|
|
241
|
+
// Try to import the key with jose - if it works, it's a valid EC key
|
|
242
|
+
await importPKCS8(str, "ES256");
|
|
243
|
+
return true;
|
|
245
244
|
} catch {
|
|
246
245
|
return false;
|
|
247
246
|
}
|
|
@@ -268,12 +267,8 @@ async function buildECJWT(
|
|
|
268
267
|
nonce: string,
|
|
269
268
|
): Promise<string> {
|
|
270
269
|
try {
|
|
271
|
-
//
|
|
272
|
-
const
|
|
273
|
-
const pkcs8Key = keyObj.export({ type: "pkcs8", format: "pem" }).toString();
|
|
274
|
-
|
|
275
|
-
// Import the key for signing
|
|
276
|
-
const ecKey = await importPKCS8(pkcs8Key, "ES256");
|
|
270
|
+
// Import the key directly with jose
|
|
271
|
+
const ecKey = await importPKCS8(privateKey, "ES256");
|
|
277
272
|
|
|
278
273
|
// Sign and return the JWT
|
|
279
274
|
return await new SignJWT(claims)
|
|
@@ -346,5 +341,7 @@ async function buildEdwardsJWT(
|
|
|
346
341
|
* @returns {string} The generated nonce.
|
|
347
342
|
*/
|
|
348
343
|
function nonce(): string {
|
|
349
|
-
|
|
344
|
+
const bytes = new Uint8Array(16);
|
|
345
|
+
getRandomValues(bytes);
|
|
346
|
+
return Buffer.from(bytes).toString("hex");
|
|
350
347
|
}
|
package/client/cdp.ts
CHANGED
|
@@ -67,6 +67,15 @@ export class CdpClient {
|
|
|
67
67
|
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
68
68
|
*/
|
|
69
69
|
constructor(options: CdpClientOptions = {}) {
|
|
70
|
+
if (Number(process.versions.node.split(".")[0]) < 19) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`
|
|
73
|
+
Node.js version ${process.versions.node} is not supported. CDP SDK requires Node.js version 19 or higher. Please upgrade your Node.js version to use the CDP SDK.
|
|
74
|
+
We recommend using https://github.com/Schniz/fnm for managing your Node.js version.
|
|
75
|
+
`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_ID ?? process.env.CDP_API_KEY_NAME;
|
|
71
80
|
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
72
81
|
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "SDK for interacting with the Coinbase Developer Platform Wallet API",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"axios": "^1.8.2",
|
|
25
25
|
"jose": "^6.0.8",
|
|
26
26
|
"md5": "^2.3.0",
|
|
27
|
+
"uncrypto": "^0.1.3",
|
|
27
28
|
"viem": "^2.21.26",
|
|
28
29
|
"zod": "^3.24.4"
|
|
29
30
|
},
|
package/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.22.0";
|