本文整理汇总了TypeScript中tape-promise/tape.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: runUtilsTests
export function runUtilsTests() {
test('makeECPrivateKey', (t) => {
t.plan(5)
const entropy = getEntropy(32)
t.ok(entropy, 'Entropy should have been created')
const privateKey = makeECPrivateKey()
t.ok(privateKey, 'Private key should have been created')
t.equal(typeof privateKey, 'string', 'Private key should be a string')
const publicKey = SECP256K1Client.derivePublicKey(privateKey)
const address = publicKeyToAddress(publicKey)
t.ok(address, 'Address should have been created')
t.equal(typeof address, 'string', 'Address should be a string')
})
test('ecPairToHexString', (t) => {
t.plan(2)
const privateKey = '00cdce6b5f87d38f2a830cae0da82162e1b487f07c5affa8130f01fe1a2a25fb01'
const expectedAddress = '1WykMawQRnLh7SWmmoRL4qTDNCgAsVRF1'
const computedECPair = hexStringToECPair(privateKey)
t.equal(privateKey, ecPairToHexString(computedECPair), 'Should return same hex string')
t.equal(expectedAddress, ecPairToAddress(computedECPair), 'Should parse to correct address')
})
test('isLaterVersion', (t) => {
t.plan(4)
t.false(isLaterVersion(undefined, '1.1.0'), 'undefined version is not later than 1.1.0')
t.true(isLaterVersion('1.2.0', '1.1.0'), '1.2.0 version is later than 1.1.0')
t.true(isLaterVersion('1.1.0', '1.1.0'), '1.1.0 version is later than 1.1.0')
t.false(isLaterVersion('1.1.0', '1.2.0'), '1.1.0 version is later than 1.2.0')
})
test('isSameOriginAbsoluteUrl', (t) => {
t.plan(12)
t.true(isSameOriginAbsoluteUrl('http://example.com', 'http://example.com/'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('https://example.com', 'https://example.com/'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('http://example.com', 'http://example.com/manifest.json'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('https://example.com', 'https://example.com/manifest.json'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('http://localhost:3000', 'http://localhost:3000/manifest.json'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('http://app.example.com', 'http://app.example.com/manifest.json'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('http://app.example.com:80', 'http://app.example.com/manifest.json'), 'should be same origin')
t.true(isSameOriginAbsoluteUrl('https://app.example.com:80', 'https://app.example.com:80/manifest.json'), 'should be same origin')
t.false(isSameOriginAbsoluteUrl('http://example.com', 'https://example.com/'), 'should not be same origin')
t.false(isSameOriginAbsoluteUrl('http://example.com', 'http://example.com:1234'), 'should not be same origin')
t.false(isSameOriginAbsoluteUrl('http://app.example.com', 'https://example.com/manifest.json'), 'should not be same origin')
t.false(isSameOriginAbsoluteUrl('http://app.example.com', '/manifest.json'), 'should not be same origin')
})
}
示例2: runProofStatementUnitTests
export function runProofStatementUnitTests() {
test('getProofStatement', (t) => {
t.plan(6)
const larry = sampleVerifications.larry
const naval = sampleVerifications.naval
const ken = sampleAddressBasedVerifications.ken
const oscar = sampleAddressBasedVerifications.oscar
t.equal(profileServices.facebook.getProofStatement(larry.facebook.body),
'Verifying that "larry.id" is my Blockstack ID.',
'Should extract proof statement from Facebook page meta tags')
t.equal(profileServices.twitter.getProofStatement(naval.twitter.body),
'Verifying myself: My Bitcoin username is +naval. https://t.co/DdpZv8tMAH #bitcoin',
'Should extract proof statement from Twitter page meta tags')
t.equal(profileServices.twitter.getProofStatement(ken.twitter.body),
'Verifying my Blockstack ID is secured with the address 1AtFqXxcckuoEN4iMNNe7n83c5nugxpzb5',
'Should extract address-based proof statement from Twitter page meta tags')
t.equal(profileServices.instagram.getProofStatement(ken.instagram.body),
'Verifying my Blockstack ID is secured with the address 1AtFqXxcckuoEN4iMNNe7n83c5nugxpzb5',
'Should extract address-based proof statement from Instagram meta tags')
t.equal(profileServices.hackerNews.getProofStatement(ken.hackerNews.body),
'Verifying my Blockstack ID is secured with the address 1AtFqXxcckuoEN4iMNNe7n83c5nugxpzb5',
'Should extract address-based proof statement from Hacker News profile')
t.equal(profileServices.linkedIn.getProofStatement(oscar.linkedIn.body),
'Oscar Lafarga on LinkedIn: "Verifying my Blockstack ID is secured with the address 1JbfoCkyyg2yn98jZ9A2HzGPzhHoc34WB7 https://lnkd.in/gM-KvXa"',
'Should extract address-based proof statement from LinkedIn meta tags')
})
}
示例3: runProofUtilsUnitTests
export function runProofUtilsUnitTests() {
test('containsValidProofStatement', (t) => {
t.plan(9)
const naval = sampleVerifications.naval
t.equal(containsValidProofStatement(naval.facebook.body, 'naval.id'),
true, 'Facebook post body should contain valid proof statement for naval.id')
t.equal(containsValidProofStatement(naval.github.body, 'naval.id'),
true, 'Github gist post body should contain valid proof statement for naval.id')
t.equal(containsValidProofStatement(naval.twitter.body, 'naval.id'),
true, 'Twitter post body should contain valid proof statement for naval.id')
const larry = sampleVerifications.larry
t.equal(containsValidProofStatement(naval.facebook.body, 'larry.id'),
false, 'Github gist post body should not contain valid proof statement for larry.id')
t.equal(containsValidProofStatement(naval.github.body, 'larry.id'),
false, 'Github gist post body should not contain valid proof statement for larry.id')
t.equal(containsValidProofStatement(naval.twitter.body, 'larry.id'),
false, 'Github gist post body should not contain valid proof statement for larry.id')
t.equal(containsValidProofStatement(larry.facebook.body, 'larry.id'),
true, 'Facebook post body should contain valid proof statement for larry.id')
const subdomainId = 'subdomainiac.id.blockstack'
t.equal(containsValidProofStatement(
`verifying that ${subdomainId} is my blockstack id`,
subdomainId
), true, 'Subdomain IDs work as proofs')
t.throws(() => {
containsValidProofStatement(larry.facebook.body, 'larry')
}, /Error/, 'Using non-fully qualified blockstack name should throw exception')
})
}
示例4: testProofChecker
export function testProofChecker() {
test('proof checker validation', async (t) => {
// This profile has 6 social proofs setup.
// At least 1 should be valid despite bugs in blockstack.js
// social website DOM parsing or whatever else going wrong.
const address = '1Nw25PemCRv24UQAcZdaj4uD11nkTCWRTE'
const filename = 'somefile'
const readURL = 'https://gaia.blockstack.org/hub/'
const proofChecker = new ProofChecker({ proofsRequired: 1 })
const isValid = await proofChecker.checkProofs(address, filename, readURL)
t.ok(isValid, 'proof checker should have at least 1 validation')
})
test('proof checker not enough proofs', async (t) => {
// This profile has no social proofs setup.
const address = '1HiCJwWuAzUxU93anq5XyBUcoWFPHMQugR'
const filename = 'somefile'
const readURL = 'https://gaia.blockstack.org/hub/'
const proofChecker = new ProofChecker({ proofsRequired: 1 })
try {
await proofChecker.checkProofs(address, filename, readURL)
t.fail('profile with no social proofs setup should fail validation')
} catch (error) {
t.equal(error.name, "NotEnoughProofError", "should have NotEnoughProofError")
t.equal(error.message, "Not enough social proofs for gaia hub writes", "should have correct error message")
}
})
test('proof checker unreachable read url', async (t) => {
const address = '1Nw25PemCRv24UQAcZdaj4uD11nkTCWRTE'
const filename = 'somefile'
const readURL = 'https://not.here.local/hub/'
const proofChecker = new ProofChecker({ proofsRequired: 1 })
try {
await proofChecker.checkProofs(address, filename, readURL)
t.fail('profile with no social proofs setup should fail validation')
} catch (error) {
t.equal(error.name, "NotEnoughProofError", "should have NotEnoughProofError")
t.equal(error.message, "Error fetching and verifying social proofs", "should have correct error message")
}
})
}
示例5: testHttpDriverOption
function testHttpDriverOption() {
test('makeHttpServer "driver" config', (t) => {
makeHttpServer({
driver: 'disk',
readURL: 'test/',
serverName: TEST_SERVER_NAME,
authTimestampCacheSize: TEST_AUTH_CACHE_SIZE,
diskSettings: {
storageRootDirectory: os.tmpdir()
}
} as HubConfigInterface & DISK_CONFIG_TYPE)
t.end()
})
test('makeHttpServer "driverInstance" config', (t) => {
const driver = new DiskDriver({
readURL: 'test/',
diskSettings: {
storageRootDirectory: os.tmpdir()
}
})
makeHttpServer({
driverInstance: driver,
serverName: TEST_SERVER_NAME,
authTimestampCacheSize: TEST_AUTH_CACHE_SIZE
})
t.end()
})
test('makeHttpServer missing driver config', (t) => {
t.throws(() => makeHttpServer({
serverName: TEST_SERVER_NAME,
authTimestampCacheSize: TEST_AUTH_CACHE_SIZE}),
Error, 'Should fail to create http server when no driver config is specified')
t.end()
})
}
示例6: testProofs
function testProofs(profile, username, totalProofs) {
test(`Profiles ${username}`,
(t) => { // FetchMock.get('https://www.facebook.com/larry.salibra/posts/10100341028448093', 'hi')
mockRequests()
return validateProofs(profile, undefined, username).then((proofs) => {
t.ok(proofs, 'Proofs must have been created')
t.equal(proofs instanceof Array, true, 'Proofs should be an Array')
t.equal(proofs.length, totalProofs,
`Should have a proof for each of the ${totalProofs} claimed accounts`)
t.equal(proofs.filter(x => x.valid).length, totalProofs, 'Should all be valid claims')
FetchMock.restore()
})
})
}
示例7: runInBodyIdentityVerificationTests
export function runInBodyIdentityVerificationTests() {
test('getProofIdentity', (t) => {
t.plan(3)
const ken = sampleAddressBasedVerifications.ken
const oscar = sampleAddressBasedVerifications.oscar
t.equal(profileServices.instagram.getProofIdentity(ken.instagram.body),
'blckstcktest',
'Should extract social proof identity from Instagram proof page body')
t.equal(profileServices.instagram.getProofIdentity(ken.instagramRegression.body),
'blckstcktest',
'Should extract social proof identity from Instagram proof page body')
t.equal(profileServices.linkedIn.getProofIdentity(oscar.linkedIn.body),
'oscarlafarga',
'Should extract social proof identity from LinkedIn proof page body')
})
}
示例8: brokenProofs
function brokenProofs() {
const naval = sampleVerifications.naval
// adding a 'b' to the url, so they don't overlap with other mocked fetches.
const navalAccounts = [{
'@type': 'Account',
service: 'facebook',
identifier: 'navalr',
proofType: 'http',
proofUrl: 'https://facebook.com/navalr/posts/10152190734077261b'
},
{
'@type': 'Account',
service: 'twitter',
identifier: 'naval',
proofType: 'http',
proofUrl: 'https://twitter.com/naval/status/486609266212499456b'
},
{
'@type': 'Account',
service: 'github',
identifier: 'navalr',
proofType: 'http',
proofUrl: 'https://gist.github.com/navalr/f31a74054f859ec0ac6ab'
}]
test('brokenProofs', (t) => {
FetchMock.get(`${naval.facebook.url}b`, naval.facebook.body)
FetchMock.get(`${naval.github.url}b/raw`, naval.github.body)
FetchMock.get(`${naval.twitter.url}b`, { body: '', status: 400 })
t.plan(2)
validateProofs({ account: navalAccounts }, undefined, 'naval.id')
.then((proofs) => {
t.equal(proofs.length, 3)
t.equal(proofs.filter(x => x.valid).length, 2)
FetchMock.restore()
})
})
}
示例9: test
.forEach((wallet) => {
test('wallet matches browser 0.26.2 implementation', (t) => {
t.plan(6)
t.equals(wallet.getIdentityPublicKeychain().toBase58(), identityXPUB, 'id xpub is correct')
t.equals(wallet.getBitcoinPublicKeychain().toBase58(), bitcoinXPUB, 'btc xpub is correct')
t.equals(wallet.getBitcoinAddress(0), bitcoinAddress, 'btc address correct')
t.deepEquals(
[0, 1, 2, 3].map(index => wallet.getIdentityKeyPair(index, true)),
identityKeyPairs, 'keypairs generated correctly'
)
const idKeyPair = wallet.getIdentityKeyPair(0, false)
t.equals(BlockstackWallet.getLegacyAppPrivateKey(idKeyPair.appsNodeKey,
idKeyPair.salt,
'https://blockstack-todos.appartisan.com'),
expectedLegacyAppSK,
'blockstack-todos app legacy private key correct')
t.equals(BlockstackWallet.getAppPrivateKey(idKeyPair.appsNodeKey,
'potato potato',
'carrot carrot carrot'),
expectedNewAppSK,
'blockstack-todos app private key correct')
})
})
示例10: testAuth
export function testAuth() {
test('authentication legacy/regression', (t) => {
const legacyPart = {
wif: 'Kzp44Hhp6SFUXMuMi6MUDTqyfcNyyjntrphEHVMsiitRrjMyoV4p',
addr: '1AotVNASQouiNiBtfxv49WWvSNcQUzGYuU',
serverName: 'storage.blockstack.org',
legacyAuth: 'eyJwdWJsaWNrZXkiOiIwMjQxYTViMDQ2Mjg1ZjVlMjgwMDRmOTJjY2M0MjNmY2RkODYyZmYzY' +
'jgwODUwNzE4MDY4MGIyNDA3ZTIyOWE3NzgiLCJzaWduYXR1cmUiOiIzMDQ0MDIyMDY5ODUwNmNjYjg3MDg1Zm' +
'Y5ZGI3ZTc4MTIwYTVmMjY1YzExZmY0ODc4OTBlNDQ1MWZjYWM3NjA4NTkyMDhjZWMwMjIwNTZkY2I0OGUyYzE' +
'4Y2YwZjQ1NDZiMmQ3M2I2MDY4MWM5ODEyMzQyMmIzOTRlZjRkMWI2MjE3NTYyODQ4MzUwNCJ9' }
t.doesNotThrow(() => auth.validateAuthorizationHeader(`bearer ${legacyPart.legacyAuth}`,
legacyPart.serverName,
legacyPart.addr),
'legacy authentication token should work')
t.end()
})
test('authentication legacy/regression with multi-case bearer', (t) => {
const legacyPart = {
wif: 'Kzp44Hhp6SFUXMuMi6MUDTqyfcNyyjntrphEHVMsiitRrjMyoV4p',
addr: '1AotVNASQouiNiBtfxv49WWvSNcQUzGYuU',
serverName: 'storage.blockstack.org',
legacyAuth: 'eyJwdWJsaWNrZXkiOiIwMjQxYTViMDQ2Mjg1ZjVlMjgwMDRmOTJjY2M0MjNmY2RkODYyZmYzY' +
'jgwODUwNzE4MDY4MGIyNDA3ZTIyOWE3NzgiLCJzaWduYXR1cmUiOiIzMDQ0MDIyMDY5ODUwNmNjYjg3MDg1Zm' +
'Y5ZGI3ZTc4MTIwYTVmMjY1YzExZmY0ODc4OTBlNDQ1MWZjYWM3NjA4NTkyMDhjZWMwMjIwNTZkY2I0OGUyYzE' +
'4Y2YwZjQ1NDZiMmQ3M2I2MDY4MWM5ODEyMzQyMmIzOTRlZjRkMWI2MjE3NTYyODQ4MzUwNCJ9' }
t.doesNotThrow(() => auth.validateAuthorizationHeader(`BeArEr ${legacyPart.legacyAuth}`,
legacyPart.serverName,
legacyPart.addr),
'legacy authentication token should work')
t.end()
})
test('storage validation', (t) => {
const challengeText = auth.getChallengeText()
const authPart = auth.LegacyAuthentication.makeAuthPart(testPairs[0], challengeText)
const authorization = `bearer ${authPart}`
const authenticator = auth.parseAuthHeader(authorization)
t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),
errors.ValidationError, 'Wrong address must throw')
t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos']),
errors.ValidationError, 'Wrong challenge text must throw')
t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),
'Good signature must pass')
t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),
'Bad signature must throw')
t.end()
})
test('v1 storage validation', (t) => {
const challengeText = 'bananas are tasty'
const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText)
console.log(`V1 storage validation: ${authPart}`)
const authorization = `bearer ${authPart}`
const authenticator = auth.parseAuthHeader(authorization)
t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),
errors.ValidationError, 'Wrong address must throw')
t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),
errors.ValidationError, 'Wrong challenge text must throw')
t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),
'Good signature must pass')
// signer address was from the v1 token
t.equal(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]), testAddrs[0])
const signerKeyHex = testPairs[0].privateKey.toString('hex')
const tokenWithoutIssuer = new TokenSigner('ES256K', signerKeyHex).sign(
{ garbage: 'in' })
const goodTokenWithoutExp = new TokenSigner('ES256K', signerKeyHex).sign(
{ gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex') })
const expiredToken = new TokenSigner('ES256K', signerKeyHex).sign(
{ gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex'), exp: 1 })
const wrongIssuerToken = new TokenSigner('ES256K', signerKeyHex).sign(
{ gaiaChallenge: challengeText, iss: testPairs[1].publicKey.toString('hex'), exp: 1 })
t.throws(() => new auth.V1Authentication(tokenWithoutIssuer).isAuthenticationValid(testAddrs[0], [challengeText]),
errors.ValidationError, 'No `iss`, should fail')
t.throws(() => new auth.V1Authentication(expiredToken).isAuthenticationValid(testAddrs[0], [challengeText]),
errors.ValidationError, 'Expired token should fail')
t.throws(() => new auth.V1Authentication(wrongIssuerToken).isAuthenticationValid(testAddrs[1], [challengeText]),
errors.ValidationError, 'Invalid signature')
t.ok(new auth.V1Authentication(goodTokenWithoutExp).isAuthenticationValid(testAddrs[0], [challengeText]),
'Valid token without expiration should pass')
t.end()
})
test('v1 storage validation with hubUrls required', (t) => {
const challengeText = 'bananas are tasty'
const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText)
console.log(`V1 storage validation: ${authPart}`)
const authorization = `bearer ${authPart}`
const authenticator = auth.parseAuthHeader(authorization)
t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),
errors.ValidationError, 'Wrong address must throw')
t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),
errors.ValidationError, 'Wrong challenge text must throw')
t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),
'Good signature must pass')
//.........这里部分代码省略.........