omnipin 2.2.0 → 2.2.3
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/index.js +221 -72
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2139,10 +2139,8 @@ function toZeroPaddedSize(payloadSize) {
|
|
|
2139
2139
|
let size = Math.max(payloadSize, MIN_PAYLOAD_SIZE), highestBit = Math.floor(Math.log2(size)), bound = Math.ceil(calculatePieceCID_FR_RATIO * 2 ** (highestBit + 1));
|
|
2140
2140
|
return size <= bound ? bound : Math.ceil(calculatePieceCID_FR_RATIO * 2 ** (highestBit + 2));
|
|
2141
2141
|
}
|
|
2142
|
-
function
|
|
2143
|
-
|
|
2144
|
-
if (void 0 === last) throw Error('invalid node size');
|
|
2145
|
-
node[31] = 63 & last;
|
|
2142
|
+
function trunc254AtOffset(buf, offset) {
|
|
2143
|
+
buf[offset + 31] = 63 & buf[offset + 31];
|
|
2146
2144
|
}
|
|
2147
2145
|
function readLength(cursor, prefix, offset) {
|
|
2148
2146
|
if (0x80 === offset && prefix < 0x80) return 1;
|
|
@@ -8419,10 +8417,12 @@ let createPresignedUrl = async ({ bucketName, apiUrl, file, token })=>{
|
|
|
8419
8417
|
'x-amz-meta-import': 'car'
|
|
8420
8418
|
}
|
|
8421
8419
|
});
|
|
8422
|
-
}, uploadOnS3 = async ({ name,
|
|
8420
|
+
}, uploadOnS3 = async ({ name, bytes, token, bucketName, apiUrl, providerName, verbose })=>{
|
|
8423
8421
|
let file = new File([
|
|
8424
|
-
|
|
8425
|
-
], name
|
|
8422
|
+
bytes.buffer
|
|
8423
|
+
], name, {
|
|
8424
|
+
type: 'application/vnd.ipld.car'
|
|
8425
|
+
}), res = await uploadCar({
|
|
8426
8426
|
apiUrl,
|
|
8427
8427
|
file,
|
|
8428
8428
|
token,
|
|
@@ -8430,7 +8430,7 @@ let createPresignedUrl = async ({ bucketName, apiUrl, file, token })=>{
|
|
|
8430
8430
|
}), text = await res.text();
|
|
8431
8431
|
if (!res.ok) throw new DeployError(providerName, text);
|
|
8432
8432
|
return verbose && logger.request('PUT', res.url, res.status), res;
|
|
8433
|
-
}, filebase_providerName = 'Filebase', filebase_baseURL = 'https://rpc.filebase.io/api/v0', uploadOnFilebase = async ({ first,
|
|
8433
|
+
}, filebase_providerName = 'Filebase', filebase_baseURL = 'https://rpc.filebase.io/api/v0', uploadOnFilebase = async ({ first, bytes, name, token, bucketName, verbose, cid, size })=>{
|
|
8434
8434
|
if (first) {
|
|
8435
8435
|
if (!bucketName) throw new MissingKeyError("FILEBASE_BUCKET_NAME");
|
|
8436
8436
|
return {
|
|
@@ -8440,8 +8440,8 @@ let createPresignedUrl = async ({ bucketName, apiUrl, file, token })=>{
|
|
|
8440
8440
|
providerName: filebase_providerName,
|
|
8441
8441
|
verbose,
|
|
8442
8442
|
name,
|
|
8443
|
-
|
|
8444
|
-
size
|
|
8443
|
+
bytes,
|
|
8444
|
+
size,
|
|
8445
8445
|
token
|
|
8446
8446
|
})).headers.get('x-amz-meta-cid'),
|
|
8447
8447
|
status: 'queued'
|
|
@@ -10112,11 +10112,14 @@ let filecoinMainnet = {
|
|
|
10112
10112
|
storage: {
|
|
10113
10113
|
address: '0x8408502033C418E1bbC97cE9ac48E5528F371A9f'
|
|
10114
10114
|
},
|
|
10115
|
+
pdpVerifier: {
|
|
10116
|
+
address: '0xBADd0B92C1c71d02E7d520f64c0876538fa2557F'
|
|
10117
|
+
},
|
|
10115
10118
|
providerRegistry: {
|
|
10116
10119
|
address: '0xf55dDbf63F1b55c3F1D4FA7e339a68AB7b64A5eB'
|
|
10117
10120
|
},
|
|
10118
10121
|
storageView: {
|
|
10119
|
-
address: '
|
|
10122
|
+
address: '0xB1B3A3d979c1f233c1021EF98dff9c0932FF1bb9'
|
|
10120
10123
|
}
|
|
10121
10124
|
},
|
|
10122
10125
|
blockExplorer: 'https://filecoin.blockscout.com'
|
|
@@ -10136,11 +10139,14 @@ let filecoinMainnet = {
|
|
|
10136
10139
|
storage: {
|
|
10137
10140
|
address: '0x02925630df557F957f70E112bA06e50965417CA0'
|
|
10138
10141
|
},
|
|
10142
|
+
pdpVerifier: {
|
|
10143
|
+
address: '0x85e366Cf9DD2c0aE37E963d9556F5f4718d6417C'
|
|
10144
|
+
},
|
|
10139
10145
|
providerRegistry: {
|
|
10140
10146
|
address: '0x839e5c9988e4e9977d40708d0094103c0839Ac9D'
|
|
10141
10147
|
},
|
|
10142
10148
|
storageView: {
|
|
10143
|
-
address: '
|
|
10149
|
+
address: '0x537320bd004a7FDd3c1932ca64BD88268301322A'
|
|
10144
10150
|
}
|
|
10145
10151
|
},
|
|
10146
10152
|
blockExplorer: 'https://filecoin-testnet.blockscout.com'
|
|
@@ -10576,6 +10582,140 @@ let getClientDatasets_abi = {
|
|
|
10576
10582
|
]
|
|
10577
10583
|
});
|
|
10578
10584
|
return AbiFunction_decodeResult(getAccountInfo_abi, result);
|
|
10585
|
+
}, getAvailableFunds = async ({ address, chain })=>{
|
|
10586
|
+
let [funds, lockupCurrent, lockupRate, lockupLastSettledAt] = await getAccountInfo({
|
|
10587
|
+
address,
|
|
10588
|
+
chain
|
|
10589
|
+
}), currentEpoch = BigInt(await constants_filProvider[chain.id].request({
|
|
10590
|
+
method: 'eth_blockNumber'
|
|
10591
|
+
})), epochsSinceSettlement = currentEpoch > lockupLastSettledAt ? currentEpoch - lockupLastSettledAt : 0n, settledLockupCurrent = lockupCurrent + epochsSinceSettlement * lockupRate;
|
|
10592
|
+
return {
|
|
10593
|
+
funds,
|
|
10594
|
+
lockupCurrent,
|
|
10595
|
+
lockupRate,
|
|
10596
|
+
lockupLastSettledAt,
|
|
10597
|
+
currentEpoch,
|
|
10598
|
+
epochsSinceSettlement,
|
|
10599
|
+
settledLockupCurrent,
|
|
10600
|
+
availableFunds: funds > settledLockupCurrent ? funds - settledLockupCurrent : 0n
|
|
10601
|
+
};
|
|
10602
|
+
}, DEFAULT_LOCKUP_PERIOD = 30n * 2880n, serviceAbi = [
|
|
10603
|
+
{
|
|
10604
|
+
type: 'function',
|
|
10605
|
+
name: 'getServicePrice',
|
|
10606
|
+
inputs: [],
|
|
10607
|
+
outputs: [
|
|
10608
|
+
{
|
|
10609
|
+
name: 'pricing',
|
|
10610
|
+
internalType: 'struct FilecoinWarmStorageService.ServicePricing',
|
|
10611
|
+
type: 'tuple',
|
|
10612
|
+
components: [
|
|
10613
|
+
{
|
|
10614
|
+
name: 'pricePerTiBPerMonthNoCDN',
|
|
10615
|
+
internalType: 'uint256',
|
|
10616
|
+
type: 'uint256'
|
|
10617
|
+
},
|
|
10618
|
+
{
|
|
10619
|
+
name: 'pricePerTiBCdnEgress',
|
|
10620
|
+
internalType: 'uint256',
|
|
10621
|
+
type: 'uint256'
|
|
10622
|
+
},
|
|
10623
|
+
{
|
|
10624
|
+
name: 'pricePerTiBCacheMissEgress',
|
|
10625
|
+
internalType: 'uint256',
|
|
10626
|
+
type: 'uint256'
|
|
10627
|
+
},
|
|
10628
|
+
{
|
|
10629
|
+
name: 'tokenAddress',
|
|
10630
|
+
internalType: 'contract IERC20',
|
|
10631
|
+
type: 'address'
|
|
10632
|
+
},
|
|
10633
|
+
{
|
|
10634
|
+
name: 'epochsPerMonth',
|
|
10635
|
+
internalType: 'uint256',
|
|
10636
|
+
type: 'uint256'
|
|
10637
|
+
},
|
|
10638
|
+
{
|
|
10639
|
+
name: 'minimumPricePerMonth',
|
|
10640
|
+
internalType: 'uint256',
|
|
10641
|
+
type: 'uint256'
|
|
10642
|
+
}
|
|
10643
|
+
]
|
|
10644
|
+
}
|
|
10645
|
+
],
|
|
10646
|
+
stateMutability: 'view'
|
|
10647
|
+
},
|
|
10648
|
+
{
|
|
10649
|
+
type: 'function',
|
|
10650
|
+
name: 'pdpVerifierAddress',
|
|
10651
|
+
inputs: [],
|
|
10652
|
+
outputs: [
|
|
10653
|
+
{
|
|
10654
|
+
name: '',
|
|
10655
|
+
internalType: 'address',
|
|
10656
|
+
type: 'address'
|
|
10657
|
+
}
|
|
10658
|
+
],
|
|
10659
|
+
stateMutability: 'view'
|
|
10660
|
+
}
|
|
10661
|
+
], pdpVerifierAbi = {
|
|
10662
|
+
type: 'function',
|
|
10663
|
+
name: 'USDFC_SYBIL_FEE',
|
|
10664
|
+
inputs: [],
|
|
10665
|
+
outputs: [
|
|
10666
|
+
{
|
|
10667
|
+
name: '',
|
|
10668
|
+
internalType: 'uint256',
|
|
10669
|
+
type: 'uint256'
|
|
10670
|
+
}
|
|
10671
|
+
],
|
|
10672
|
+
stateMutability: 'view'
|
|
10673
|
+
}, getDataSetCreationRequirements = async ({ chain })=>{
|
|
10674
|
+
let provider = constants_filProvider[chain.id], [servicePriceResult, pdpVerifierResult] = await Promise.all([
|
|
10675
|
+
provider.request({
|
|
10676
|
+
method: 'eth_call',
|
|
10677
|
+
params: [
|
|
10678
|
+
{
|
|
10679
|
+
to: chain.contracts.storage.address,
|
|
10680
|
+
data: AbiFunction_encodeData(serviceAbi[0])
|
|
10681
|
+
},
|
|
10682
|
+
'latest'
|
|
10683
|
+
]
|
|
10684
|
+
}),
|
|
10685
|
+
provider.request({
|
|
10686
|
+
method: 'eth_call',
|
|
10687
|
+
params: [
|
|
10688
|
+
{
|
|
10689
|
+
to: chain.contracts.storage.address,
|
|
10690
|
+
data: AbiFunction_encodeData(serviceAbi[1])
|
|
10691
|
+
},
|
|
10692
|
+
'latest'
|
|
10693
|
+
]
|
|
10694
|
+
})
|
|
10695
|
+
]), { minimumPricePerMonth } = AbiFunction_decodeResult(serviceAbi[0], servicePriceResult), pdpVerifierAddress = AbiFunction_decodeResult(serviceAbi[1], pdpVerifierResult), verifierAddress = '0x0000000000000000000000000000000000000000' === pdpVerifierAddress ? chain.contracts.pdpVerifier.address : pdpVerifierAddress, sybilFeeResult = await provider.request({
|
|
10696
|
+
method: 'eth_call',
|
|
10697
|
+
params: [
|
|
10698
|
+
{
|
|
10699
|
+
to: verifierAddress,
|
|
10700
|
+
data: AbiFunction_encodeData(pdpVerifierAbi)
|
|
10701
|
+
},
|
|
10702
|
+
'latest'
|
|
10703
|
+
]
|
|
10704
|
+
}), sybilFee = AbiFunction_decodeResult(pdpVerifierAbi, sybilFeeResult), requirements = (({ minimumPricePerMonth, sybilFee })=>({
|
|
10705
|
+
defaultLockupPeriod: DEFAULT_LOCKUP_PERIOD,
|
|
10706
|
+
epochsPerMonth: DEFAULT_LOCKUP_PERIOD,
|
|
10707
|
+
minimumLockupRequired: minimumPricePerMonth,
|
|
10708
|
+
creationRequirement: minimumPricePerMonth + sybilFee
|
|
10709
|
+
}))({
|
|
10710
|
+
minimumPricePerMonth,
|
|
10711
|
+
sybilFee
|
|
10712
|
+
});
|
|
10713
|
+
return {
|
|
10714
|
+
minimumPricePerMonth,
|
|
10715
|
+
pdpVerifierAddress: verifierAddress,
|
|
10716
|
+
sybilFee,
|
|
10717
|
+
...requirements
|
|
10718
|
+
};
|
|
10579
10719
|
}, getServicePrice_abi = {
|
|
10580
10720
|
type: 'function',
|
|
10581
10721
|
inputs: [],
|
|
@@ -11960,7 +12100,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
11960
12100
|
await promises_setTimeout(delay);
|
|
11961
12101
|
}
|
|
11962
12102
|
throw Error(`Transaction ${hash} not mined within timeout period`);
|
|
11963
|
-
}, filecoin_providerName = 'Filecoin', uploadToFilecoin = async ({ providerAddress, providerURL, cid,
|
|
12103
|
+
}, filecoin_providerName = 'Filecoin', uploadToFilecoin = async ({ providerAddress, providerURL, cid, bytes, token: privateKey, verbose, filecoinChain = 'mainnet', filecoinForceNewDataset, size })=>{
|
|
11964
12104
|
if (!providerAddress && providerURL) throw new MissingKeyError('FILECOIN_SP_ADDRESS');
|
|
11965
12105
|
let address = fromPublicKey(Secp256k1_getPublicKey({
|
|
11966
12106
|
privateKey
|
|
@@ -11968,7 +12108,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
11968
12108
|
address,
|
|
11969
12109
|
chain
|
|
11970
12110
|
});
|
|
11971
|
-
verbose && (logger.info(`Payer address: ${address}`), logger.info(`Filecoin chain: ${chain.name}`), logger.info(`USDfc balance: ${Value_format(balance, 18)}`), logger.info('Looking up existing data sets'));
|
|
12111
|
+
verbose && (logger.info(`Payer address: ${address}`), logger.info(`Filecoin chain: ${chain.name}`), logger.info(`Wallet USDfc balance: ${Value_format(balance, 18)}`), logger.info('Looking up existing data sets'));
|
|
11972
12112
|
let providerId = await pickProvider({
|
|
11973
12113
|
chain,
|
|
11974
12114
|
...providerAddress ? {
|
|
@@ -11994,7 +12134,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
11994
12134
|
chain
|
|
11995
12135
|
});
|
|
11996
12136
|
logger.info(`Price for storage: ${Value_format(perMonth, 18)} USDfc/month`);
|
|
11997
|
-
let
|
|
12137
|
+
let pieceCid = link_create(raw_code, digest_create(0x1011, function(data) {
|
|
11998
12138
|
let fr32 = function(source) {
|
|
11999
12139
|
let output = new Uint8Array(Math.floor(toZeroPaddedSize(source.length) / calculatePieceCID_FR_RATIO)), quadCount = toZeroPaddedSize(source.length) / 127;
|
|
12000
12140
|
for(let n = 0; n < quadCount; n++){
|
|
@@ -12031,45 +12171,38 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12031
12171
|
return output;
|
|
12032
12172
|
}(data), root = function(fr32) {
|
|
12033
12173
|
if (0 === fr32.length || fr32.length % 32 != 0) throw Error(`invalid fr32 payload size: ${fr32.length}`);
|
|
12034
|
-
let targetLeaves = 1 << Math.ceil(Math.log2(fr32.length / 32)),
|
|
12035
|
-
|
|
12036
|
-
|
|
12037
|
-
|
|
12038
|
-
|
|
12039
|
-
|
|
12040
|
-
let
|
|
12041
|
-
|
|
12042
|
-
|
|
12043
|
-
|
|
12044
|
-
|
|
12045
|
-
let input = new Uint8Array(64);
|
|
12046
|
-
input.set(left, 0), input.set(right, 32);
|
|
12047
|
-
let out = new Uint8Array(hashes_sha2_sha256(input));
|
|
12048
|
-
return trunc254InPlace(out), out;
|
|
12049
|
-
}(left, right);
|
|
12174
|
+
let targetLeaves = 1 << Math.ceil(Math.log2(fr32.length / 32)), buf = new Uint8Array(32 * targetLeaves);
|
|
12175
|
+
buf.set(fr32, 0);
|
|
12176
|
+
for(let i = 0; i < targetLeaves; i++)trunc254AtOffset(buf, 32 * i);
|
|
12177
|
+
let hashInput = new Uint8Array(64), count = targetLeaves;
|
|
12178
|
+
for(; count > 1;){
|
|
12179
|
+
let half = count / 2;
|
|
12180
|
+
for(let i = 0; i < half; i++){
|
|
12181
|
+
let leftOff = 2 * i * 32, rightOff = leftOff + 32;
|
|
12182
|
+
hashInput.set(buf.subarray(leftOff, leftOff + 32), 0), hashInput.set(buf.subarray(rightOff, rightOff + 32), 32);
|
|
12183
|
+
let hash = hashes_sha2_sha256(hashInput), destOff = 32 * i;
|
|
12184
|
+
buf.set(hash, destOff), trunc254AtOffset(buf, destOff);
|
|
12050
12185
|
}
|
|
12051
|
-
|
|
12186
|
+
count = half;
|
|
12052
12187
|
}
|
|
12053
|
-
|
|
12054
|
-
if (!root) throw Error('failed to build piece root');
|
|
12055
|
-
return root;
|
|
12188
|
+
return buf.slice(0, 32);
|
|
12056
12189
|
}(fr32), pieceSize = fr32.length, height = Math.log2(pieceSize / 32);
|
|
12057
12190
|
if (!Number.isInteger(height) || height < 0 || height > 255) throw Error(`invalid piece height for piece size ${pieceSize}`);
|
|
12058
12191
|
let payloadPadding = toZeroPaddedSize(data.length) - data.length, paddingVarint = Uint8Array.from(varint_0.encode(payloadPadding)), out = new Uint8Array(paddingVarint.length + 1 + 32);
|
|
12059
12192
|
return out.set(paddingVarint, 0), out[paddingVarint.length] = height, out.set(root, paddingVarint.length + 1), out;
|
|
12060
|
-
}(
|
|
12193
|
+
}(bytes))), providerActiveDataSets = (await getClientDataSets({
|
|
12061
12194
|
chain,
|
|
12062
12195
|
address
|
|
12063
|
-
})).filter((ds)=>ds.providerId === providerId && 0n === ds.pdpEndEpoch), isNewDataSet = 0 === providerActiveDataSets.length || filecoinForceNewDataset,
|
|
12064
|
-
|
|
12065
|
-
|
|
12196
|
+
})).filter((ds)=>ds.providerId === providerId && 0n === ds.pdpEndEpoch), isNewDataSet = 0 === providerActiveDataSets.length || filecoinForceNewDataset, creationRequirement = isNewDataSet ? (await getDataSetCreationRequirements({
|
|
12197
|
+
chain
|
|
12198
|
+
})).creationRequirement : 0n, requiredAmount = isNewDataSet && creationRequirement > perMonth ? creationRequirement : perMonth;
|
|
12199
|
+
verbose && (logger.info(`Storage price: ${Value_format(perMonth, 18)} USDFC/month`), isNewDataSet && logger.info(`Creation requirement: ${Value_format(creationRequirement, 18)} USDFC`), logger.info(`Required funds: ${Value_format(requiredAmount, 18)} USDFC`));
|
|
12200
|
+
let { funds, availableFunds } = await getAvailableFunds({
|
|
12066
12201
|
address,
|
|
12067
12202
|
chain
|
|
12068
|
-
})
|
|
12069
|
-
|
|
12070
|
-
|
|
12071
|
-
logger.info(`Available funds: ${Value_format(availableFunds, 18)} USDFC`);
|
|
12072
|
-
let depositNeeded = totalRequired > availableFunds ? totalRequired - availableFunds : 0n;
|
|
12203
|
+
});
|
|
12204
|
+
verbose && logger.info(`Filecoin Pay deposited funds: ${Value_format(funds, 18)} USDFC`), logger.info(`Filecoin Pay available funds: ${Value_format(availableFunds, 18)} USDFC`);
|
|
12205
|
+
let depositNeeded = requiredAmount > availableFunds ? requiredAmount - availableFunds : 0n;
|
|
12073
12206
|
if (depositNeeded > 0n) {
|
|
12074
12207
|
verbose && logger.info(`Depositing ${Value_format(depositNeeded, 18)} USDFC`);
|
|
12075
12208
|
let params = await depositAndApproveOperatorWriteParameters({
|
|
@@ -12091,7 +12224,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12091
12224
|
logger.info('Creating new data set'), verbose && logger.info('Uploading piece to provider'), await uploadPiece({
|
|
12092
12225
|
providerURL,
|
|
12093
12226
|
pieceCid: pieceCid.toString(),
|
|
12094
|
-
bytes:
|
|
12227
|
+
bytes: bytes
|
|
12095
12228
|
}), verbose && logger.info('Waiting for piece to be stored at provider'), await findPiece(providerURL, pieceCid.toString(), {
|
|
12096
12229
|
verbose
|
|
12097
12230
|
});
|
|
@@ -12186,7 +12319,7 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12186
12319
|
verbose && logger.info(`Data set ID: ${dataset.dataSetId}`), verbose && logger.info('Uploading piece to provider'), await uploadPiece({
|
|
12187
12320
|
providerURL,
|
|
12188
12321
|
pieceCid: pieceCid.toString(),
|
|
12189
|
-
bytes:
|
|
12322
|
+
bytes: bytes
|
|
12190
12323
|
}), logger.info('Waiting for piece to be stored at provider'), await findPiece(providerURL, pieceCid.toString(), {
|
|
12191
12324
|
verbose
|
|
12192
12325
|
});
|
|
@@ -12211,10 +12344,14 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12211
12344
|
}), logger.success('Piece found'), {
|
|
12212
12345
|
cid
|
|
12213
12346
|
};
|
|
12214
|
-
}, lighthouse_providerName = 'Lighthouse', uploadOnLighthouse = async ({
|
|
12347
|
+
}, lighthouse_providerName = 'Lighthouse', uploadOnLighthouse = async ({ bytes, name, first, token, verbose, cid })=>{
|
|
12215
12348
|
if (first) {
|
|
12216
12349
|
let fd = new FormData();
|
|
12217
|
-
fd.append('file',
|
|
12350
|
+
fd.append('file', new Blob([
|
|
12351
|
+
Uint8Array.from(bytes).buffer
|
|
12352
|
+
], {
|
|
12353
|
+
type: 'application/vnd.ipld.car'
|
|
12354
|
+
}), `${name}.car`);
|
|
12218
12355
|
let res = await fetch('https://upload.lighthouse.storage/api/v0/dag/import', {
|
|
12219
12356
|
method: 'POST',
|
|
12220
12357
|
headers: {
|
|
@@ -12246,10 +12383,14 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12246
12383
|
cid,
|
|
12247
12384
|
status: 'queued'
|
|
12248
12385
|
};
|
|
12249
|
-
}, pinata_providerName = 'Pinata', uploadOnPinata = async ({
|
|
12386
|
+
}, pinata_providerName = 'Pinata', uploadOnPinata = async ({ bytes, name, token, verbose, first, cid })=>{
|
|
12250
12387
|
if (first) {
|
|
12251
12388
|
let fd = new FormData();
|
|
12252
|
-
fd.append('file',
|
|
12389
|
+
fd.append('file', new Blob([
|
|
12390
|
+
bytes.buffer
|
|
12391
|
+
], {
|
|
12392
|
+
type: 'application/vnd.ipld.car'
|
|
12393
|
+
})), fd.append('network', 'public'), fd.append('name', `${name}.car`), fd.append('car', 'true');
|
|
12253
12394
|
let res = await fetch('https://uploads.pinata.cloud/v3/files', {
|
|
12254
12395
|
method: 'POST',
|
|
12255
12396
|
headers: {
|
|
@@ -12291,10 +12432,10 @@ let serializedType = '0x02', TxEnvelopeEip1559_type = 'eip1559', SIMULATION_GAS_
|
|
|
12291
12432
|
status: json.status,
|
|
12292
12433
|
cid: json.pin.cid
|
|
12293
12434
|
};
|
|
12294
|
-
}, uploadToSimplePage = async ({ token,
|
|
12435
|
+
}, uploadToSimplePage = async ({ token, bytes, name })=>{
|
|
12295
12436
|
let fd = new FormData();
|
|
12296
12437
|
fd.append('file', new File([
|
|
12297
|
-
|
|
12438
|
+
bytes.buffer
|
|
12298
12439
|
], `${name}.car`, {
|
|
12299
12440
|
type: 'application/vnd.ipld.car'
|
|
12300
12441
|
}));
|
|
@@ -17710,13 +17851,18 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17710
17851
|
}, swarmy_providerName = 'Swarmy', PROVIDERS = {
|
|
17711
17852
|
STORACHA_TOKEN: {
|
|
17712
17853
|
name: 'Storacha',
|
|
17713
|
-
upload: async ({ token,
|
|
17854
|
+
upload: async ({ token, bytes, proof })=>{
|
|
17714
17855
|
if (!proof) throw new MissingKeyError("STORACHA_PROOF");
|
|
17715
17856
|
let { agent, space } = await setup({
|
|
17716
17857
|
pk: token,
|
|
17717
17858
|
proof
|
|
17718
17859
|
});
|
|
17719
17860
|
if (!space) throw Error('No space found');
|
|
17861
|
+
let blob = new Blob([
|
|
17862
|
+
bytes.buffer
|
|
17863
|
+
], {
|
|
17864
|
+
type: 'application/vnd.ipld.car'
|
|
17865
|
+
});
|
|
17720
17866
|
try {
|
|
17721
17867
|
return {
|
|
17722
17868
|
cid: (await uploadCAR({
|
|
@@ -17726,7 +17872,7 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17726
17872
|
with: space.did()
|
|
17727
17873
|
}))),
|
|
17728
17874
|
with: space.did()
|
|
17729
|
-
},
|
|
17875
|
+
}, blob)).toString()
|
|
17730
17876
|
};
|
|
17731
17877
|
} catch (e) {
|
|
17732
17878
|
throw new DeployError('Storacha', e.message, {
|
|
@@ -17789,10 +17935,12 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17789
17935
|
},
|
|
17790
17936
|
SWARMY_TOKEN: {
|
|
17791
17937
|
name: 'Swarmy',
|
|
17792
|
-
upload: async ({ token,
|
|
17938
|
+
upload: async ({ token, bytes, verbose, first })=>{
|
|
17793
17939
|
if (!first) throw new PinningNotSupportedError(swarmy_providerName);
|
|
17794
17940
|
let body = new FormData();
|
|
17795
|
-
body.append('file',
|
|
17941
|
+
body.append('file', new Blob([
|
|
17942
|
+
bytes.buffer
|
|
17943
|
+
]));
|
|
17796
17944
|
let res = await fetch('https://api.swarmy.cloud/api/files?website=true', {
|
|
17797
17945
|
body,
|
|
17798
17946
|
headers: {
|
|
@@ -17811,10 +17959,12 @@ let uploadCAR = async (conf, car)=>{
|
|
|
17811
17959
|
},
|
|
17812
17960
|
BEE_TOKEN: {
|
|
17813
17961
|
name: 'Bee',
|
|
17814
|
-
upload: async ({ token,
|
|
17962
|
+
upload: async ({ token, bytes, verbose, beeURL, first })=>{
|
|
17815
17963
|
if (!first) throw new PinningNotSupportedError('Bee');
|
|
17816
17964
|
let res = await fetch(`${beeURL}/bzz`, {
|
|
17817
|
-
body:
|
|
17965
|
+
body: new Blob([
|
|
17966
|
+
bytes.buffer
|
|
17967
|
+
]),
|
|
17818
17968
|
headers: {
|
|
17819
17969
|
'Swarm-Postage-Batch-Id': token,
|
|
17820
17970
|
'Content-Type': 'application/x-tar',
|
|
@@ -20379,6 +20529,9 @@ class MemoryBlockstore {
|
|
|
20379
20529
|
async delete(key, options) {
|
|
20380
20530
|
options?.signal?.throwIfAborted(), this.data.delete(base32.encode(key.multihash.bytes));
|
|
20381
20531
|
}
|
|
20532
|
+
clear() {
|
|
20533
|
+
this.data.clear();
|
|
20534
|
+
}
|
|
20382
20535
|
*getAll(options) {
|
|
20383
20536
|
for (let [key, value] of (options?.signal?.throwIfAborted(), this.data.entries()))yield {
|
|
20384
20537
|
cid: cid_CID.createV1(raw_code, digest_decode(base32.decode(key))),
|
|
@@ -20415,12 +20568,10 @@ let ipfs_tmp = tmpdir(), ipfs_concatBytes = (chunks)=>{
|
|
|
20415
20568
|
} catch (error) {
|
|
20416
20569
|
console.warn(`Failed to add block ${cid.toString()} to CAR:`, error);
|
|
20417
20570
|
}
|
|
20418
|
-
|
|
20419
|
-
|
|
20420
|
-
|
|
20421
|
-
|
|
20422
|
-
type: 'application/vnd.ipld.car'
|
|
20423
|
-
}),
|
|
20571
|
+
await writer.close(), await writePromise, writeStream.end(), await new Promise((resolve)=>writeStream.on('close', resolve));
|
|
20572
|
+
let file = await readFile(output);
|
|
20573
|
+
return blockstore.clear(), {
|
|
20574
|
+
bytes: file,
|
|
20424
20575
|
rootCID
|
|
20425
20576
|
};
|
|
20426
20577
|
}, assertCID = (cid)=>{
|
|
@@ -21232,17 +21383,15 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21232
21383
|
'dist'
|
|
21233
21384
|
].includes(dir) ? name : dir;
|
|
21234
21385
|
if (onlyHash || logger.start(`Packing ${isTTY ? styleText('cyan', distName) : distName} (${fileSize(size, 2)})`), tar) return {
|
|
21235
|
-
|
|
21236
|
-
await packTAR(files)
|
|
21237
|
-
]),
|
|
21386
|
+
bytes: await packTAR(files),
|
|
21238
21387
|
size
|
|
21239
21388
|
};
|
|
21240
21389
|
{
|
|
21241
|
-
let { rootCID,
|
|
21390
|
+
let { rootCID, bytes } = await packCAR(files, name, dist), cid = rootCID.toString();
|
|
21242
21391
|
return onlyHash ? console.log(cid) : logger.info(`Root CID: ${isTTY ? styleText('white', cid) : cid}`), {
|
|
21243
21392
|
name,
|
|
21244
21393
|
cid,
|
|
21245
|
-
|
|
21394
|
+
bytes,
|
|
21246
21395
|
files,
|
|
21247
21396
|
size
|
|
21248
21397
|
};
|
|
@@ -21251,7 +21400,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21251
21400
|
let cid, { strict, ens, chain = 'mainnet', name: customName, dist, verbose = !1, providers: providersList, dnslink, 'progress-bar': progressBar, 'filecoin-chain': filecoinChain, 'filecoin-force-new-dataset': filecoinForceNewDataset, ...opts } = options, apiTokens = parseTokensFromEnv(), allProviders = (providersList ? providersList.split(',') : tokensToProviderNames(apiTokens.keys())).map((providerName)=>PROVIDERS[findEnvVarProviderName(providerName)]), ipfsProviders = allProviders.filter((p)=>'ipfs' === p.protocol), swarmProviders = allProviders.filter((p)=>'swarm' === p.protocol);
|
|
21252
21401
|
if (ipfsProviders.sort((a)=>'both' === a.supported || 'upload' === a.supported ? -1 : 1), !allProviders.length) throw new NoProvidersError();
|
|
21253
21402
|
logger.info(`Deploying with providers: ${(swarmProviders.length ? swarmProviders : ipfsProviders).map((p)=>p.name).join(', ')}`);
|
|
21254
|
-
let { name, cid: ipfsCid,
|
|
21403
|
+
let { name, cid: ipfsCid, bytes, size } = await packAction({
|
|
21255
21404
|
dir,
|
|
21256
21405
|
options: {
|
|
21257
21406
|
name: customName,
|
|
@@ -21272,7 +21421,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21272
21421
|
let envVar = findEnvVarProviderName(provider.name);
|
|
21273
21422
|
try {
|
|
21274
21423
|
let result = await provider.upload({
|
|
21275
|
-
|
|
21424
|
+
bytes,
|
|
21276
21425
|
token: apiTokens.get(envVar),
|
|
21277
21426
|
verbose,
|
|
21278
21427
|
name: '',
|
|
@@ -21294,7 +21443,7 @@ let ENS_DEPLOYER_ROLE = keccak256(Bytes_fromString('ENS_DEPLOYER')), execTransac
|
|
|
21294
21443
|
try {
|
|
21295
21444
|
await provider.upload({
|
|
21296
21445
|
name,
|
|
21297
|
-
|
|
21446
|
+
bytes,
|
|
21298
21447
|
token,
|
|
21299
21448
|
bucketName,
|
|
21300
21449
|
proof: apiTokens.get('STORACHA_PROOF'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnipin",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"author": "v1rtl <hi@v1rtl.site>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@biomejs/biome": "^2.4.7",
|
|
11
11
|
"@ipld/car": "^5.4.2",
|
|
12
12
|
"@ipld/dag-ucan": "^3.4.5",
|
|
13
|
-
"@omnipin/foc": "npm:@jsr/omnipin__foc@0.0.
|
|
13
|
+
"@omnipin/foc": "npm:@jsr/omnipin__foc@0.0.12",
|
|
14
14
|
"@rslib/core": "^0.20.0",
|
|
15
15
|
"@size-limit/file": "^12.0.1",
|
|
16
16
|
"@stauro/filebase-upload": "npm:@jsr/stauro__filebase-upload",
|