@ckbfs/api
Version:
SDK for CKBFS protocol on CKB
105 lines (104 loc) • 4.83 kB
JavaScript
"use strict";
/**
* CKBFS protocol deployment constants
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_NETWORK = exports.DEFAULT_VERSION = exports.DEPLOY_TX_HASH = exports.DEP_GROUP_TX_HASH = exports.ADLER32_TYPE_ID = exports.ADLER32_CODE_HASH = exports.CKBFS_TYPE_ID = exports.CKBFS_CODE_HASH = exports.ProtocolVersion = exports.NetworkType = void 0;
exports.getCKBFSScriptConfig = getCKBFSScriptConfig;
var NetworkType;
(function (NetworkType) {
NetworkType["Mainnet"] = "mainnet";
NetworkType["Testnet"] = "testnet";
})(NetworkType || (exports.NetworkType = NetworkType = {}));
// Use string literals for version values to avoid TypeScript indexing issues
exports.ProtocolVersion = {
V1: '20240906.ce6724722cf6', // Original version, compact and simple, suitable for small files
V2: '20241025.db973a8e8032' // New version, more features and can do complex operations
};
// CKBFS Type Script Constants
exports.CKBFS_CODE_HASH = {
[ ]: {
[ ]: '0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a'
},
[ ]: {
[ ]: '0xe8905ad29a02cf8befa9c258f4f941773839a618d75a64afc22059de9413f712',
[ ]: '0x31e6376287d223b8c0410d562fb422f04d1d617b2947596a14c3d2efb7218d3a'
}
};
exports.CKBFS_TYPE_ID = {
[ ]: {
[ ]: '0xfd2058c9a0c0183354cf637e25d2707ffa9bb6fa2ba9b29f4ebc6be3e54ad7eb'
},
[ ]: {
[ ]: '0x88ef4d436af35684a27edda0d44dd8771318330285f90f02d13606e095aea86f',
[ ]: '0x7c6dcab8268201f064dc8676b5eafa60ca2569e5c6209dcbab0eb64a9cb3aaa3'
}
};
// Adler32 Hasher Constants
exports.ADLER32_CODE_HASH = {
[ ]: {
[ ]: '0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f'
},
[ ]: {
[ ]: '0x8af42cd329cf1bcffb4c73b48252e99cb32346fdbc1cdaa5ae1d000232d47e84',
[ ]: '0x2138683f76944437c0c643664120d620bdb5858dd6c9d1d156805e279c2c536f'
}
};
exports.ADLER32_TYPE_ID = {
[ ]: {
[ ]: '0x641c01d590833a3f5471bd441651d9f2a8a200141949cdfeef2d68d8094c5876'
},
[ ]: {
[ ]: '0xccf29a0d8e860044a3d2f6a6e709f6572f77e4fe245fadd212fc342337048d60',
[ ]: '0x5f73f128be76e397f5a3b56c94ca16883a8ee91b498bc0ee80473818318c05ac'
}
};
// Dep Group Transaction Constants
exports.DEP_GROUP_TX_HASH = {
[ ]: {
[ ]: '0xfab07962ed7178ed88d450774e2a6ecd50bae856bdb9b692980be8c5147d1bfa'
},
[ ]: {
[ ]: '0xc8fd44aba36f0c4b37536b6c7ea3b88df65fa97e02f77cd33b9bf20bf241a09b',
[ ]: '0x469af0d961dcaaedd872968a9388b546717a6ccfa47b3165b3f9c981e9d66aaa'
}
};
// Deploy Transaction Constants
exports.DEPLOY_TX_HASH = {
[ ]: {
[ ]: {
ckbfs: '0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc',
adler32: '0xc9b6698f44c3b80e7e1c48823b2714e432b93f0206ffaf9df885d23267ed2ebc'
}
},
[ ]: {
[ ]: {
ckbfs: '0xde8eb09151fbcdcba398423159ce348cc89a38a736de3fd0960b18b084465382',
adler32: '0x042f264d7397a181437b51ff9981cf536f252ab5740b61ce52ce31ada04ed54b'
},
[ ]: {
ckbfs: '0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616',
adler32: '0x2c8c9ad3134743368b5a79977648f96c5bd0aba187021a72fb624301064d3616'
}
}
};
// Default values - V2 is now the default
exports.DEFAULT_VERSION = exports.ProtocolVersion.V2;
exports.DEFAULT_NETWORK = NetworkType.Testnet;
/**
* Get CKBFS script configuration for a specific network and version
* @param network Network type (mainnet or testnet)
* @param version Protocol version (default: latest version)
* @param useTypeID Whether to use type ID instead of code hash (default: false)
* @returns CKBFS script configuration
*/
function getCKBFSScriptConfig(network = exports.DEFAULT_NETWORK, version = exports.DEFAULT_VERSION, useTypeID = false) {
return {
codeHash: useTypeID
? exports.CKBFS_TYPE_ID[network][version]
: exports.CKBFS_CODE_HASH[network][version],
hashType: useTypeID ? 'type' : 'data1',
depTxHash: exports.DEP_GROUP_TX_HASH[network][version],
depIndex: 0
};
}