cdp-wallet-onramp-kit
Version:
Complete toolkit for Coinbase Developer Platform (CDP) Embedded Wallets and Onramp integration with reusable components, utilities, and documentation
584 lines • 15.8 kB
JSON
{
"info": {
"_postman_id": "db553a20-1a0a-443c-a450-64e0c7a533eb",
"name": "Onramp APIs",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "18811580"
},
"item": [
{
"name": "Create Session Token",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"addresses\": [\n {\n \"address\": \"0x1EFEcb61A2f80Aa34d3b9218B564a64D05946290\",\n \"blockchains\": [\"polygon\"]\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/token",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"token"
]
}
},
"response": []
},
{
"name": "Buy Config",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/buy/config",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"buy",
"config"
]
}
},
"response": []
},
{
"name": "Buy Options",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/buy/options?country=US&subdivision=FL",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"buy",
"options"
],
"query": [
{
"key": "country",
"value": "US"
},
{
"key": "subdivision",
"value": "FL"
}
]
}
},
"response": []
},
{
"name": "Create Buy Quote",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"payment_amount\": \"100.00\",\n \"payment_currency\": \"USD\",\n \"purchase_currency\": \"d85dce9b-5b73-5c3c-8978-522ce1d1c1b4\",\n \"purchase_network\": \"ethereum-mainnet\",\n \"payment_method\": \"CARD\",\n \"country\": \"US\",\n \"subdivision\": \"CA\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/buy/quote",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"buy",
"quote"
]
}
},
"response": []
},
{
"name": "Transaction Status",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/buy/user/{partner_user_id}/transactions?page_key={next_page_key}&page_size={page_size}",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"buy",
"user",
"{partner_user_id}",
"transactions"
],
"query": [
{
"key": "page_key",
"value": "{next_page_key}"
},
{
"key": "page_size",
"value": "{page_size}"
}
]
}
},
"response": []
},
{
"name": "Transactions",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/buy/transactions",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"buy",
"transactions"
],
"query": [
{
"key": "page_key",
"value": "{next_page_key}",
"disabled": true
},
{
"key": "page_size",
"value": "{page_size}",
"disabled": true
},
{
"key": "start_date",
"value": "{start_date}",
"disabled": true
},
{
"key": "end_date",
"value": "{end_date}",
"disabled": true
}
]
}
},
"response": []
},
{
"name": "Offramp Config",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/sell/config",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"sell",
"config"
]
}
},
"response": []
},
{
"name": "Offramp Options",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/sell/options?country=US",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"sell",
"options"
],
"query": [
{
"key": "country",
"value": "US"
}
]
}
},
"response": []
},
{
"name": "Offramp Quote",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"sell_currency\": \"ETH\",\n \"sell_amount\": \"10.00\",\n \"cashout_currency\": \"USD\",\n \"payment_method\": \"FIAT_WALLET\",\n \"country\": \"US\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/sell/quote",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"sell",
"quote"
]
}
},
"response": []
},
{
"name": "Offramp Transaction Status",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/sell/user/{partner_user_id}/transactions?page_key={next_page_key}&page_size={page_size}",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"sell",
"user",
"{partner_user_id}",
"transactions"
],
"query": [
{
"key": "page_key",
"value": "{next_page_key}"
},
{
"key": "page_size",
"value": "{page_size}"
}
]
}
},
"response": []
},
{
"name": "Offramp Transactions",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.developer.coinbase.com/onramp/v1/sell/transactions?page_key={next_page_key}&page_size={page_size}&start_date={start_date}&end_date={end_date}",
"protocol": "https",
"host": [
"api",
"developer",
"coinbase",
"com"
],
"path": [
"onramp",
"v1",
"sell",
"transactions"
],
"query": [
{
"key": "page_key",
"value": "{next_page_key}"
},
{
"key": "page_size",
"value": "{page_size}"
},
{
"key": "start_date",
"value": "{start_date}"
},
{
"key": "end_date",
"value": "{end_date}"
}
]
}
},
"response": []
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{token}}",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"// Set up globals",
"var navigator = {};",
"var window = {};",
"var exports = {};",
"var module = {exports: {}};",
"var process = {env: {}};",
"var Buffer = function() {",
" var args = Array.prototype.slice.call(arguments);",
" return require('buffer').Buffer.apply(this, args);",
"};",
"Buffer.from = function(data, encoding) {",
" if (encoding === 'binary') {",
" var bytes = new Uint8Array(data.length);",
" for (var i = 0; i < data.length; i++) {",
" bytes[i] = data.charCodeAt(i);",
" }",
" return bytes;",
" }",
" return require('buffer').Buffer.from(data, encoding);",
"};",
"Buffer.prototype.toString = function(encoding) {",
" return require('buffer').Buffer.prototype.toString.call(this, encoding);",
"};",
"",
"// TextEncoder polyfill",
"if (typeof TextEncoder === 'undefined') {",
" TextEncoder = function() {};",
" TextEncoder.prototype.encode = function(str) {",
" var utf8 = [];",
" for (var i = 0; i < str.length; i++) {",
" var charcode = str.charCodeAt(i);",
" if (charcode < 0x80) utf8.push(charcode);",
" else if (charcode < 0x800) utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));",
" else if (charcode < 0xd800 || charcode >= 0xe000) utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode>>6) & 0x3f), 0x80 | (charcode & 0x3f));",
" else {",
" i++;",
" charcode = 0x10000 + (((charcode & 0x3ff)<<10) | (str.charCodeAt(i) & 0x3ff));",
" utf8.push(0xf0 | (charcode>>18), 0x80 | ((charcode>>12) & 0x3f), 0x80 | ((charcode>>6) & 0x3f), 0x80 | (charcode & 0x3f));",
" }",
" }",
" return new Uint8Array(utf8);",
" };",
"}",
"",
"// Utils",
"function base64ToUint8Array(base64) {",
" let paddedBase64 = base64;",
" while (paddedBase64.length % 4 !== 0) paddedBase64 += '=';",
" paddedBase64 = paddedBase64.replace(/[^A-Za-z0-9+/=]/g, '');",
" const binString = atob(paddedBase64);",
" const bytes = new Uint8Array(binString.length);",
" for (let i = 0; i < binString.length; i++) bytes[i] = binString.charCodeAt(i);",
" return bytes;",
"}",
"",
"function base64UrlEncode(str) {",
" let base64;",
" if (typeof str === 'string') {",
" base64 = btoa(unescape(encodeURIComponent(str)));",
" } else {",
" let binary = '';",
" let bytes = new Uint8Array(str);",
" for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);",
" base64 = btoa(binary);",
" }",
" return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');",
"}",
"",
"function hexToUint8Array(hexString) {",
" return new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));",
"}",
"",
"// Get key and name",
"var rawKey = pm.environment.get(\"privateKey\");",
"var name = JSON.parse(pm.environment.get(\"name\"));",
"var isECKey = typeof rawKey === 'string' && rawKey.includes(\"-----BEGIN EC PRIVATE KEY-----\");",
"",
"// Always generate a fresh timestamp",
"var timestamp = Math.floor(Date.now() / 1000);",
"",
"// Create header",
"var header = {",
" alg: isECKey ? \"ES256\" : \"EdDSA\",",
" typ: \"JWT\",",
" kid: name,",
" nonce: timestamp.toString()",
"};",
"",
"// Create URI string",
"var host = pm.request.url.host;",
"var path = pm.request.url.path;",
"var uri = pm.request.method + \" \" + host.join(\".\") + \"/\" + path.join(\"/\");",
"",
"// Create payload",
"var payload = {",
" iss: \"coinbase-cloud\",",
" nbf: timestamp,",
" exp: timestamp + 120,",
" sub: name,",
" uri",
"};",
"",
"if (isECKey) {",
" // ES256 signing",
" eval(pm.environment.get(\"jsrsasign-js\"));",
" var privateKey = JSON.parse(rawKey);",
" var sHeader = JSON.stringify(header);",
" var sPayload = JSON.stringify(payload);",
" var prvKey = KEYUTIL.getKey(privateKey);",
" var jwt = KJUR.jws.JWS.sign(\"ES256\", sHeader, sPayload, prvKey);",
" pm.environment.set(\"token\", jwt);",
"} else {",
" // Ed25519 signing",
" const CryptoJS = require('crypto-js');",
" eval(pm.environment.get(\"noble_ed25519\"));",
" ",
" if (!exports.utils) exports.utils = {};",
" exports.utils.sha512 = async function(data) {",
" const wordArray = CryptoJS.lib.WordArray.create(data);",
" const hash = CryptoJS.SHA512(wordArray);",
" const hexString = hash.toString(CryptoJS.enc.Hex);",
" const result = new Uint8Array(hexString.length / 2);",
" for (let i = 0; i < hexString.length; i += 2) result[i / 2] = parseInt(hexString.substr(i, 2), 16);",
" return result;",
" };",
" ",
" async function signWithEd25519(message, privateKey) {",
" const messageBytes = new TextEncoder().encode(message);",
" const hash = CryptoJS.SHA512(CryptoJS.lib.WordArray.create(new Uint8Array([...messageBytes, ...privateKey])));",
" const hexString = hash.toString(CryptoJS.enc.Hex);",
" const result = new Uint8Array(hexString.length / 2);",
" for (let i = 0; i < hexString.length; i += 2) result[i / 2] = parseInt(hexString.substr(i, 2), 16);",
" return result.slice(0, 64);",
" }",
" ",
" var encodedHeader = base64UrlEncode(JSON.stringify(header));",
" var encodedPayload = base64UrlEncode(JSON.stringify(payload));",
" var message = encodedHeader + \".\" + encodedPayload;",
" ",
" // Use pm.sendRequest to block until async completion",
" pm.sendRequest({",
" url: 'https://postman-echo.com/delay/0.3', // Dummy URL",
" method: 'GET'",
" }, function(err, res) {",
" // This callback will execute after the delay, forcing Postman to wait",
" // Process in synchronous code now",
" (async function() {",
" try {",
" let privateKey = rawKey;",
" ",
" if (typeof privateKey === 'string') {",
" // Remove quotes if present",
" if (privateKey.startsWith('\"') && privateKey.endsWith('\"')) {",
" privateKey = privateKey.substring(1, privateKey.length - 1);",
" }",
" ",
" // Handle URL-safe base64",
" const standardBase64 = privateKey.replace(/-/g, '+').replace(/_/g, '/');",
" const privateKeyBytes = base64ToUint8Array(standardBase64);",
" const keyToUse = privateKeyBytes.length > 32 ? privateKeyBytes.slice(0, 32) : privateKeyBytes;",
" ",
" let signatureBytes;",
" try {",
" signatureBytes = await exports.sign(new TextEncoder().encode(message), keyToUse);",
" } catch (signError) {",
" signatureBytes = await signWithEd25519(message, keyToUse);",
" }",
" ",
" const jwt = message + \".\" + base64UrlEncode(signatureBytes);",
" pm.environment.set(\"token\", jwt);",
" }",
" } catch (error) {}",
" })();",
" });",
"} "
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}