@originals/sdk 1.4.2 → 1.4.5
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/adapters/FeeOracleMock.d.ts +6 -0
- package/dist/adapters/FeeOracleMock.js +8 -0
- package/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -1
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/providers/OrdHttpProvider.d.ts +56 -0
- package/dist/adapters/providers/OrdHttpProvider.js +110 -0
- package/dist/adapters/providers/OrdMockProvider.d.ts +70 -0
- package/dist/adapters/providers/OrdMockProvider.js +75 -0
- package/dist/adapters/types.d.ts +71 -0
- package/dist/adapters/types.js +1 -0
- package/dist/bitcoin/BitcoinManager.d.ts +15 -0
- package/dist/bitcoin/BitcoinManager.js +262 -0
- package/dist/bitcoin/BroadcastClient.d.ts +30 -0
- package/dist/bitcoin/BroadcastClient.js +35 -0
- package/dist/bitcoin/OrdinalsClient.d.ts +21 -0
- package/dist/bitcoin/OrdinalsClient.js +105 -0
- package/dist/bitcoin/PSBTBuilder.d.ts +24 -0
- package/dist/bitcoin/PSBTBuilder.js +80 -0
- package/dist/bitcoin/fee-calculation.d.ts +14 -0
- package/{src/bitcoin/fee-calculation.ts → dist/bitcoin/fee-calculation.js} +5 -12
- package/dist/bitcoin/providers/OrdNodeProvider.d.ts +38 -0
- package/dist/bitcoin/providers/OrdNodeProvider.js +67 -0
- package/dist/bitcoin/providers/OrdinalsProvider.d.ts +33 -0
- package/dist/bitcoin/providers/OrdinalsProvider.js +50 -0
- package/dist/bitcoin/providers/types.d.ts +63 -0
- package/dist/bitcoin/providers/types.js +1 -0
- package/dist/bitcoin/transactions/commit.d.ts +89 -0
- package/dist/bitcoin/transactions/commit.js +311 -0
- package/dist/bitcoin/transactions/index.d.ts +7 -0
- package/{src/bitcoin/transactions/index.ts → dist/bitcoin/transactions/index.js} +1 -6
- package/dist/bitcoin/transfer.d.ts +9 -0
- package/dist/bitcoin/transfer.js +26 -0
- package/dist/bitcoin/utxo-selection.d.ts +78 -0
- package/dist/bitcoin/utxo-selection.js +237 -0
- package/dist/bitcoin/utxo.d.ts +26 -0
- package/dist/bitcoin/utxo.js +78 -0
- package/dist/contexts/credentials-v1.json +195 -0
- package/dist/contexts/credentials-v2-examples.json +5 -0
- package/dist/contexts/credentials-v2.json +301 -0
- package/dist/contexts/credentials.json +195 -0
- package/dist/contexts/data-integrity-v2.json +81 -0
- package/dist/contexts/dids.json +57 -0
- package/dist/contexts/ed255192020.json +93 -0
- package/dist/contexts/ordinals-plus.json +23 -0
- package/dist/contexts/originals.json +22 -0
- package/dist/core/OriginalsSDK.d.ts +158 -0
- package/dist/core/OriginalsSDK.js +274 -0
- package/dist/crypto/Multikey.d.ts +30 -0
- package/dist/crypto/Multikey.js +149 -0
- package/dist/crypto/Signer.d.ts +21 -0
- package/dist/crypto/Signer.js +196 -0
- package/dist/crypto/noble-init.d.ts +18 -0
- package/dist/crypto/noble-init.js +106 -0
- package/dist/did/BtcoDidResolver.d.ts +57 -0
- package/dist/did/BtcoDidResolver.js +166 -0
- package/dist/did/DIDManager.d.ts +101 -0
- package/dist/did/DIDManager.js +493 -0
- package/dist/did/Ed25519Verifier.d.ts +30 -0
- package/dist/did/Ed25519Verifier.js +59 -0
- package/dist/did/KeyManager.d.ts +17 -0
- package/dist/did/KeyManager.js +207 -0
- package/dist/did/WebVHManager.d.ts +100 -0
- package/dist/did/WebVHManager.js +312 -0
- package/dist/did/createBtcoDidDocument.d.ts +10 -0
- package/dist/did/createBtcoDidDocument.js +42 -0
- package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +23 -0
- package/dist/did/providers/OrdinalsClientProviderAdapter.js +51 -0
- package/dist/events/EventEmitter.d.ts +115 -0
- package/dist/events/EventEmitter.js +198 -0
- package/dist/events/index.d.ts +7 -0
- package/dist/events/index.js +6 -0
- package/dist/events/types.d.ts +286 -0
- package/dist/events/types.js +9 -0
- package/dist/examples/basic-usage.d.ts +3 -0
- package/dist/examples/basic-usage.js +62 -0
- package/dist/examples/create-module-original.d.ts +32 -0
- package/dist/examples/create-module-original.js +376 -0
- package/dist/examples/full-lifecycle-flow.d.ts +56 -0
- package/dist/examples/full-lifecycle-flow.js +419 -0
- package/dist/examples/run.d.ts +12 -0
- package/dist/examples/run.js +51 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +52 -0
- package/dist/kinds/KindRegistry.d.ts +76 -0
- package/dist/kinds/KindRegistry.js +216 -0
- package/dist/kinds/index.d.ts +33 -0
- package/{src/kinds/index.ts → dist/kinds/index.js} +6 -44
- package/dist/kinds/types.d.ts +363 -0
- package/dist/kinds/types.js +25 -0
- package/dist/kinds/validators/AgentValidator.d.ts +14 -0
- package/dist/kinds/validators/AgentValidator.js +155 -0
- package/dist/kinds/validators/AppValidator.d.ts +14 -0
- package/dist/kinds/validators/AppValidator.js +135 -0
- package/dist/kinds/validators/DatasetValidator.d.ts +14 -0
- package/dist/kinds/validators/DatasetValidator.js +148 -0
- package/dist/kinds/validators/DocumentValidator.d.ts +14 -0
- package/dist/kinds/validators/DocumentValidator.js +180 -0
- package/dist/kinds/validators/MediaValidator.d.ts +14 -0
- package/dist/kinds/validators/MediaValidator.js +172 -0
- package/dist/kinds/validators/ModuleValidator.d.ts +14 -0
- package/dist/kinds/validators/ModuleValidator.js +140 -0
- package/dist/kinds/validators/base.d.ts +96 -0
- package/dist/kinds/validators/base.js +218 -0
- package/{src/kinds/validators/index.ts → dist/kinds/validators/index.d.ts} +0 -2
- package/dist/kinds/validators/index.js +10 -0
- package/dist/lifecycle/BatchOperations.d.ts +147 -0
- package/dist/lifecycle/BatchOperations.js +251 -0
- package/dist/lifecycle/LifecycleManager.d.ts +362 -0
- package/dist/lifecycle/LifecycleManager.js +1692 -0
- package/dist/lifecycle/OriginalsAsset.d.ts +164 -0
- package/dist/lifecycle/OriginalsAsset.js +380 -0
- package/dist/lifecycle/ProvenanceQuery.d.ts +126 -0
- package/dist/lifecycle/ProvenanceQuery.js +220 -0
- package/dist/lifecycle/ResourceVersioning.d.ts +73 -0
- package/dist/lifecycle/ResourceVersioning.js +127 -0
- package/dist/migration/MigrationManager.d.ts +86 -0
- package/dist/migration/MigrationManager.js +412 -0
- package/dist/migration/audit/AuditLogger.d.ts +51 -0
- package/dist/migration/audit/AuditLogger.js +156 -0
- package/dist/migration/checkpoint/CheckpointManager.d.ts +31 -0
- package/dist/migration/checkpoint/CheckpointManager.js +96 -0
- package/dist/migration/checkpoint/CheckpointStorage.d.ts +26 -0
- package/dist/migration/checkpoint/CheckpointStorage.js +89 -0
- package/dist/migration/index.d.ts +22 -0
- package/{src/migration/index.ts → dist/migration/index.js} +0 -6
- package/dist/migration/operations/BaseMigration.d.ts +48 -0
- package/dist/migration/operations/BaseMigration.js +83 -0
- package/dist/migration/operations/PeerToBtcoMigration.d.ts +25 -0
- package/dist/migration/operations/PeerToBtcoMigration.js +67 -0
- package/dist/migration/operations/PeerToWebvhMigration.d.ts +19 -0
- package/dist/migration/operations/PeerToWebvhMigration.js +46 -0
- package/dist/migration/operations/WebvhToBtcoMigration.d.ts +25 -0
- package/dist/migration/operations/WebvhToBtcoMigration.js +67 -0
- package/dist/migration/rollback/RollbackManager.d.ts +29 -0
- package/dist/migration/rollback/RollbackManager.js +146 -0
- package/dist/migration/state/StateMachine.d.ts +25 -0
- package/dist/migration/state/StateMachine.js +76 -0
- package/dist/migration/state/StateTracker.d.ts +36 -0
- package/dist/migration/state/StateTracker.js +123 -0
- package/dist/migration/types.d.ts +306 -0
- package/dist/migration/types.js +33 -0
- package/dist/migration/validation/BitcoinValidator.d.ts +13 -0
- package/dist/migration/validation/BitcoinValidator.js +83 -0
- package/dist/migration/validation/CredentialValidator.d.ts +13 -0
- package/dist/migration/validation/CredentialValidator.js +46 -0
- package/dist/migration/validation/DIDCompatibilityValidator.d.ts +16 -0
- package/dist/migration/validation/DIDCompatibilityValidator.js +127 -0
- package/dist/migration/validation/LifecycleValidator.d.ts +10 -0
- package/dist/migration/validation/LifecycleValidator.js +52 -0
- package/dist/migration/validation/StorageValidator.d.ts +10 -0
- package/dist/migration/validation/StorageValidator.js +65 -0
- package/dist/migration/validation/ValidationPipeline.d.ts +29 -0
- package/dist/migration/validation/ValidationPipeline.js +180 -0
- package/dist/resources/ResourceManager.d.ts +231 -0
- package/dist/resources/ResourceManager.js +573 -0
- package/{src/resources/index.ts → dist/resources/index.d.ts} +3 -13
- package/dist/resources/index.js +10 -0
- package/dist/resources/types.d.ts +93 -0
- package/dist/resources/types.js +80 -0
- package/dist/storage/LocalStorageAdapter.d.ts +11 -0
- package/dist/storage/LocalStorageAdapter.js +53 -0
- package/dist/storage/MemoryStorageAdapter.d.ts +6 -0
- package/dist/storage/MemoryStorageAdapter.js +21 -0
- package/dist/storage/StorageAdapter.d.ts +16 -0
- package/dist/storage/StorageAdapter.js +1 -0
- package/{src/storage/index.ts → dist/storage/index.d.ts} +0 -1
- package/dist/storage/index.js +2 -0
- package/dist/types/bitcoin.d.ts +84 -0
- package/dist/types/bitcoin.js +1 -0
- package/dist/types/common.d.ts +82 -0
- package/dist/types/common.js +1 -0
- package/dist/types/credentials.d.ts +75 -0
- package/dist/types/credentials.js +1 -0
- package/dist/types/did.d.ts +26 -0
- package/dist/types/did.js +1 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +0 -2
- package/dist/types/index.js +5 -0
- package/dist/types/network.d.ts +78 -0
- package/dist/types/network.js +145 -0
- package/dist/utils/EventLogger.d.ts +71 -0
- package/dist/utils/EventLogger.js +232 -0
- package/dist/utils/Logger.d.ts +106 -0
- package/dist/utils/Logger.js +257 -0
- package/dist/utils/MetricsCollector.d.ts +110 -0
- package/dist/utils/MetricsCollector.js +264 -0
- package/dist/utils/bitcoin-address.d.ts +38 -0
- package/dist/utils/bitcoin-address.js +113 -0
- package/dist/utils/cbor.d.ts +2 -0
- package/dist/utils/cbor.js +9 -0
- package/dist/utils/encoding.d.ts +37 -0
- package/dist/utils/encoding.js +120 -0
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +5 -0
- package/dist/utils/retry.d.ts +10 -0
- package/dist/utils/retry.js +35 -0
- package/dist/utils/satoshi-validation.d.ts +60 -0
- package/dist/utils/satoshi-validation.js +156 -0
- package/dist/utils/serialization.d.ts +14 -0
- package/dist/utils/serialization.js +76 -0
- package/dist/utils/telemetry.d.ts +17 -0
- package/dist/utils/telemetry.js +24 -0
- package/dist/utils/validation.d.ts +5 -0
- package/dist/utils/validation.js +98 -0
- package/dist/vc/CredentialManager.d.ts +329 -0
- package/dist/vc/CredentialManager.js +615 -0
- package/dist/vc/Issuer.d.ts +27 -0
- package/dist/vc/Issuer.js +70 -0
- package/dist/vc/Verifier.d.ts +16 -0
- package/dist/vc/Verifier.js +50 -0
- package/dist/vc/cryptosuites/bbs.d.ts +44 -0
- package/dist/vc/cryptosuites/bbs.js +213 -0
- package/dist/vc/cryptosuites/bbsSimple.d.ts +9 -0
- package/dist/vc/cryptosuites/bbsSimple.js +12 -0
- package/dist/vc/cryptosuites/eddsa.d.ts +30 -0
- package/dist/vc/cryptosuites/eddsa.js +81 -0
- package/dist/vc/documentLoader.d.ts +16 -0
- package/dist/vc/documentLoader.js +59 -0
- package/dist/vc/proofs/data-integrity.d.ts +21 -0
- package/dist/vc/proofs/data-integrity.js +15 -0
- package/dist/vc/utils/jsonld.d.ts +2 -0
- package/dist/vc/utils/jsonld.js +15 -0
- package/package.json +5 -1
- package/.eslintrc.json +0 -33
- package/src/adapters/FeeOracleMock.ts +0 -9
- package/src/adapters/providers/OrdHttpProvider.ts +0 -126
- package/src/adapters/providers/OrdMockProvider.ts +0 -101
- package/src/adapters/types.ts +0 -66
- package/src/bitcoin/BitcoinManager.ts +0 -330
- package/src/bitcoin/BroadcastClient.ts +0 -54
- package/src/bitcoin/OrdinalsClient.ts +0 -119
- package/src/bitcoin/PSBTBuilder.ts +0 -106
- package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
- package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
- package/src/bitcoin/providers/types.ts +0 -59
- package/src/bitcoin/transactions/commit.ts +0 -465
- package/src/bitcoin/transfer.ts +0 -43
- package/src/bitcoin/utxo-selection.ts +0 -322
- package/src/bitcoin/utxo.ts +0 -113
- package/src/contexts/credentials-v1.json +0 -237
- package/src/contexts/credentials-v2-examples.json +0 -5
- package/src/contexts/credentials-v2.json +0 -340
- package/src/contexts/credentials.json +0 -237
- package/src/contexts/data-integrity-v2.json +0 -81
- package/src/contexts/dids.json +0 -58
- package/src/contexts/ed255192020.json +0 -93
- package/src/contexts/ordinals-plus.json +0 -23
- package/src/contexts/originals.json +0 -22
- package/src/core/OriginalsSDK.ts +0 -416
- package/src/crypto/Multikey.ts +0 -194
- package/src/crypto/Signer.ts +0 -254
- package/src/crypto/noble-init.ts +0 -121
- package/src/did/BtcoDidResolver.ts +0 -227
- package/src/did/DIDManager.ts +0 -694
- package/src/did/Ed25519Verifier.ts +0 -68
- package/src/did/KeyManager.ts +0 -236
- package/src/did/WebVHManager.ts +0 -498
- package/src/did/createBtcoDidDocument.ts +0 -59
- package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
- package/src/events/EventEmitter.ts +0 -222
- package/src/events/index.ts +0 -19
- package/src/events/types.ts +0 -331
- package/src/examples/basic-usage.ts +0 -78
- package/src/examples/create-module-original.ts +0 -435
- package/src/examples/full-lifecycle-flow.ts +0 -514
- package/src/examples/run.ts +0 -60
- package/src/index.ts +0 -150
- package/src/kinds/KindRegistry.ts +0 -290
- package/src/kinds/types.ts +0 -470
- package/src/kinds/validators/AgentValidator.ts +0 -257
- package/src/kinds/validators/AppValidator.ts +0 -211
- package/src/kinds/validators/DatasetValidator.ts +0 -242
- package/src/kinds/validators/DocumentValidator.ts +0 -311
- package/src/kinds/validators/MediaValidator.ts +0 -269
- package/src/kinds/validators/ModuleValidator.ts +0 -225
- package/src/kinds/validators/base.ts +0 -276
- package/src/lifecycle/BatchOperations.ts +0 -373
- package/src/lifecycle/LifecycleManager.ts +0 -2126
- package/src/lifecycle/OriginalsAsset.ts +0 -524
- package/src/lifecycle/ProvenanceQuery.ts +0 -280
- package/src/lifecycle/ResourceVersioning.ts +0 -163
- package/src/migration/MigrationManager.ts +0 -527
- package/src/migration/audit/AuditLogger.ts +0 -176
- package/src/migration/checkpoint/CheckpointManager.ts +0 -112
- package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
- package/src/migration/operations/BaseMigration.ts +0 -126
- package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
- package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
- package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
- package/src/migration/rollback/RollbackManager.ts +0 -170
- package/src/migration/state/StateMachine.ts +0 -92
- package/src/migration/state/StateTracker.ts +0 -156
- package/src/migration/types.ts +0 -344
- package/src/migration/validation/BitcoinValidator.ts +0 -107
- package/src/migration/validation/CredentialValidator.ts +0 -62
- package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
- package/src/migration/validation/LifecycleValidator.ts +0 -64
- package/src/migration/validation/StorageValidator.ts +0 -79
- package/src/migration/validation/ValidationPipeline.ts +0 -213
- package/src/resources/ResourceManager.ts +0 -655
- package/src/resources/types.ts +0 -202
- package/src/storage/LocalStorageAdapter.ts +0 -61
- package/src/storage/MemoryStorageAdapter.ts +0 -29
- package/src/storage/StorageAdapter.ts +0 -25
- package/src/types/bitcoin.ts +0 -98
- package/src/types/common.ts +0 -92
- package/src/types/credentials.ts +0 -88
- package/src/types/did.ts +0 -31
- package/src/types/external-shims.d.ts +0 -53
- package/src/types/network.ts +0 -175
- package/src/utils/EventLogger.ts +0 -298
- package/src/utils/Logger.ts +0 -322
- package/src/utils/MetricsCollector.ts +0 -358
- package/src/utils/bitcoin-address.ts +0 -130
- package/src/utils/cbor.ts +0 -12
- package/src/utils/encoding.ts +0 -127
- package/src/utils/hash.ts +0 -6
- package/src/utils/retry.ts +0 -46
- package/src/utils/satoshi-validation.ts +0 -196
- package/src/utils/serialization.ts +0 -96
- package/src/utils/telemetry.ts +0 -40
- package/src/utils/validation.ts +0 -119
- package/src/vc/CredentialManager.ts +0 -918
- package/src/vc/Issuer.ts +0 -100
- package/src/vc/Verifier.ts +0 -47
- package/src/vc/cryptosuites/bbs.ts +0 -253
- package/src/vc/cryptosuites/bbsSimple.ts +0 -21
- package/src/vc/cryptosuites/eddsa.ts +0 -99
- package/src/vc/documentLoader.ts +0 -67
- package/src/vc/proofs/data-integrity.ts +0 -33
- package/src/vc/utils/jsonld.ts +0 -18
- package/tests/__mocks__/bbs-signatures.js +0 -17
- package/tests/__mocks__/mf-base58.js +0 -24
- package/tests/fixtures/did-documents.ts +0 -247
- package/tests/index.test.ts +0 -21
- package/tests/integration/BatchOperations.test.ts +0 -531
- package/tests/integration/CompleteLifecycle.e2e.test.ts +0 -735
- package/tests/integration/CredentialManager.test.ts +0 -42
- package/tests/integration/DIDManager.test.ts +0 -41
- package/tests/integration/DidPeerToWebVhFlow.test.ts +0 -351
- package/tests/integration/Events.test.ts +0 -435
- package/tests/integration/Lifecycle.transfer.btco.integration.test.ts +0 -25
- package/tests/integration/LifecycleManager.test.ts +0 -21
- package/tests/integration/MultikeyFlow.test.ts +0 -52
- package/tests/integration/TelemetryIntegration.test.ts +0 -395
- package/tests/integration/WebVhPublish.test.ts +0 -48
- package/tests/integration/createTypedOriginal.test.ts +0 -379
- package/tests/integration/migration/peer-to-webvh.test.ts +0 -172
- package/tests/manual/test-commit-creation.ts +0 -323
- package/tests/mocks/MockKeyStore.ts +0 -38
- package/tests/mocks/adapters/MemoryStorageAdapter.ts +0 -24
- package/tests/mocks/adapters/MockFeeOracle.ts +0 -11
- package/tests/mocks/adapters/MockOrdinalsProvider.ts +0 -76
- package/tests/mocks/adapters/OrdMockProvider.test.ts +0 -176
- package/tests/mocks/adapters/index.ts +0 -6
- package/tests/performance/BatchOperations.perf.test.ts +0 -403
- package/tests/performance/logging.perf.test.ts +0 -336
- package/tests/sdk.test.ts +0 -43
- package/tests/security/bitcoin-penetration-tests.test.ts +0 -622
- package/tests/setup.bun.ts +0 -69
- package/tests/setup.jest.ts +0 -23
- package/tests/stress/batch-operations-stress.test.ts +0 -571
- package/tests/unit/adapters/FeeOracleMock.test.ts +0 -40
- package/tests/unit/bitcoin/BitcoinManager.test.ts +0 -293
- package/tests/unit/bitcoin/BroadcastClient.test.ts +0 -52
- package/tests/unit/bitcoin/OrdNodeProvider.test.ts +0 -53
- package/tests/unit/bitcoin/OrdinalsClient.test.ts +0 -381
- package/tests/unit/bitcoin/OrdinalsClientProvider.test.ts +0 -102
- package/tests/unit/bitcoin/PSBTBuilder.test.ts +0 -84
- package/tests/unit/bitcoin/fee-calculation.test.ts +0 -261
- package/tests/unit/bitcoin/transactions/commit.test.ts +0 -649
- package/tests/unit/bitcoin/transfer.test.ts +0 -31
- package/tests/unit/bitcoin/utxo-selection-new.test.ts +0 -502
- package/tests/unit/bitcoin/utxo.more.test.ts +0 -39
- package/tests/unit/bitcoin/utxo.selection.test.ts +0 -38
- package/tests/unit/core/OriginalsSDK.test.ts +0 -152
- package/tests/unit/crypto/Multikey.test.ts +0 -206
- package/tests/unit/crypto/Signer.test.ts +0 -408
- package/tests/unit/did/BtcoDidResolver.test.ts +0 -611
- package/tests/unit/did/DIDManager.more.test.ts +0 -43
- package/tests/unit/did/DIDManager.test.ts +0 -185
- package/tests/unit/did/Ed25519Verifier.test.ts +0 -160
- package/tests/unit/did/KeyManager.test.ts +0 -452
- package/tests/unit/did/OrdinalsClientProviderAdapter.test.ts +0 -45
- package/tests/unit/did/WebVHManager.test.ts +0 -435
- package/tests/unit/did/createBtcoDidDocument.test.ts +0 -67
- package/tests/unit/did/providers/OrdinalsClientProviderAdapter.test.ts +0 -159
- package/tests/unit/events/EventEmitter.test.ts +0 -407
- package/tests/unit/kinds/KindRegistry.test.ts +0 -329
- package/tests/unit/kinds/types.test.ts +0 -409
- package/tests/unit/kinds/validators.test.ts +0 -651
- package/tests/unit/lifecycle/BatchOperations.test.ts +0 -527
- package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +0 -441
- package/tests/unit/lifecycle/LifecycleManager.keymanagement.test.ts +0 -312
- package/tests/unit/lifecycle/LifecycleManager.prov.test.ts +0 -18
- package/tests/unit/lifecycle/LifecycleManager.test.ts +0 -213
- package/tests/unit/lifecycle/LifecycleManager.transfer.unit.test.ts +0 -30
- package/tests/unit/lifecycle/OriginalsAsset.test.ts +0 -176
- package/tests/unit/lifecycle/ProvenanceQuery.test.ts +0 -577
- package/tests/unit/lifecycle/ResourceVersioning.test.ts +0 -651
- package/tests/unit/resources/ResourceManager.test.ts +0 -740
- package/tests/unit/storage/MemoryStorageAdapter.test.ts +0 -93
- package/tests/unit/types/network.test.ts +0 -255
- package/tests/unit/utils/EventIntegration.test.ts +0 -384
- package/tests/unit/utils/Logger.test.ts +0 -473
- package/tests/unit/utils/MetricsCollector.test.ts +0 -358
- package/tests/unit/utils/bitcoin-address.test.ts +0 -250
- package/tests/unit/utils/cbor.test.ts +0 -35
- package/tests/unit/utils/encoding.test.ts +0 -318
- package/tests/unit/utils/hash.test.ts +0 -12
- package/tests/unit/utils/retry.test.ts +0 -100
- package/tests/unit/utils/satoshi-validation.test.ts +0 -354
- package/tests/unit/utils/serialization.test.ts +0 -124
- package/tests/unit/utils/telemetry.test.ts +0 -52
- package/tests/unit/utils/validation.test.ts +0 -141
- package/tests/unit/vc/CredentialManager.helpers.test.ts +0 -527
- package/tests/unit/vc/CredentialManager.test.ts +0 -487
- package/tests/unit/vc/Issuer.test.ts +0 -107
- package/tests/unit/vc/Verifier.test.ts +0 -525
- package/tests/unit/vc/bbs.test.ts +0 -282
- package/tests/unit/vc/cryptosuites/eddsa.test.ts +0 -398
- package/tests/unit/vc/documentLoader.test.ts +0 -121
- package/tests/unit/vc/proofs/data-integrity.test.ts +0 -24
- package/tsconfig.json +0 -31
- package/tsconfig.test.json +0 -15
package/src/vc/Issuer.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { VerifiableCredential, VerifiablePresentation, Proof } from '../types';
|
|
2
|
-
import { multikey, MultikeyType } from '../crypto/Multikey';
|
|
3
|
-
import { DIDManager } from '../did/DIDManager';
|
|
4
|
-
import { createDocumentLoader } from './documentLoader';
|
|
5
|
-
import { DataIntegrityProofManager } from './proofs/data-integrity';
|
|
6
|
-
|
|
7
|
-
export interface IssueOptions {
|
|
8
|
-
proofPurpose: 'assertionMethod' | 'authentication';
|
|
9
|
-
documentLoader?: (iri: string) => Promise<{ document: any; documentUrl: string; contextUrl: string | null }>;
|
|
10
|
-
challenge?: string;
|
|
11
|
-
domain?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type VerificationMethodLike = {
|
|
15
|
-
id: string;
|
|
16
|
-
controller: string;
|
|
17
|
-
publicKeyMultibase: string;
|
|
18
|
-
secretKeyMultibase?: string;
|
|
19
|
-
type?: 'Multikey' | string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export class Issuer {
|
|
23
|
-
constructor(private didManager: DIDManager, private verificationMethod: VerificationMethodLike) {}
|
|
24
|
-
|
|
25
|
-
private inferKeyType(publicKeyMultibase: string): MultikeyType {
|
|
26
|
-
try {
|
|
27
|
-
return multikey.decodePublicKey(publicKeyMultibase).type;
|
|
28
|
-
} catch {
|
|
29
|
-
return 'Ed25519';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async issueCredential(
|
|
34
|
-
unsigned: Omit<VerifiableCredential, '@context' | 'proof'>,
|
|
35
|
-
options: IssueOptions
|
|
36
|
-
): Promise<VerifiableCredential> {
|
|
37
|
-
const documentLoader = options.documentLoader || createDocumentLoader(this.didManager);
|
|
38
|
-
await documentLoader(this.verificationMethod.id);
|
|
39
|
-
|
|
40
|
-
const issuerId = typeof unsigned.issuer === 'string' ? unsigned.issuer : (unsigned.issuer as any)?.id;
|
|
41
|
-
const credential: VerifiableCredential = {
|
|
42
|
-
...unsigned,
|
|
43
|
-
'@context': ['https://www.w3.org/ns/credentials/v2'],
|
|
44
|
-
issuer: issuerId || this.verificationMethod.controller,
|
|
45
|
-
proof: undefined
|
|
46
|
-
} as any;
|
|
47
|
-
|
|
48
|
-
if (!this.verificationMethod.secretKeyMultibase) {
|
|
49
|
-
throw new Error('Missing secretKeyMultibase for issuance');
|
|
50
|
-
}
|
|
51
|
-
const keyType = this.inferKeyType(this.verificationMethod.publicKeyMultibase);
|
|
52
|
-
if (keyType !== 'Ed25519') {
|
|
53
|
-
throw new Error('Only Ed25519 supported for eddsa-rdfc-2022');
|
|
54
|
-
}
|
|
55
|
-
const proof = await DataIntegrityProofManager.createProof(credential, {
|
|
56
|
-
verificationMethod: this.verificationMethod.id,
|
|
57
|
-
proofPurpose: options.proofPurpose,
|
|
58
|
-
cryptosuite: 'eddsa-rdfc-2022',
|
|
59
|
-
type: 'DataIntegrityProof',
|
|
60
|
-
privateKey: this.verificationMethod.secretKeyMultibase,
|
|
61
|
-
documentLoader
|
|
62
|
-
});
|
|
63
|
-
return { ...credential, proof } as any;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async issuePresentation(
|
|
67
|
-
presentation: Omit<VerifiablePresentation, '@context' | 'proof'>,
|
|
68
|
-
options: IssueOptions
|
|
69
|
-
): Promise<VerifiablePresentation> {
|
|
70
|
-
const documentLoader = options.documentLoader || createDocumentLoader(this.didManager);
|
|
71
|
-
await documentLoader(this.verificationMethod.id);
|
|
72
|
-
|
|
73
|
-
if (!this.verificationMethod.secretKeyMultibase) {
|
|
74
|
-
throw new Error('Missing secretKeyMultibase for issuance');
|
|
75
|
-
}
|
|
76
|
-
const keyType = this.inferKeyType(this.verificationMethod.publicKeyMultibase);
|
|
77
|
-
if (keyType !== 'Ed25519') {
|
|
78
|
-
throw new Error('Only Ed25519 supported for eddsa-rdfc-2022');
|
|
79
|
-
}
|
|
80
|
-
const proof = await DataIntegrityProofManager.createProof(
|
|
81
|
-
{ ...(presentation as any), '@context': ['https://www.w3.org/ns/credentials/v2'] },
|
|
82
|
-
{
|
|
83
|
-
verificationMethod: this.verificationMethod.id,
|
|
84
|
-
proofPurpose: options.proofPurpose,
|
|
85
|
-
cryptosuite: 'eddsa-rdfc-2022',
|
|
86
|
-
type: 'DataIntegrityProof',
|
|
87
|
-
privateKey: this.verificationMethod.secretKeyMultibase,
|
|
88
|
-
challenge: options.challenge,
|
|
89
|
-
domain: options.domain,
|
|
90
|
-
documentLoader
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
return {
|
|
94
|
-
...(presentation as any),
|
|
95
|
-
'@context': ['https://www.w3.org/ns/credentials/v2'],
|
|
96
|
-
proof
|
|
97
|
-
} as VerifiablePresentation;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
package/src/vc/Verifier.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { VerifiableCredential, VerifiablePresentation } from '../types';
|
|
2
|
-
import { DIDManager } from '../did/DIDManager';
|
|
3
|
-
import { createDocumentLoader } from './documentLoader';
|
|
4
|
-
import { DataIntegrityProofManager } from './proofs/data-integrity';
|
|
5
|
-
|
|
6
|
-
export type VerificationResult = { verified: boolean; errors: string[] };
|
|
7
|
-
|
|
8
|
-
export class Verifier {
|
|
9
|
-
constructor(private didManager: DIDManager) {}
|
|
10
|
-
|
|
11
|
-
async verifyCredential(vc: VerifiableCredential, options: { documentLoader?: (iri: string) => Promise<any> } = {}): Promise<VerificationResult> {
|
|
12
|
-
try {
|
|
13
|
-
if (!vc || !vc['@context'] || !vc.type) throw new Error('Invalid credential');
|
|
14
|
-
if (!vc.proof) throw new Error('Credential has no proof');
|
|
15
|
-
const loader = options.documentLoader || createDocumentLoader(this.didManager);
|
|
16
|
-
const ctxs: string[] = Array.isArray(vc['@context']) ? (vc['@context'] as any) : [vc['@context'] as any];
|
|
17
|
-
for (const c of ctxs) await loader(c);
|
|
18
|
-
const proof = Array.isArray(vc.proof) ? (vc.proof as any)[0] : (vc.proof as any);
|
|
19
|
-
const result = await DataIntegrityProofManager.verifyProof(vc, proof, { documentLoader: loader });
|
|
20
|
-
return result.verified ? { verified: true, errors: [] } : { verified: false, errors: result.errors ?? ['Verification failed'] };
|
|
21
|
-
} catch (e: any) {
|
|
22
|
-
return { verified: false, errors: [e?.message ?? 'Unknown error in verifyCredential'] };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async verifyPresentation(vp: VerifiablePresentation, options: { documentLoader?: (iri: string) => Promise<any> } = {}): Promise<VerificationResult> {
|
|
27
|
-
try {
|
|
28
|
-
if (!vp || !vp['@context'] || !vp.type) throw new Error('Invalid presentation');
|
|
29
|
-
if (!vp.proof) throw new Error('Presentation has no proof');
|
|
30
|
-
const loader = options.documentLoader || createDocumentLoader(this.didManager);
|
|
31
|
-
const ctxs: string[] = Array.isArray(vp['@context']) ? (vp['@context'] as any) : [vp['@context'] as any];
|
|
32
|
-
for (const c of ctxs) await loader(c);
|
|
33
|
-
if (vp.verifiableCredential) {
|
|
34
|
-
for (const c of vp.verifiableCredential) {
|
|
35
|
-
const res = await this.verifyCredential(c as any, { documentLoader: loader });
|
|
36
|
-
if (!res.verified) return res;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const proof = Array.isArray(vp.proof) ? (vp.proof as any)[0] : (vp.proof as any);
|
|
40
|
-
const result = await DataIntegrityProofManager.verifyProof(vp, proof, { documentLoader: loader });
|
|
41
|
-
return result.verified ? { verified: true, errors: [] } : { verified: false, errors: result.errors ?? ['Verification failed'] };
|
|
42
|
-
} catch (e: any) {
|
|
43
|
-
return { verified: false, errors: [e?.message ?? 'Unknown error in verifyPresentation'] };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import * as cbor from 'cbor-js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Minimal BBS utility methods ported from legacy for working with
|
|
5
|
-
* Data Integrity BBS (bbs-2023) base and derived proof value encoding.
|
|
6
|
-
*
|
|
7
|
-
* Notes:
|
|
8
|
-
* - This module focuses on serialization/parsing helpers used by callers
|
|
9
|
-
* to pack/unpack proof values. It does not perform signing or verification.
|
|
10
|
-
* - All methods operate on Uint8Array inputs and return multibase strings
|
|
11
|
-
* (base64url with 'u' prefix) where applicable to match the spec.
|
|
12
|
-
*/
|
|
13
|
-
export class BBSCryptosuiteUtils {
|
|
14
|
-
private static encodeBase64urlNoPad(bytes: Uint8Array): string {
|
|
15
|
-
const b64 = Buffer.from(bytes).toString('base64');
|
|
16
|
-
const b64url = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
|
|
17
|
-
return 'u' + b64url;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private static decodeBase64urlNoPad(s: string): Uint8Array {
|
|
21
|
-
if (!s.startsWith('u')) throw new Error('Not a multibase base64url (u- prefixed) string');
|
|
22
|
-
const raw = s.slice(1);
|
|
23
|
-
const b64 = raw.replace(/-/g, '+').replace(/_/g, '/');
|
|
24
|
-
const pad = b64.length % 4 === 2 ? '==' : b64.length % 4 === 3 ? '=' : '';
|
|
25
|
-
return new Uint8Array(Buffer.from(b64 + pad, 'base64'));
|
|
26
|
-
}
|
|
27
|
-
private static compareBytes(a: Uint8Array, b: number[]): boolean {
|
|
28
|
-
if (a.length !== b.length) return false;
|
|
29
|
-
for (let i = 0; i < b.length; i++) {
|
|
30
|
-
if (a[i] !== b[i]) return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private static concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
36
|
-
const out = new Uint8Array(a.length + b.length);
|
|
37
|
-
out.set(a, 0);
|
|
38
|
-
out.set(b, a.length);
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ===== Base proof (serialize/parse) =====
|
|
43
|
-
|
|
44
|
-
static serializeBaseProofValue(
|
|
45
|
-
bbsSignature: Uint8Array,
|
|
46
|
-
bbsHeader: Uint8Array,
|
|
47
|
-
publicKey: Uint8Array,
|
|
48
|
-
hmacKey: Uint8Array,
|
|
49
|
-
mandatoryPointers: string[],
|
|
50
|
-
featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym_issuer_pid' | 'pseudonym_hidden_pid',
|
|
51
|
-
pid?: Uint8Array,
|
|
52
|
-
signerBlind?: Uint8Array
|
|
53
|
-
): string {
|
|
54
|
-
let headerBytes: Uint8Array;
|
|
55
|
-
let components: (Uint8Array | string[] | Uint8Array)[];
|
|
56
|
-
|
|
57
|
-
switch (featureOption) {
|
|
58
|
-
case 'baseline':
|
|
59
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x02]);
|
|
60
|
-
components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers];
|
|
61
|
-
break;
|
|
62
|
-
case 'anonymous_holder_binding':
|
|
63
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x04]);
|
|
64
|
-
if (!signerBlind) throw new Error('signerBlind is required for anonymous_holder_binding');
|
|
65
|
-
components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, signerBlind];
|
|
66
|
-
break;
|
|
67
|
-
case 'pseudonym_issuer_pid':
|
|
68
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x06]);
|
|
69
|
-
if (!pid) throw new Error('pid is required for pseudonym_issuer_pid');
|
|
70
|
-
components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, pid];
|
|
71
|
-
break;
|
|
72
|
-
case 'pseudonym_hidden_pid':
|
|
73
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x08]);
|
|
74
|
-
if (!signerBlind) throw new Error('signerBlind is required for pseudonym_hidden_pid');
|
|
75
|
-
components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, signerBlind];
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
throw new Error(`Unsupported feature option: ${featureOption}`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const encodedComponents = cbor.encode(components);
|
|
82
|
-
const proofBytes = BBSCryptosuiteUtils.concatBytes(headerBytes, new Uint8Array(encodedComponents));
|
|
83
|
-
return BBSCryptosuiteUtils.encodeBase64urlNoPad(proofBytes);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static parseBaseProofValue(proofValue: string): {
|
|
87
|
-
bbsSignature: Uint8Array;
|
|
88
|
-
bbsHeader: Uint8Array;
|
|
89
|
-
publicKey: Uint8Array;
|
|
90
|
-
hmacKey: Uint8Array;
|
|
91
|
-
mandatoryPointers: string[];
|
|
92
|
-
featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym_issuer_pid' | 'pseudonym_hidden_pid' | 'base_proof';
|
|
93
|
-
pid?: Uint8Array;
|
|
94
|
-
signerBlind?: Uint8Array;
|
|
95
|
-
} {
|
|
96
|
-
const decoded = BBSCryptosuiteUtils.decodeBase64urlNoPad(proofValue);
|
|
97
|
-
const header = decoded.slice(0, 3);
|
|
98
|
-
let featureOption: any;
|
|
99
|
-
if (this.compareBytes(header, [0xd9, 0x5d, 0x02])) featureOption = 'baseline';
|
|
100
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x04])) featureOption = 'anonymous_holder_binding';
|
|
101
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x06])) featureOption = 'pseudonym_issuer_pid';
|
|
102
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x08])) featureOption = 'pseudonym_hidden_pid';
|
|
103
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x03])) featureOption = 'base_proof';
|
|
104
|
-
else throw new Error('Invalid BBS base proof header');
|
|
105
|
-
|
|
106
|
-
const components: any[] = cbor.decode(decoded.slice(3).buffer) as any[];
|
|
107
|
-
const base = {
|
|
108
|
-
bbsSignature: components[0] as Uint8Array,
|
|
109
|
-
bbsHeader: components[1] as Uint8Array,
|
|
110
|
-
publicKey: components[2] as Uint8Array,
|
|
111
|
-
hmacKey: components[3] as Uint8Array,
|
|
112
|
-
mandatoryPointers: components[4] as string[],
|
|
113
|
-
featureOption
|
|
114
|
-
} as any;
|
|
115
|
-
|
|
116
|
-
if (featureOption === 'anonymous_holder_binding' || featureOption === 'pseudonym_hidden_pid') {
|
|
117
|
-
base.signerBlind = components[5] as Uint8Array;
|
|
118
|
-
}
|
|
119
|
-
if (featureOption === 'pseudonym_issuer_pid') {
|
|
120
|
-
base.pid = components[5] as Uint8Array;
|
|
121
|
-
}
|
|
122
|
-
return base;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ===== Label map compression helpers =====
|
|
126
|
-
|
|
127
|
-
private static compressLabelMap(labelMap: { [key: string]: string }): { [key: string]: string } {
|
|
128
|
-
const map: { [key: string]: string } = {};
|
|
129
|
-
for (const [k, v] of Object.entries(labelMap)) {
|
|
130
|
-
const c14nMatch = k.match(/^c14n(\d+)$/);
|
|
131
|
-
const bMatch = v.match(/^b(\d+)$/);
|
|
132
|
-
if (!c14nMatch || !bMatch) {
|
|
133
|
-
throw new Error(`Invalid label map entry: ${k} -> ${v}`);
|
|
134
|
-
}
|
|
135
|
-
const key = parseInt(c14nMatch[1], 10);
|
|
136
|
-
const value = parseInt(bMatch[1], 10);
|
|
137
|
-
map[key] = value.toString();
|
|
138
|
-
}
|
|
139
|
-
return map;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private static decompressLabelMap(compressed: { [key: string]: string }): { [key: string]: string } {
|
|
143
|
-
const map: { [key: string]: string } = {};
|
|
144
|
-
for (const [k, v] of Object.entries(compressed)) {
|
|
145
|
-
map[`c14n${k}`] = `b${v}`;
|
|
146
|
-
}
|
|
147
|
-
return map;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ===== Derived proof (serialize/parse) =====
|
|
151
|
-
|
|
152
|
-
static serializeDerivedProofValue(
|
|
153
|
-
bbsProof: Uint8Array,
|
|
154
|
-
labelMap: { [key: string]: string },
|
|
155
|
-
mandatoryIndexes: number[],
|
|
156
|
-
selectiveIndexes: number[],
|
|
157
|
-
presentationHeader: Uint8Array,
|
|
158
|
-
featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym',
|
|
159
|
-
pseudonym?: string,
|
|
160
|
-
lengthBBSMessages?: number
|
|
161
|
-
): string {
|
|
162
|
-
const compressedLabelMap = this.compressLabelMap(labelMap);
|
|
163
|
-
|
|
164
|
-
let headerBytes: Uint8Array;
|
|
165
|
-
let components: (Uint8Array | { [key: string]: string } | number[] | number | string)[];
|
|
166
|
-
|
|
167
|
-
switch (featureOption) {
|
|
168
|
-
case 'baseline':
|
|
169
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x03]);
|
|
170
|
-
components = [
|
|
171
|
-
bbsProof,
|
|
172
|
-
compressedLabelMap,
|
|
173
|
-
mandatoryIndexes,
|
|
174
|
-
selectiveIndexes,
|
|
175
|
-
presentationHeader
|
|
176
|
-
];
|
|
177
|
-
break;
|
|
178
|
-
case 'anonymous_holder_binding':
|
|
179
|
-
if (typeof lengthBBSMessages !== 'number') {
|
|
180
|
-
throw new Error('lengthBBSMessages is required for anonymous_holder_binding');
|
|
181
|
-
}
|
|
182
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x05]);
|
|
183
|
-
components = [
|
|
184
|
-
bbsProof,
|
|
185
|
-
compressedLabelMap,
|
|
186
|
-
mandatoryIndexes,
|
|
187
|
-
selectiveIndexes,
|
|
188
|
-
presentationHeader,
|
|
189
|
-
lengthBBSMessages
|
|
190
|
-
];
|
|
191
|
-
break;
|
|
192
|
-
case 'pseudonym':
|
|
193
|
-
if (!pseudonym || typeof lengthBBSMessages !== 'number') {
|
|
194
|
-
throw new Error('pseudonym and lengthBBSMessages are required for pseudonym features');
|
|
195
|
-
}
|
|
196
|
-
headerBytes = new Uint8Array([0xd9, 0x5d, 0x07]);
|
|
197
|
-
components = [
|
|
198
|
-
bbsProof,
|
|
199
|
-
compressedLabelMap,
|
|
200
|
-
mandatoryIndexes,
|
|
201
|
-
selectiveIndexes,
|
|
202
|
-
presentationHeader,
|
|
203
|
-
pseudonym,
|
|
204
|
-
lengthBBSMessages
|
|
205
|
-
];
|
|
206
|
-
break;
|
|
207
|
-
default:
|
|
208
|
-
throw new Error(`Unsupported feature option: ${featureOption}`);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const encodedComponents = cbor.encode(components);
|
|
212
|
-
const proofBytes = this.concatBytes(headerBytes, new Uint8Array(encodedComponents));
|
|
213
|
-
return this.encodeBase64urlNoPad(proofBytes);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
static parseDerivedProofValue(proofValue: string): {
|
|
217
|
-
bbsProof: Uint8Array;
|
|
218
|
-
labelMap: { [key: string]: string };
|
|
219
|
-
mandatoryIndexes: number[];
|
|
220
|
-
selectiveIndexes: number[];
|
|
221
|
-
presentationHeader: Uint8Array;
|
|
222
|
-
featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym';
|
|
223
|
-
pseudonym?: string;
|
|
224
|
-
lengthBBSMessages?: number;
|
|
225
|
-
} {
|
|
226
|
-
const decoded = this.decodeBase64urlNoPad(proofValue);
|
|
227
|
-
const header = decoded.slice(0, 3);
|
|
228
|
-
let featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym';
|
|
229
|
-
if (this.compareBytes(header, [0xd9, 0x5d, 0x03])) featureOption = 'baseline';
|
|
230
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x05])) featureOption = 'anonymous_holder_binding';
|
|
231
|
-
else if (this.compareBytes(header, [0xd9, 0x5d, 0x07])) featureOption = 'pseudonym';
|
|
232
|
-
else throw new Error('Invalid BBS derived proof header');
|
|
233
|
-
|
|
234
|
-
const components: any[] = cbor.decode(decoded.slice(3).buffer) as any[];
|
|
235
|
-
const decompressedLabelMap = this.decompressLabelMap(components[1]);
|
|
236
|
-
const result: any = {
|
|
237
|
-
bbsProof: components[0],
|
|
238
|
-
labelMap: decompressedLabelMap,
|
|
239
|
-
mandatoryIndexes: components[2],
|
|
240
|
-
selectiveIndexes: components[3],
|
|
241
|
-
presentationHeader: components[4],
|
|
242
|
-
featureOption
|
|
243
|
-
};
|
|
244
|
-
if (featureOption === 'anonymous_holder_binding') {
|
|
245
|
-
result.lengthBBSMessages = components[5];
|
|
246
|
-
} else if (featureOption === 'pseudonym') {
|
|
247
|
-
result.pseudonym = components[5];
|
|
248
|
-
result.lengthBBSMessages = components[6];
|
|
249
|
-
}
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { sha256 } from '@noble/hashes/sha2.js';
|
|
2
|
-
|
|
3
|
-
export type BbsKeyPair = {
|
|
4
|
-
publicKey: Uint8Array;
|
|
5
|
-
privateKey: Uint8Array;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export class BbsSimple {
|
|
9
|
-
static readonly CIPHERSUITE = 'BLS12-381-SHA-256';
|
|
10
|
-
|
|
11
|
-
static async sign(messages: Uint8Array[], keypair: BbsKeyPair, header?: Uint8Array): Promise<Uint8Array> {
|
|
12
|
-
const headerBytes = header ?? new Uint8Array(sha256(new Uint8Array(0)));
|
|
13
|
-
throw new Error('BbsSimple.sign is not implemented');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static async verify(messages: Uint8Array[], signature: Uint8Array, publicKey: Uint8Array, header?: Uint8Array): Promise<boolean> {
|
|
17
|
-
const headerBytes = header ?? new Uint8Array(sha256(new Uint8Array(0)));
|
|
18
|
-
throw new Error('BbsSimple.verify is not implemented');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { base58 } from '@scure/base';
|
|
2
|
-
import * as ed25519 from '@noble/ed25519';
|
|
3
|
-
import { canonize, canonizeProof } from '../utils/jsonld';
|
|
4
|
-
import { multikey } from '../../crypto/Multikey';
|
|
5
|
-
import { sha256Bytes } from '../../utils/hash';
|
|
6
|
-
|
|
7
|
-
export interface DataIntegrityProof {
|
|
8
|
-
type: 'DataIntegrityProof';
|
|
9
|
-
cryptosuite: string;
|
|
10
|
-
created?: string;
|
|
11
|
-
verificationMethod: string;
|
|
12
|
-
proofPurpose: string;
|
|
13
|
-
proofValue: string;
|
|
14
|
-
id?: string;
|
|
15
|
-
previousProof?: string | string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface VerificationResult {
|
|
19
|
-
verified: boolean;
|
|
20
|
-
errors?: string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class EdDSACryptosuiteManager {
|
|
24
|
-
|
|
25
|
-
static async createProof(document: any, options: any): Promise<DataIntegrityProof> {
|
|
26
|
-
const proofConfig = await this.createProofConfiguration(options);
|
|
27
|
-
const transformedData = await this.transform(document, options);
|
|
28
|
-
const hashData = await this.hash(transformedData, proofConfig, options);
|
|
29
|
-
let privateKey: Uint8Array;
|
|
30
|
-
if (typeof options.privateKey === 'string') {
|
|
31
|
-
const dec = multikey.decodePrivateKey(options.privateKey);
|
|
32
|
-
if (dec.type !== 'Ed25519') throw new Error('Invalid key type for EdDSA');
|
|
33
|
-
privateKey = dec.key;
|
|
34
|
-
} else if (options.privateKey instanceof Uint8Array) {
|
|
35
|
-
privateKey = options.privateKey;
|
|
36
|
-
} else {
|
|
37
|
-
throw new Error('Invalid private key format');
|
|
38
|
-
}
|
|
39
|
-
const proofValueBytes = await this.sign({ data: hashData, privateKey });
|
|
40
|
-
delete (proofConfig as any)['@context'];
|
|
41
|
-
return { ...proofConfig, proofValue: base58.encode(proofValueBytes) } as DataIntegrityProof;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static async verifyProof(document: any, proof: DataIntegrityProof, options: any): Promise<VerificationResult> {
|
|
45
|
-
try {
|
|
46
|
-
const documentToVerify = { ...document };
|
|
47
|
-
delete (documentToVerify as any).proof;
|
|
48
|
-
const transformedData = await this.transform(documentToVerify, options);
|
|
49
|
-
const hashData = await this.hash(transformedData, { '@context': document['@context'], ...proof }, options);
|
|
50
|
-
const vmDoc = await options.documentLoader(proof.verificationMethod);
|
|
51
|
-
const pk = vmDoc.document.publicKeyMultibase as string;
|
|
52
|
-
const dec = multikey.decodePublicKey(pk);
|
|
53
|
-
if (dec.type !== 'Ed25519') throw new Error('Invalid key type for EdDSA');
|
|
54
|
-
const signature = base58.decode(proof.proofValue);
|
|
55
|
-
const verified = await this.verify({ data: hashData, signature, publicKey: dec.key });
|
|
56
|
-
return verified ? { verified: true } : { verified: false, errors: ['Proof verification failed'] };
|
|
57
|
-
} catch (e: any) {
|
|
58
|
-
return { verified: false, errors: [e?.message ?? 'Unknown verification error'] };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private static async createProofConfiguration(options: any): Promise<any> {
|
|
63
|
-
return {
|
|
64
|
-
'@context': 'https://w3id.org/security/data-integrity/v2',
|
|
65
|
-
type: 'DataIntegrityProof',
|
|
66
|
-
cryptosuite: 'eddsa-rdfc-2022',
|
|
67
|
-
created: new Date().toISOString(),
|
|
68
|
-
verificationMethod: options.verificationMethod,
|
|
69
|
-
proofPurpose: options.proofPurpose || 'assertionMethod',
|
|
70
|
-
...(options.challenge && { challenge: options.challenge }),
|
|
71
|
-
...(options.domain && { domain: options.domain })
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private static async transform(document: any, options: any): Promise<string> {
|
|
76
|
-
return await canonize(document, { documentLoader: options.documentLoader });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private static async hash(transformedData: string, proofConfig: any, options: any): Promise<Uint8Array> {
|
|
80
|
-
const canonicalProofConfig = await canonizeProof(proofConfig, { documentLoader: options.documentLoader });
|
|
81
|
-
const proofConfigHash = await sha256Bytes(canonicalProofConfig);
|
|
82
|
-
const documentHash = await sha256Bytes(transformedData);
|
|
83
|
-
return new Uint8Array([...proofConfigHash, ...documentHash]);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static async sign({ data, privateKey }: { data: Uint8Array; privateKey: Uint8Array }): Promise<Uint8Array> {
|
|
87
|
-
if (privateKey.length !== 32) {
|
|
88
|
-
if (privateKey.length === 64) privateKey = privateKey.slice(32);
|
|
89
|
-
else throw new Error('Invalid private key length');
|
|
90
|
-
}
|
|
91
|
-
const signature = await ed25519.signAsync(Buffer.from(data).toString('hex'), Buffer.from(privateKey).toString('hex'));
|
|
92
|
-
return signature;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
static async verify({ data, signature, publicKey }: { data: Uint8Array; signature: Uint8Array; publicKey: Uint8Array }): Promise<boolean> {
|
|
96
|
-
return await ed25519.verifyAsync(Buffer.from(signature).toString('hex'), Buffer.from(data).toString('hex'), Buffer.from(publicKey).toString('hex'));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
package/src/vc/documentLoader.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { DIDManager } from '../did/DIDManager';
|
|
2
|
-
|
|
3
|
-
type LoadedDocument = { document: any; documentUrl: string; contextUrl: string | null };
|
|
4
|
-
|
|
5
|
-
const CONTEXTS: Record<string, any> = {
|
|
6
|
-
// Provide 1.1-compatible stubs for jsonld canonize
|
|
7
|
-
'https://www.w3.org/ns/credentials/v2': { '@context': { '@version': 1.1 } },
|
|
8
|
-
'https://w3id.org/security/data-integrity/v2': { '@context': { '@version': 1.1 } }
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export class DocumentLoader {
|
|
12
|
-
constructor(private didManager: DIDManager) {}
|
|
13
|
-
|
|
14
|
-
async load(iri: string): Promise<LoadedDocument> {
|
|
15
|
-
if (iri.startsWith('did:')) {
|
|
16
|
-
return this.resolveDID(iri);
|
|
17
|
-
}
|
|
18
|
-
const doc = CONTEXTS[iri];
|
|
19
|
-
if (doc) {
|
|
20
|
-
return { document: doc, documentUrl: iri, contextUrl: null };
|
|
21
|
-
}
|
|
22
|
-
throw new Error(`Document not found: ${iri}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private async resolveDID(didUrl: string): Promise<LoadedDocument> {
|
|
26
|
-
const [did, fragment] = didUrl.split('#');
|
|
27
|
-
const didDoc = await this.didManager.resolveDID(did);
|
|
28
|
-
if (!didDoc) {
|
|
29
|
-
throw new Error(`DID not resolved: ${did}`);
|
|
30
|
-
}
|
|
31
|
-
if (fragment) {
|
|
32
|
-
// If a VM was registered explicitly, prefer it
|
|
33
|
-
const cached = verificationMethodRegistry.get(didUrl);
|
|
34
|
-
if (cached) {
|
|
35
|
-
return {
|
|
36
|
-
document: { '@context': (didDoc as any)['@context'], ...cached },
|
|
37
|
-
documentUrl: didUrl,
|
|
38
|
-
contextUrl: null
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const vms = (didDoc as any).verificationMethod as any[] | undefined;
|
|
42
|
-
const vm = vms?.find((m) => m.id === didUrl);
|
|
43
|
-
if (vm) {
|
|
44
|
-
return {
|
|
45
|
-
document: { '@context': (didDoc as any)['@context'], ...vm },
|
|
46
|
-
documentUrl: didUrl,
|
|
47
|
-
contextUrl: null
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
document: { '@context': (didDoc as any)['@context'], id: didUrl },
|
|
52
|
-
documentUrl: didUrl,
|
|
53
|
-
contextUrl: null
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return { document: didDoc, documentUrl: didUrl, contextUrl: null };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const createDocumentLoader = (didManager: DIDManager) =>
|
|
61
|
-
(iri: string) => new DocumentLoader(didManager).load(iri);
|
|
62
|
-
|
|
63
|
-
export const verificationMethodRegistry: Map<string, any> = new Map();
|
|
64
|
-
export function registerVerificationMethod(vm: any) {
|
|
65
|
-
if (vm?.id) verificationMethodRegistry.set(vm.id, vm);
|
|
66
|
-
}
|
|
67
|
-
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EdDSACryptosuiteManager, type DataIntegrityProof } from '../cryptosuites/eddsa';
|
|
2
|
-
|
|
3
|
-
export interface VerificationResult { verified: boolean; errors?: string[] }
|
|
4
|
-
|
|
5
|
-
export interface ProofOptions {
|
|
6
|
-
verificationMethod: string;
|
|
7
|
-
proofPurpose: string;
|
|
8
|
-
privateKey?: Uint8Array | string;
|
|
9
|
-
type: 'DataIntegrityProof';
|
|
10
|
-
created?: string;
|
|
11
|
-
cryptosuite: string;
|
|
12
|
-
documentLoader?: (url: string) => Promise<any>;
|
|
13
|
-
previousProof?: string | string[];
|
|
14
|
-
challenge?: string;
|
|
15
|
-
domain?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class DataIntegrityProofManager {
|
|
19
|
-
static async createProof(document: any, options: ProofOptions): Promise<DataIntegrityProof> {
|
|
20
|
-
if (options.cryptosuite !== 'eddsa-rdfc-2022') {
|
|
21
|
-
throw new Error(`Unsupported cryptosuite: ${options.cryptosuite}`);
|
|
22
|
-
}
|
|
23
|
-
return await EdDSACryptosuiteManager.createProof(document, options);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static async verifyProof(document: any, proof: DataIntegrityProof, options: any): Promise<VerificationResult> {
|
|
27
|
-
if (proof.cryptosuite !== 'eddsa-rdfc-2022') {
|
|
28
|
-
return { verified: false, errors: [`Unsupported cryptosuite: ${proof.cryptosuite}`] };
|
|
29
|
-
}
|
|
30
|
-
return await EdDSACryptosuiteManager.verifyProof(document, proof, options);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
package/src/vc/utils/jsonld.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import jsonld from 'jsonld';
|
|
2
|
-
|
|
3
|
-
export async function canonize(input: any, { documentLoader }: any): Promise<string> {
|
|
4
|
-
return await jsonld.canonize(input, {
|
|
5
|
-
algorithm: 'URDNA2015',
|
|
6
|
-
format: 'application/n-quads',
|
|
7
|
-
documentLoader,
|
|
8
|
-
safe: false,
|
|
9
|
-
useNative: false,
|
|
10
|
-
rdfDirection: 'i18n-datatype'
|
|
11
|
-
} as any);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function canonizeProof(proof: any, { documentLoader }: any): Promise<string> {
|
|
15
|
-
const { jws, signatureValue, proofValue, ...rest } = proof;
|
|
16
|
-
return await canonize(rest, { documentLoader });
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Minimal mock for @digitalbazaar/bbs-signatures used in tests
|
|
2
|
-
const toHex = (u8) => Buffer.from(u8).toString('hex');
|
|
3
|
-
|
|
4
|
-
exports.sign = async ({ secretKey, publicKey, header, messages }) => {
|
|
5
|
-
// produce a deterministic pseudo-signature for tests
|
|
6
|
-
const data = [secretKey, publicKey, header, ...messages].map(toHex).join('|');
|
|
7
|
-
return new Uint8Array(Buffer.from('sig:' + data));
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
exports.verifySignature = async ({ publicKey, signature, header, messages }) => {
|
|
11
|
-
const expected = await exports.sign({ secretKey: new Uint8Array(0), publicKey, header, messages });
|
|
12
|
-
// accept any signature that starts with 'sig:' and contains publicKey/header/messages
|
|
13
|
-
const sigStr = Buffer.from(signature).toString();
|
|
14
|
-
const expStr = Buffer.from(expected).toString();
|
|
15
|
-
return sigStr.includes(Buffer.from(publicKey).toString('hex')) && sigStr.includes(Buffer.from(header).toString('hex')) && sigStr.includes(expStr.split('|').slice(2).join('|'));
|
|
16
|
-
};
|
|
17
|
-
|