@stacks/bns
Advanced tools
Comparing version 2.0.0-beta.1 to 2.0.1-beta.1
@@ -6,4 +6,38 @@ # Change Log | ||
## [2.0.1-beta.1](https://github.com/blockstack/stacks.js/compare/v2.0.0-beta.1...v2.0.1-beta.1) (2021-07-26) | ||
### Bug Fixes | ||
* add missing stx burn and NFT post conditions ([7e0fcba](https://github.com/blockstack/stacks.js/commit/7e0fcba3f52062e9531923e82676e1121a9a3eb0)) | ||
* fix optional argument encoding and update test cases in bns transferName, renewName calls ([6f4f8fa](https://github.com/blockstack/stacks.js/commit/6f4f8fa67e208541adf9acbe780f74a8d002e5a2)) | ||
### Features | ||
* refactor all js `number` and `bn.js` usages in Clarity integer values to native bigint ([1f78339](https://github.com/blockstack/stacks.js/commit/1f783397e7f5b38aabb6e0342af71b58022aed4c)) | ||
# [2.0.0-beta.2](https://github.com/blockstack/stacks.js/compare/v2.0.0-beta.1...v2.0.0-beta.2) (2021-07-26) | ||
### Bug Fixes | ||
* add missing stx burn and NFT post conditions ([7e0fcba](https://github.com/blockstack/stacks.js/commit/7e0fcba3f52062e9531923e82676e1121a9a3eb0)) | ||
* fix optional argument encoding and update test cases in bns transferName, renewName calls ([6f4f8fa](https://github.com/blockstack/stacks.js/commit/6f4f8fa67e208541adf9acbe780f74a8d002e5a2)) | ||
### Features | ||
* refactor all js `number` and `bn.js` usages in Clarity integer values to native bigint ([1f78339](https://github.com/blockstack/stacks.js/commit/1f783397e7f5b38aabb6e0342af71b58022aed4c)) | ||
## [1.4.1](https://github.com/blockstack/stacks.js/compare/v1.4.1-alpha.0...v1.4.1) (2021-04-20) | ||
**Note:** Version bump only for package @stacks/bns |
/// <reference types="node" /> | ||
import { ClarityValue, StacksTransaction } from '@stacks/transactions'; | ||
import { IntegerType } from '@stacks/common'; | ||
import { ClarityValue, StacksTransaction, PostCondition } from '@stacks/transactions'; | ||
import { StacksNetwork } from '@stacks/network'; | ||
import BN from 'bn.js'; | ||
export declare const BNS_CONTRACT_NAME = "bns"; | ||
@@ -11,22 +11,22 @@ export declare const enum BnsContractAddress { | ||
export interface PriceFunction { | ||
base: BN; | ||
coefficient: BN; | ||
b1: BN; | ||
b2: BN; | ||
b3: BN; | ||
b4: BN; | ||
b5: BN; | ||
b6: BN; | ||
b7: BN; | ||
b8: BN; | ||
b9: BN; | ||
b10: BN; | ||
b11: BN; | ||
b12: BN; | ||
b13: BN; | ||
b14: BN; | ||
b15: BN; | ||
b16: BN; | ||
nonAlphaDiscount: BN; | ||
noVowelDiscount: BN; | ||
base: IntegerType; | ||
coefficient: IntegerType; | ||
b1: IntegerType; | ||
b2: IntegerType; | ||
b3: IntegerType; | ||
b4: IntegerType; | ||
b5: IntegerType; | ||
b6: IntegerType; | ||
b7: IntegerType; | ||
b8: IntegerType; | ||
b9: IntegerType; | ||
b10: IntegerType; | ||
b11: IntegerType; | ||
b12: IntegerType; | ||
b13: IntegerType; | ||
b14: IntegerType; | ||
b15: IntegerType; | ||
b16: IntegerType; | ||
nonAlphaDiscount: IntegerType; | ||
noVowelDiscount: IntegerType; | ||
} | ||
@@ -39,2 +39,3 @@ export interface BnsContractCallOptions { | ||
attachment?: Buffer; | ||
postConditions?: PostCondition[]; | ||
} | ||
@@ -56,3 +57,3 @@ export interface BnsReadOnlyOptions { | ||
} | ||
export declare function getNamespacePrice({ namespace, network, }: GetNamespacePriceOptions): Promise<BN>; | ||
export declare function getNamespacePrice({ namespace, network, }: GetNamespacePriceOptions): Promise<bigint>; | ||
export interface GetNamePriceOptions { | ||
@@ -62,7 +63,7 @@ fullyQualifiedName: string; | ||
} | ||
export declare function getNamePrice({ fullyQualifiedName, network, }: GetNamePriceOptions): Promise<BN>; | ||
export declare function getNamePrice({ fullyQualifiedName, network, }: GetNamePriceOptions): Promise<bigint>; | ||
export interface PreorderNamespaceOptions { | ||
namespace: string; | ||
salt: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -76,3 +77,3 @@ network: StacksNetwork; | ||
priceFunction: PriceFunction; | ||
lifetime: BN; | ||
lifetime: IntegerType; | ||
namespaceImportAddress: string; | ||
@@ -101,3 +102,3 @@ publicKey: string; | ||
salt: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -138,3 +139,3 @@ network: StacksNetwork; | ||
fullyQualifiedName: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -141,0 +142,0 @@ network: StacksNetwork; |
import { Buffer } from '@stacks/common'; | ||
import { AnchorMode, bufferCV, callReadOnlyFunction, ClarityType, cvToString, getAddressFromPrivateKey, getCVTypeString, hash160, makeRandomPrivKey, makeUnsignedContractCall, privateKeyToString, standardPrincipalCV, } from '@stacks/transactions'; | ||
import { bufferCVFromString, decodeFQN, getZonefileHash, uintCVFromBN } from './utils'; | ||
import { AnchorMode, bufferCV, callReadOnlyFunction, ClarityType, cvToString, getAddressFromPrivateKey, getCVTypeString, hash160, makeRandomPrivKey, makeUnsignedContractCall, privateKeyToString, standardPrincipalCV, uintCV, someCV, noneCV, createSTXPostCondition, createStacksPublicKey, publicKeyToAddress, FungibleConditionCode, AddressVersion, createNonFungiblePostCondition, NonFungibleConditionCode, parseAssetInfoString, tupleCV, } from '@stacks/transactions'; | ||
import { bufferCVFromString, decodeFQN, getZonefileHash } from './utils'; | ||
import { ChainID } from '@stacks/common'; | ||
@@ -14,2 +14,7 @@ export const BNS_CONTRACT_NAME = 'bns'; | ||
} | ||
function getAddressVersion(network) { | ||
return network.chainId === ChainID.Mainnet | ||
? AddressVersion.MainnetSingleSig | ||
: AddressVersion.TestnetSingleSig; | ||
} | ||
async function makeBnsContractCall(options) { | ||
@@ -25,2 +30,3 @@ const txOptions = { | ||
anchorMode: AnchorMode.Any, | ||
postConditions: options.postConditions, | ||
}; | ||
@@ -119,7 +125,9 @@ return makeUnsignedContractCall(txOptions); | ||
const hashedSaltedNamespace = hash160(saltedNamespaceBuffer); | ||
const burnSTXPostCondition = createSTXPostCondition(publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [bufferCV(hashedSaltedNamespace), uintCVFromBN(stxToBurn)], | ||
functionArgs: [bufferCV(hashedSaltedNamespace), uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -134,23 +142,23 @@ } | ||
bufferCVFromString(salt), | ||
uintCVFromBN(priceFunction.base), | ||
uintCVFromBN(priceFunction.coefficient), | ||
uintCVFromBN(priceFunction.b1), | ||
uintCVFromBN(priceFunction.b2), | ||
uintCVFromBN(priceFunction.b3), | ||
uintCVFromBN(priceFunction.b4), | ||
uintCVFromBN(priceFunction.b5), | ||
uintCVFromBN(priceFunction.b6), | ||
uintCVFromBN(priceFunction.b7), | ||
uintCVFromBN(priceFunction.b8), | ||
uintCVFromBN(priceFunction.b9), | ||
uintCVFromBN(priceFunction.b10), | ||
uintCVFromBN(priceFunction.b11), | ||
uintCVFromBN(priceFunction.b12), | ||
uintCVFromBN(priceFunction.b13), | ||
uintCVFromBN(priceFunction.b14), | ||
uintCVFromBN(priceFunction.b15), | ||
uintCVFromBN(priceFunction.b16), | ||
uintCVFromBN(priceFunction.nonAlphaDiscount), | ||
uintCVFromBN(priceFunction.noVowelDiscount), | ||
uintCVFromBN(lifetime), | ||
uintCV(priceFunction.base), | ||
uintCV(priceFunction.coefficient), | ||
uintCV(priceFunction.b1), | ||
uintCV(priceFunction.b2), | ||
uintCV(priceFunction.b3), | ||
uintCV(priceFunction.b4), | ||
uintCV(priceFunction.b5), | ||
uintCV(priceFunction.b6), | ||
uintCV(priceFunction.b7), | ||
uintCV(priceFunction.b8), | ||
uintCV(priceFunction.b9), | ||
uintCV(priceFunction.b10), | ||
uintCV(priceFunction.b11), | ||
uintCV(priceFunction.b12), | ||
uintCV(priceFunction.b13), | ||
uintCV(priceFunction.b14), | ||
uintCV(priceFunction.b15), | ||
uintCV(priceFunction.b16), | ||
uintCV(priceFunction.nonAlphaDiscount), | ||
uintCV(priceFunction.noVowelDiscount), | ||
uintCV(lifetime), | ||
standardPrincipalCV(namespaceImportAddress), | ||
@@ -195,7 +203,9 @@ ], | ||
const hashedSaltedName = hash160(saltedNamesBuffer); | ||
const burnSTXPostCondition = createSTXPostCondition(publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [bufferCV(hashedSaltedName), uintCVFromBN(stxToBurn)], | ||
functionArgs: [bufferCV(hashedSaltedName), uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -247,7 +257,13 @@ } | ||
bufferCVFromString(name), | ||
bufferCVFromString(newOwnerAddress), | ||
standardPrincipalCV(newOwnerAddress), | ||
zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), | ||
]; | ||
if (zonefile) { | ||
functionArgs.push(bufferCV(getZonefileHash(zonefile))); | ||
} | ||
const postConditionSender = createNonFungiblePostCondition(publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), NonFungibleConditionCode.DoesNotOwn, parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), tupleCV({ | ||
name: bufferCVFromString(name), | ||
namespace: bufferCVFromString(namespace), | ||
})); | ||
const postConditionReceiver = createNonFungiblePostCondition(newOwnerAddress, NonFungibleConditionCode.Owns, parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), tupleCV({ | ||
name: bufferCVFromString(name), | ||
namespace: bufferCVFromString(namespace), | ||
})); | ||
return makeBnsContractCall({ | ||
@@ -259,2 +275,3 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? Buffer.from(zonefile) : undefined, | ||
postConditions: [postConditionSender, postConditionReceiver], | ||
}); | ||
@@ -284,11 +301,7 @@ } | ||
bufferCVFromString(name), | ||
uintCVFromBN(stxToBurn), | ||
uintCV(stxToBurn), | ||
newOwnerAddress ? someCV(standardPrincipalCV(newOwnerAddress)) : noneCV(), | ||
zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), | ||
]; | ||
if (newOwnerAddress) { | ||
functionArgs.push(bufferCVFromString(newOwnerAddress)); | ||
} | ||
if (zonefile) { | ||
const zonefileHash = getZonefileHash(zonefile); | ||
functionArgs.push(bufferCV(zonefileHash)); | ||
} | ||
const burnSTXPostCondition = createSTXPostCondition(publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
@@ -300,4 +313,5 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? Buffer.from(zonefile) : undefined, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
/// <reference types="node" /> | ||
import { ClarityValue, StacksTransaction } from '@stacks/transactions'; | ||
import { IntegerType } from '@stacks/common'; | ||
import { ClarityValue, StacksTransaction, PostCondition } from '@stacks/transactions'; | ||
import { StacksNetwork } from '@stacks/network'; | ||
import BN from 'bn.js'; | ||
export declare const BNS_CONTRACT_NAME = "bns"; | ||
@@ -11,22 +11,22 @@ export declare const enum BnsContractAddress { | ||
export interface PriceFunction { | ||
base: BN; | ||
coefficient: BN; | ||
b1: BN; | ||
b2: BN; | ||
b3: BN; | ||
b4: BN; | ||
b5: BN; | ||
b6: BN; | ||
b7: BN; | ||
b8: BN; | ||
b9: BN; | ||
b10: BN; | ||
b11: BN; | ||
b12: BN; | ||
b13: BN; | ||
b14: BN; | ||
b15: BN; | ||
b16: BN; | ||
nonAlphaDiscount: BN; | ||
noVowelDiscount: BN; | ||
base: IntegerType; | ||
coefficient: IntegerType; | ||
b1: IntegerType; | ||
b2: IntegerType; | ||
b3: IntegerType; | ||
b4: IntegerType; | ||
b5: IntegerType; | ||
b6: IntegerType; | ||
b7: IntegerType; | ||
b8: IntegerType; | ||
b9: IntegerType; | ||
b10: IntegerType; | ||
b11: IntegerType; | ||
b12: IntegerType; | ||
b13: IntegerType; | ||
b14: IntegerType; | ||
b15: IntegerType; | ||
b16: IntegerType; | ||
nonAlphaDiscount: IntegerType; | ||
noVowelDiscount: IntegerType; | ||
} | ||
@@ -39,2 +39,3 @@ export interface BnsContractCallOptions { | ||
attachment?: Buffer; | ||
postConditions?: PostCondition[]; | ||
} | ||
@@ -56,3 +57,3 @@ export interface BnsReadOnlyOptions { | ||
} | ||
export declare function getNamespacePrice({ namespace, network, }: GetNamespacePriceOptions): Promise<BN>; | ||
export declare function getNamespacePrice({ namespace, network, }: GetNamespacePriceOptions): Promise<bigint>; | ||
export interface GetNamePriceOptions { | ||
@@ -62,7 +63,7 @@ fullyQualifiedName: string; | ||
} | ||
export declare function getNamePrice({ fullyQualifiedName, network, }: GetNamePriceOptions): Promise<BN>; | ||
export declare function getNamePrice({ fullyQualifiedName, network, }: GetNamePriceOptions): Promise<bigint>; | ||
export interface PreorderNamespaceOptions { | ||
namespace: string; | ||
salt: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -76,3 +77,3 @@ network: StacksNetwork; | ||
priceFunction: PriceFunction; | ||
lifetime: BN; | ||
lifetime: IntegerType; | ||
namespaceImportAddress: string; | ||
@@ -101,3 +102,3 @@ publicKey: string; | ||
salt: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -138,3 +139,3 @@ network: StacksNetwork; | ||
fullyQualifiedName: string; | ||
stxToBurn: BN; | ||
stxToBurn: IntegerType; | ||
publicKey: string; | ||
@@ -141,0 +142,0 @@ network: StacksNetwork; |
@@ -17,2 +17,7 @@ "use strict"; | ||
} | ||
function getAddressVersion(network) { | ||
return network.chainId === common_2.ChainID.Mainnet | ||
? transactions_1.AddressVersion.MainnetSingleSig | ||
: transactions_1.AddressVersion.TestnetSingleSig; | ||
} | ||
async function makeBnsContractCall(options) { | ||
@@ -28,2 +33,3 @@ const txOptions = { | ||
anchorMode: transactions_1.AnchorMode.Any, | ||
postConditions: options.postConditions, | ||
}; | ||
@@ -125,7 +131,9 @@ return transactions_1.makeUnsignedContractCall(txOptions); | ||
const hashedSaltedNamespace = transactions_1.hash160(saltedNamespaceBuffer); | ||
const burnSTXPostCondition = transactions_1.createSTXPostCondition(transactions_1.publicKeyToAddress(getAddressVersion(network), transactions_1.createStacksPublicKey(publicKey)), transactions_1.FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [transactions_1.bufferCV(hashedSaltedNamespace), utils_1.uintCVFromBN(stxToBurn)], | ||
functionArgs: [transactions_1.bufferCV(hashedSaltedNamespace), transactions_1.uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -141,23 +149,23 @@ } | ||
utils_1.bufferCVFromString(salt), | ||
utils_1.uintCVFromBN(priceFunction.base), | ||
utils_1.uintCVFromBN(priceFunction.coefficient), | ||
utils_1.uintCVFromBN(priceFunction.b1), | ||
utils_1.uintCVFromBN(priceFunction.b2), | ||
utils_1.uintCVFromBN(priceFunction.b3), | ||
utils_1.uintCVFromBN(priceFunction.b4), | ||
utils_1.uintCVFromBN(priceFunction.b5), | ||
utils_1.uintCVFromBN(priceFunction.b6), | ||
utils_1.uintCVFromBN(priceFunction.b7), | ||
utils_1.uintCVFromBN(priceFunction.b8), | ||
utils_1.uintCVFromBN(priceFunction.b9), | ||
utils_1.uintCVFromBN(priceFunction.b10), | ||
utils_1.uintCVFromBN(priceFunction.b11), | ||
utils_1.uintCVFromBN(priceFunction.b12), | ||
utils_1.uintCVFromBN(priceFunction.b13), | ||
utils_1.uintCVFromBN(priceFunction.b14), | ||
utils_1.uintCVFromBN(priceFunction.b15), | ||
utils_1.uintCVFromBN(priceFunction.b16), | ||
utils_1.uintCVFromBN(priceFunction.nonAlphaDiscount), | ||
utils_1.uintCVFromBN(priceFunction.noVowelDiscount), | ||
utils_1.uintCVFromBN(lifetime), | ||
transactions_1.uintCV(priceFunction.base), | ||
transactions_1.uintCV(priceFunction.coefficient), | ||
transactions_1.uintCV(priceFunction.b1), | ||
transactions_1.uintCV(priceFunction.b2), | ||
transactions_1.uintCV(priceFunction.b3), | ||
transactions_1.uintCV(priceFunction.b4), | ||
transactions_1.uintCV(priceFunction.b5), | ||
transactions_1.uintCV(priceFunction.b6), | ||
transactions_1.uintCV(priceFunction.b7), | ||
transactions_1.uintCV(priceFunction.b8), | ||
transactions_1.uintCV(priceFunction.b9), | ||
transactions_1.uintCV(priceFunction.b10), | ||
transactions_1.uintCV(priceFunction.b11), | ||
transactions_1.uintCV(priceFunction.b12), | ||
transactions_1.uintCV(priceFunction.b13), | ||
transactions_1.uintCV(priceFunction.b14), | ||
transactions_1.uintCV(priceFunction.b15), | ||
transactions_1.uintCV(priceFunction.b16), | ||
transactions_1.uintCV(priceFunction.nonAlphaDiscount), | ||
transactions_1.uintCV(priceFunction.noVowelDiscount), | ||
transactions_1.uintCV(lifetime), | ||
transactions_1.standardPrincipalCV(namespaceImportAddress), | ||
@@ -205,7 +213,9 @@ ], | ||
const hashedSaltedName = transactions_1.hash160(saltedNamesBuffer); | ||
const burnSTXPostCondition = transactions_1.createSTXPostCondition(transactions_1.publicKeyToAddress(getAddressVersion(network), transactions_1.createStacksPublicKey(publicKey)), transactions_1.FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [transactions_1.bufferCV(hashedSaltedName), utils_1.uintCVFromBN(stxToBurn)], | ||
functionArgs: [transactions_1.bufferCV(hashedSaltedName), transactions_1.uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -260,7 +270,13 @@ } | ||
utils_1.bufferCVFromString(name), | ||
utils_1.bufferCVFromString(newOwnerAddress), | ||
transactions_1.standardPrincipalCV(newOwnerAddress), | ||
zonefile ? transactions_1.someCV(transactions_1.bufferCV(utils_1.getZonefileHash(zonefile))) : transactions_1.noneCV(), | ||
]; | ||
if (zonefile) { | ||
functionArgs.push(transactions_1.bufferCV(utils_1.getZonefileHash(zonefile))); | ||
} | ||
const postConditionSender = transactions_1.createNonFungiblePostCondition(transactions_1.publicKeyToAddress(getAddressVersion(network), transactions_1.createStacksPublicKey(publicKey)), transactions_1.NonFungibleConditionCode.DoesNotOwn, transactions_1.parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), transactions_1.tupleCV({ | ||
name: utils_1.bufferCVFromString(name), | ||
namespace: utils_1.bufferCVFromString(namespace), | ||
})); | ||
const postConditionReceiver = transactions_1.createNonFungiblePostCondition(newOwnerAddress, transactions_1.NonFungibleConditionCode.Owns, transactions_1.parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), transactions_1.tupleCV({ | ||
name: utils_1.bufferCVFromString(name), | ||
namespace: utils_1.bufferCVFromString(namespace), | ||
})); | ||
return makeBnsContractCall({ | ||
@@ -272,2 +288,3 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? common_1.Buffer.from(zonefile) : undefined, | ||
postConditions: [postConditionSender, postConditionReceiver], | ||
}); | ||
@@ -299,11 +316,7 @@ } | ||
utils_1.bufferCVFromString(name), | ||
utils_1.uintCVFromBN(stxToBurn), | ||
transactions_1.uintCV(stxToBurn), | ||
newOwnerAddress ? transactions_1.someCV(transactions_1.standardPrincipalCV(newOwnerAddress)) : transactions_1.noneCV(), | ||
zonefile ? transactions_1.someCV(transactions_1.bufferCV(utils_1.getZonefileHash(zonefile))) : transactions_1.noneCV(), | ||
]; | ||
if (newOwnerAddress) { | ||
functionArgs.push(utils_1.bufferCVFromString(newOwnerAddress)); | ||
} | ||
if (zonefile) { | ||
const zonefileHash = utils_1.getZonefileHash(zonefile); | ||
functionArgs.push(transactions_1.bufferCV(zonefileHash)); | ||
} | ||
const burnSTXPostCondition = transactions_1.createSTXPostCondition(transactions_1.publicKeyToAddress(getAddressVersion(network), transactions_1.createStacksPublicKey(publicKey)), transactions_1.FungibleConditionCode.Equal, stxToBurn); | ||
return makeBnsContractCall({ | ||
@@ -315,2 +328,3 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? common_1.Buffer.from(zonefile) : undefined, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -317,0 +331,0 @@ } |
{ | ||
"name": "@stacks/bns", | ||
"version": "2.0.0-beta.1", | ||
"version": "2.0.1-beta.1", | ||
"description": "Library for working with the Stacks Blockchain Naming System BNS.", | ||
@@ -41,5 +41,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@stacks/common": "^2.0.0-beta.0", | ||
"@stacks/common": "^2.0.1-beta.1", | ||
"@stacks/network": "^1.2.2", | ||
"@stacks/transactions": "^2.0.0-beta.1", | ||
"@stacks/transactions": "^2.0.1-beta.1", | ||
"@types/bn.js": "^4.11.6", | ||
@@ -66,3 +66,3 @@ "bn.js": "^4.12.0" | ||
"unpkg": "dist/index.umd.js", | ||
"gitHead": "49425044179afac8fbedda2d57fe081950580bbd" | ||
"gitHead": "06c038827d29651628706474b2207ebe4f5859d9" | ||
} |
236
src/index.ts
@@ -1,2 +0,2 @@ | ||
import { Buffer } from '@stacks/common'; | ||
import { Buffer, IntegerType } from '@stacks/common'; | ||
import { | ||
@@ -18,3 +18,16 @@ AnchorMode, | ||
standardPrincipalCV, | ||
uintCV, | ||
someCV, | ||
noneCV, | ||
UnsignedContractCallOptions, | ||
PostCondition, | ||
createSTXPostCondition, | ||
createStacksPublicKey, | ||
publicKeyToAddress, | ||
FungibleConditionCode, | ||
AddressVersion, | ||
createNonFungiblePostCondition, | ||
NonFungibleConditionCode, | ||
parseAssetInfoString, | ||
tupleCV, | ||
} from '@stacks/transactions'; | ||
@@ -24,6 +37,4 @@ | ||
import { bufferCVFromString, decodeFQN, getZonefileHash, uintCVFromBN } from './utils'; | ||
import { bufferCVFromString, decodeFQN, getZonefileHash } from './utils'; | ||
import BN from 'bn.js'; | ||
import { ChainID } from '@stacks/common'; | ||
@@ -44,23 +55,29 @@ | ||
function getAddressVersion(network: StacksNetwork) { | ||
return network.chainId === ChainID.Mainnet | ||
? AddressVersion.MainnetSingleSig | ||
: AddressVersion.TestnetSingleSig; | ||
} | ||
export interface PriceFunction { | ||
base: BN; | ||
coefficient: BN; | ||
b1: BN; | ||
b2: BN; | ||
b3: BN; | ||
b4: BN; | ||
b5: BN; | ||
b6: BN; | ||
b7: BN; | ||
b8: BN; | ||
b9: BN; | ||
b10: BN; | ||
b11: BN; | ||
b12: BN; | ||
b13: BN; | ||
b14: BN; | ||
b15: BN; | ||
b16: BN; | ||
nonAlphaDiscount: BN; | ||
noVowelDiscount: BN; | ||
base: IntegerType; | ||
coefficient: IntegerType; | ||
b1: IntegerType; | ||
b2: IntegerType; | ||
b3: IntegerType; | ||
b4: IntegerType; | ||
b5: IntegerType; | ||
b6: IntegerType; | ||
b7: IntegerType; | ||
b8: IntegerType; | ||
b9: IntegerType; | ||
b10: IntegerType; | ||
b11: IntegerType; | ||
b12: IntegerType; | ||
b13: IntegerType; | ||
b14: IntegerType; | ||
b15: IntegerType; | ||
b16: IntegerType; | ||
nonAlphaDiscount: IntegerType; | ||
noVowelDiscount: IntegerType; | ||
} | ||
@@ -74,2 +91,3 @@ | ||
attachment?: Buffer; | ||
postConditions?: PostCondition[]; | ||
} | ||
@@ -87,2 +105,3 @@ | ||
anchorMode: AnchorMode.Any, | ||
postConditions: options.postConditions, | ||
}; | ||
@@ -182,3 +201,3 @@ | ||
network, | ||
}: GetNamespacePriceOptions): Promise<BN> { | ||
}: GetNamespacePriceOptions): Promise<bigint> { | ||
const bnsFunctionName = 'get-namespace-price'; | ||
@@ -234,3 +253,3 @@ | ||
network, | ||
}: GetNamePriceOptions): Promise<BN> { | ||
}: GetNamePriceOptions): Promise<bigint> { | ||
const bnsFunctionName = 'get-name-price'; | ||
@@ -269,14 +288,13 @@ const { subdomain, namespace, name } = decodeFQN(fullyQualifiedName); | ||
* Preorder namespace options | ||
* | ||
* @param {String} namespace - the namespace to preorder | ||
* @param {String} salt - salt used to generate the preorder namespace hash | ||
* @param {BN} stxToBurn - amount of STX to burn for the registration | ||
* @param {String} publicKey - the private key to sign the transaction | ||
* @param {StacksNetwork} network - the Stacks blockchain network to use | ||
*/ | ||
export interface PreorderNamespaceOptions { | ||
/** the namespace to preorder */ | ||
namespace: string; | ||
/** salt used to generate the preorder namespace hash */ | ||
salt: string; | ||
stxToBurn: BN; | ||
/** amount of STX to burn for the registration */ | ||
stxToBurn: IntegerType; | ||
/** the private key to sign the transaction */ | ||
publicKey: string; | ||
/** the Stacks blockchain network to use */ | ||
network: StacksNetwork; | ||
@@ -307,7 +325,14 @@ } | ||
const burnSTXPostCondition = createSTXPostCondition( | ||
publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), | ||
FungibleConditionCode.Equal, | ||
stxToBurn | ||
); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [bufferCV(hashedSaltedNamespace), uintCVFromBN(stxToBurn)], | ||
functionArgs: [bufferCV(hashedSaltedNamespace), uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -318,18 +343,17 @@ } | ||
* Reveal namespace options | ||
* | ||
* @param {String} namespace - the namespace to reveal | ||
* @param {String} salt - salt used to generate the preorder namespace hash | ||
* @param {PriceFunction} priceFunction - an object containing the price function for the namespace | ||
* @param {BN} lifeTime - the number of blocks name registrations are valid for in the namespace | ||
* @param {String} namespaceImportAddress - the STX address used for name imports | ||
* @param {String} publicKey - the private key to sign the transaction | ||
* @param {StacksNetwork} network - the Stacks blockchain network to use | ||
*/ | ||
export interface RevealNamespaceOptions { | ||
/** the namespace to reveal */ | ||
namespace: string; | ||
/** salt used to generate the preorder namespace hash */ | ||
salt: string; | ||
/** an object containing the price function for the namespace */ | ||
priceFunction: PriceFunction; | ||
lifetime: BN; | ||
/** the number of blocks name registrations are valid for in the namespace */ | ||
lifetime: IntegerType; | ||
/** the STX address used for name imports */ | ||
namespaceImportAddress: string; | ||
/** the key to sign the transaction */ | ||
publicKey: string; | ||
/** the Stacks blockchain network to use */ | ||
network: StacksNetwork; | ||
@@ -364,23 +388,23 @@ } | ||
bufferCVFromString(salt), | ||
uintCVFromBN(priceFunction.base), | ||
uintCVFromBN(priceFunction.coefficient), | ||
uintCVFromBN(priceFunction.b1), | ||
uintCVFromBN(priceFunction.b2), | ||
uintCVFromBN(priceFunction.b3), | ||
uintCVFromBN(priceFunction.b4), | ||
uintCVFromBN(priceFunction.b5), | ||
uintCVFromBN(priceFunction.b6), | ||
uintCVFromBN(priceFunction.b7), | ||
uintCVFromBN(priceFunction.b8), | ||
uintCVFromBN(priceFunction.b9), | ||
uintCVFromBN(priceFunction.b10), | ||
uintCVFromBN(priceFunction.b11), | ||
uintCVFromBN(priceFunction.b12), | ||
uintCVFromBN(priceFunction.b13), | ||
uintCVFromBN(priceFunction.b14), | ||
uintCVFromBN(priceFunction.b15), | ||
uintCVFromBN(priceFunction.b16), | ||
uintCVFromBN(priceFunction.nonAlphaDiscount), | ||
uintCVFromBN(priceFunction.noVowelDiscount), | ||
uintCVFromBN(lifetime), | ||
uintCV(priceFunction.base), | ||
uintCV(priceFunction.coefficient), | ||
uintCV(priceFunction.b1), | ||
uintCV(priceFunction.b2), | ||
uintCV(priceFunction.b3), | ||
uintCV(priceFunction.b4), | ||
uintCV(priceFunction.b5), | ||
uintCV(priceFunction.b6), | ||
uintCV(priceFunction.b7), | ||
uintCV(priceFunction.b8), | ||
uintCV(priceFunction.b9), | ||
uintCV(priceFunction.b10), | ||
uintCV(priceFunction.b11), | ||
uintCV(priceFunction.b12), | ||
uintCV(priceFunction.b13), | ||
uintCV(priceFunction.b14), | ||
uintCV(priceFunction.b15), | ||
uintCV(priceFunction.b16), | ||
uintCV(priceFunction.nonAlphaDiscount), | ||
uintCV(priceFunction.noVowelDiscount), | ||
uintCV(lifetime), | ||
standardPrincipalCV(namespaceImportAddress), | ||
@@ -488,15 +512,13 @@ ], | ||
* Preorder name options | ||
* | ||
* @param {String} fullyQualifiedName - the fully qualified name to preorder including the | ||
* namespace (myName.id) | ||
* @param {String} salt - salt used to generate the preorder name hash | ||
* @param {BN} stxToBurn - amount of STX to burn for the registration | ||
* @param {String} publicKey - the private key to sign the transaction | ||
* @param {StacksNetwork} network - the Stacks blockchain network to use | ||
*/ | ||
export interface PreorderNameOptions { | ||
/** the fully qualified name to preorder including the namespace (myName.id) */ | ||
fullyQualifiedName: string; | ||
/** salt used to generate the preorder name hash */ | ||
salt: string; | ||
stxToBurn: BN; | ||
/** amount of STX to burn for the registration */ | ||
stxToBurn: IntegerType; | ||
/** the private key to sign the transaction */ | ||
publicKey: string; | ||
/** the Stacks blockchain network to use */ | ||
network: StacksNetwork; | ||
@@ -531,7 +553,14 @@ } | ||
const burnSTXPostCondition = createSTXPostCondition( | ||
publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), | ||
FungibleConditionCode.Equal, | ||
stxToBurn | ||
); | ||
return makeBnsContractCall({ | ||
functionName: bnsFunctionName, | ||
functionArgs: [bufferCV(hashedSaltedName), uintCVFromBN(stxToBurn)], | ||
functionArgs: [bufferCV(hashedSaltedName), uintCV(stxToBurn)], | ||
publicKey, | ||
network, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
@@ -693,9 +722,24 @@ } | ||
bufferCVFromString(name), | ||
bufferCVFromString(newOwnerAddress), | ||
standardPrincipalCV(newOwnerAddress), | ||
zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), | ||
]; | ||
const postConditionSender = createNonFungiblePostCondition( | ||
publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), | ||
NonFungibleConditionCode.DoesNotOwn, | ||
parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), | ||
tupleCV({ | ||
name: bufferCVFromString(name), | ||
namespace: bufferCVFromString(namespace), | ||
}) | ||
); | ||
const postConditionReceiver = createNonFungiblePostCondition( | ||
newOwnerAddress, | ||
NonFungibleConditionCode.Owns, | ||
parseAssetInfoString(`${getBnsContractAddress(network)}.bns::names`), | ||
tupleCV({ | ||
name: bufferCVFromString(name), | ||
namespace: bufferCVFromString(namespace), | ||
}) | ||
); | ||
if (zonefile) { | ||
functionArgs.push(bufferCV(getZonefileHash(zonefile))); | ||
} | ||
return makeBnsContractCall({ | ||
@@ -707,2 +751,3 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? Buffer.from(zonefile) : undefined, | ||
postConditions: [postConditionSender, postConditionReceiver], | ||
}); | ||
@@ -756,17 +801,15 @@ } | ||
* Renew name options | ||
* | ||
* @param {String} fullyQualifiedName - the fully qualified name to renew including the | ||
* namespace (myName.id) | ||
* @param {BN} stxToBurn - amount of STX to burn for the registration | ||
* @param {String} publicKey - the private key to sign the transaction | ||
* @param {String} newOwnerAddress - optionally choose a new owner address | ||
* @param {String} zonefileHash - optionally update the zonefile hash | ||
* @param {StacksNetwork} network - the Stacks blockchain network to use | ||
*/ | ||
export interface RenewNameOptions { | ||
/** the fully qualified name to renew including the namespace (myName.id) */ | ||
fullyQualifiedName: string; | ||
stxToBurn: BN; | ||
/** amount of STX to burn for the registration */ | ||
stxToBurn: IntegerType; | ||
/** the private key to sign the transaction */ | ||
publicKey: string; | ||
/** the Stacks blockchain network to use */ | ||
network: StacksNetwork; | ||
/** optionally choose a new owner address */ | ||
newOwnerAddress?: string; | ||
/** optionally update the zonefile hash */ | ||
zonefile?: string; | ||
@@ -802,14 +845,12 @@ } | ||
bufferCVFromString(name), | ||
uintCVFromBN(stxToBurn), | ||
uintCV(stxToBurn), | ||
newOwnerAddress ? someCV(standardPrincipalCV(newOwnerAddress)) : noneCV(), | ||
zonefile ? someCV(bufferCV(getZonefileHash(zonefile))) : noneCV(), | ||
]; | ||
const burnSTXPostCondition = createSTXPostCondition( | ||
publicKeyToAddress(getAddressVersion(network), createStacksPublicKey(publicKey)), | ||
FungibleConditionCode.Equal, | ||
stxToBurn | ||
); | ||
if (newOwnerAddress) { | ||
functionArgs.push(bufferCVFromString(newOwnerAddress)); | ||
} | ||
if (zonefile) { | ||
const zonefileHash = getZonefileHash(zonefile); | ||
functionArgs.push(bufferCV(zonefileHash)); | ||
} | ||
return makeBnsContractCall({ | ||
@@ -821,3 +862,4 @@ functionName: bnsFunctionName, | ||
attachment: zonefile ? Buffer.from(zonefile) : undefined, | ||
postConditions: [burnSTXPostCondition], | ||
}); | ||
} |
@@ -6,5 +6,3 @@ import { Buffer } from '@stacks/common'; | ||
export function decodeFQN( | ||
fqdn: string | ||
): { | ||
export function decodeFQN(fqdn: string): { | ||
name: string; | ||
@@ -11,0 +9,0 @@ namespace: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
98455
1807