@bsv/sdk 1.6.8 → 1.6.10
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/README.md +9 -4
- package/dist/cjs/package.json +7 -5
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +11 -3
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/utils/toOriginHeader.js +21 -0
- package/dist/cjs/src/wallet/substrates/utils/toOriginHeader.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +9 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/esm/src/wallet/substrates/utils/toOriginHeader.js +17 -0
- package/dist/esm/src/wallet/substrates/utils/toOriginHeader.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/utils/toOriginHeader.d.ts +2 -0
- package/dist/types/src/wallet/substrates/utils/toOriginHeader.d.ts.map +1 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/concepts/beef.md +84 -0
- package/docs/concepts/chain-tracking.md +122 -0
- package/docs/concepts/decentralized-identity.md +184 -0
- package/docs/concepts/fees.md +217 -0
- package/docs/concepts/identity-certificates.md +255 -0
- package/docs/concepts/index.md +62 -0
- package/docs/concepts/key-management.md +176 -0
- package/docs/concepts/script-templates.md +163 -0
- package/docs/concepts/sdk-philosophy.md +72 -0
- package/docs/concepts/signatures.md +179 -0
- package/docs/concepts/spv-verification.md +106 -0
- package/docs/concepts/transaction-encoding.md +148 -0
- package/docs/concepts/transaction-structure.md +63 -0
- package/docs/concepts/trust-model.md +123 -0
- package/docs/concepts/verification.md +219 -0
- package/docs/concepts/wallet-integration.md +95 -0
- package/docs/guides/direct-transaction-creation.md +137 -0
- package/docs/guides/http-client-configuration.md +414 -0
- package/docs/guides/index.md +30 -0
- package/docs/guides/transaction-signing-methods.md +268 -0
- package/docs/index.md +74 -0
- package/docs/reference/arc-config.md +698 -0
- package/docs/reference/brc-100.md +33 -0
- package/docs/reference/configuration.md +829 -0
- package/docs/reference/debugging.md +700 -0
- package/docs/reference/errors.md +547 -0
- package/docs/reference/index.md +98 -0
- package/docs/reference/network-config.md +914 -0
- package/docs/reference/op-codes.md +306 -0
- package/docs/reference/transaction-signatures.md +94 -0
- package/docs/{wallet.md → reference/wallet.md} +9 -0
- package/docs/requirements.txt +3 -0
- package/docs/tutorials/advanced-transaction.md +575 -0
- package/docs/tutorials/aes-encryption.md +947 -0
- package/docs/tutorials/authfetch-tutorial.md +957 -0
- package/docs/tutorials/ecdh-key-exchange.md +547 -0
- package/docs/tutorials/elliptic-curve-fundamentals.md +603 -0
- package/docs/tutorials/error-handling.md +1215 -0
- package/docs/tutorials/first-transaction-low-level.md +204 -0
- package/docs/tutorials/first-transaction.md +278 -0
- package/docs/tutorials/hashes-and-hmacs.md +814 -0
- package/docs/tutorials/identity-management.md +702 -0
- package/docs/tutorials/index.md +182 -0
- package/docs/tutorials/key-management.md +536 -0
- package/docs/tutorials/protowallet-development.md +716 -0
- package/docs/tutorials/script-construction.md +690 -0
- package/docs/tutorials/spv-merkle-proofs.md +682 -0
- package/docs/tutorials/testnet-transactions-low-level.md +352 -0
- package/docs/tutorials/transaction-broadcasting.md +535 -0
- package/docs/tutorials/transaction-types.md +419 -0
- package/docs/tutorials/type-42.md +582 -0
- package/docs/tutorials/uhrp-storage.md +579 -0
- package/package.json +7 -5
- package/src/transaction/__tests/Transaction.test.ts +1 -1
- package/src/wallet/substrates/HTTPWalletJSON.ts +11 -1
- package/src/wallet/substrates/WalletWireProcessor.ts +1 -1
- package/src/wallet/substrates/__tests/toOriginHeader.test.ts +34 -0
- package/src/wallet/substrates/utils/toOriginHeader.ts +15 -0
- package/docs/README.md +0 -21
- /package/docs/{auth.md → reference/auth.md} +0 -0
- /package/docs/{compat.md → reference/compat.md} +0 -0
- /package/docs/{identity.md → reference/identity.md} +0 -0
- /package/docs/{kvstore.md → reference/kvstore.md} +0 -0
- /package/docs/{messages.md → reference/messages.md} +0 -0
- /package/docs/{overlay-tools.md → reference/overlay-tools.md} +0 -0
- /package/docs/{primitives.md → reference/primitives.md} +0 -0
- /package/docs/{registry.md → reference/registry.md} +0 -0
- /package/docs/{script.md → reference/script.md} +0 -0
- /package/docs/{storage.md → reference/storage.md} +0 -0
- /package/docs/{totp.md → reference/totp.md} +0 -0
- /package/docs/{transaction.md → reference/transaction.md} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toOriginHeader } from "../utils/toOriginHeader"
|
|
2
|
+
|
|
3
|
+
afterEach(() => jest.resetAllMocks())
|
|
4
|
+
|
|
5
|
+
type FetchMockCall = Parameters<typeof fetch> // alias for readability
|
|
6
|
+
|
|
7
|
+
function okJson(body: unknown = {}) {
|
|
8
|
+
return Promise.resolve({
|
|
9
|
+
ok: true,
|
|
10
|
+
status: 200,
|
|
11
|
+
json: () => Promise.resolve(body),
|
|
12
|
+
} as Response)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("toOriginHeader()", () => {
|
|
16
|
+
const vectors: Array<[originator: string, baseUrl: string, expected: string | undefined]> = [
|
|
17
|
+
/* originator, baseUrl, expected */
|
|
18
|
+
["localhost", "http://localhost:3321", "http://localhost"],
|
|
19
|
+
["localhost:3000", "http://localhost:3321", "http://localhost:3000"],
|
|
20
|
+
["example.com", "https://api.example.com", "https://example.com"],
|
|
21
|
+
["https://example.com:8443", "http://localhost:3321", "https://example.com:8443"],
|
|
22
|
+
// ["metanet://somehost", "http://localhost:3321", "metanet://somehost"], // TODO: Consider adding support in the future
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
it.each(vectors)("originator=%p, baseUrl=%p → %p", (originator, baseUrl, expected) => {
|
|
26
|
+
const schemeFromBase = new URL(baseUrl).protocol.replace(":", "")
|
|
27
|
+
const result = toOriginHeader(originator, schemeFromBase)
|
|
28
|
+
expect(result).toBe(expected)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it("throws on clearly malformed input", () => {
|
|
32
|
+
expect(() => toOriginHeader("bad url^%", "http")).toThrow()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function toOriginHeader(originator: string, fallbackScheme = 'http'): string | undefined {
|
|
2
|
+
// If the caller already gave us a scheme, assume it’s fine
|
|
3
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(originator)) {
|
|
4
|
+
try {
|
|
5
|
+
return new URL(originator).origin // trims any path/query
|
|
6
|
+
} catch { /* fall through to fix-up */ }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Otherwise, prepend the fallback scheme and validate
|
|
10
|
+
try {
|
|
11
|
+
return new URL(`${fallbackScheme}://${originator}`).origin
|
|
12
|
+
} catch {
|
|
13
|
+
throw new Error(`Invalid originator value: ${originator}`)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/docs/README.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# TypeScript Library API Documentation
|
|
2
|
-
|
|
3
|
-
The documentation is split into various pages, each covering a set of related functionality. The pages are as follows:
|
|
4
|
-
|
|
5
|
-
- [Primitives](./primitives.md) — Covers public and private keys, key derivation, digital signaturs, symmetric keys, and low-level operations
|
|
6
|
-
- [Script](./script.md) — Covers Bitcoin scripts, the templating system, serialization, and the Spend class (script interpreter)
|
|
7
|
-
- [Transaction](./transaction.md) — Covers transaction construction, signing, broadcasters, fee models, merkle proofs, and SPV structures like BUMP
|
|
8
|
-
- [Messages](./messages.md) — Covers generalizable message signing, verification, encryption and decryption
|
|
9
|
-
- [TOTP](./totp.md) - Covers Time-based One Time Password, useful for validating counterparties across unsecured mediums.
|
|
10
|
-
- [Wallet](./wallet.md) - Covers the Wallet interface for communication between applications and wallets using a standard interface.
|
|
11
|
-
- [Wallet Substrates](./wallet-substrates.md) - Covers the Wallet Substrates which facilitate communication between apps and wallets.
|
|
12
|
-
- [Overlay Tools](./overlay-tools.md) - Covers the use of Overlays for broadcast of transactions based on topics, as well as distributed lookup of tokens.
|
|
13
|
-
- [Auth](./auth.md) - Mutual Authentication and Service Monetization Framework
|
|
14
|
-
- [Storage](./storage.md) — Covers a UHRP client for storing and retrieving data from distributed data storage services by hash.
|
|
15
|
-
- [Compat](./compat.md) — Covers deprecated functionality for legacy systems like BIP32 and ECIES
|
|
16
|
-
|
|
17
|
-
## Swagger
|
|
18
|
-
|
|
19
|
-
[BRC-100](https://brc.dev/100) defines a Unified, Vendor-Neutral, Unchanging, and Open BSV Blockchain Standard Wallet-to-Application Interface which is implemented in this library within the WalletClient class. The API is laid out here as a swagger openapi document to offer a fast-track to understanding the interface which is implemented across multiple substrates. The JSON api is generally considered a developer friendly introduction to the WalletClient, where an binary equivalent ABI may be preferred for production use cases.
|
|
20
|
-
|
|
21
|
-
- [Wallet JSON API Swagger](./swagger)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|